MLE-World / export_jsonl.py
ko120's picture
Release MLE World experiment artifacts: checkpoint 6685 and matching SFT corpus
5107871 verified
Raw History Blame Contribute Delete
1.78 kB
#!/usr/bin/env python3
"""Restore LlamaFactory JSONL files from this downloaded dataset repository."""
import argparse
import hashlib
import json
import shutil
from pathlib import Path
import pyarrow.parquet as pq
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output-dir', type=Path, required=True)
args = parser.parse_args()
root = Path(__file__).resolve().parent
provenance = json.loads((root / 'provenance.json').read_text())
args.output_dir.mkdir(parents=True, exist_ok=True)
for split, filename in [('train', 'train.jsonl'), ('validation', 'holdout.sharegpt.jsonl')]:
info = provenance['splits'][split]
destination = args.output_dir / filename
if destination.exists():
raise FileExistsError(destination)
digest, count = hashlib.sha256(), 0
with destination.open('x', encoding='utf-8') as stream:
for shard in info['shards']:
for batch in pq.ParquetFile(root / shard['path']).iter_batches(batch_size=1000):
for row in batch.to_pylist():
line = json.dumps(row, ensure_ascii=False, sort_keys=True, separators=(',', ':')) + '\n'
stream.write(line)
digest.update(line.encode())
count += 1
assert count == info['rows']
assert digest.hexdigest() == info['canonical_rows_sha256']
print(f'{filename}: {count} verified rows')
shutil.copy2(root / 'llamafactory/dataset_info.json', args.output_dir / 'dataset_info.json')
for name in ('exception_tokens.json', 'exception_tokens.yaml'):
shutil.copy2(root / name, args.output_dir / name)
if __name__ == '__main__':
main()