Skip to content

Commit 939eeb8

Browse files
committed
fix bug for cache file
1 parent fb51bae commit 939eeb8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎xtuner/v1/datasets/jsonl.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,17 @@ def __init__(
321321
if not os.path.exists(_cached_file):
322322
offsets = self.count_offsets(file_cache_dir)
323323

324-
if not os.path.exists(self.meta_path):
324+
# (Re)initialize the meta file when it is missing, empty, or
325+
# corrupted (e.g. a previous run was killed between
326+
# `truncate(0)` and `write`, or the user cleared its content).
327+
need_init = not os.path.exists(self.meta_path)
328+
if not need_init:
329+
try:
330+
with open(self.meta_path) as f:
331+
json.load(f)
332+
except (json.JSONDecodeError, ValueError):
333+
need_init = True
334+
if need_init:
325335
with open(self.meta_path, "w") as f:
326336
f.write("{}")
327337

0 commit comments

Comments
 (0)