1
0
mirror of https://github.com/osmarks/nanogpt-experiments.git synced 2024-09-21 03:39:44 +00:00

batch file write

This commit is contained in:
Laiho 2023-01-02 17:49:21 +02:00
parent ea4de192e0
commit 0a2ea95338

View File

@ -53,12 +53,16 @@ for split, dset in tokenized.items():
filename = f'{split}.bin' filename = f'{split}.bin'
dtype = np.uint16 # (can do since enc.max_token_value == 50256 is < 2**16) dtype = np.uint16 # (can do since enc.max_token_value == 50256 is < 2**16)
arr = np.memmap(filename, dtype=dtype, mode='w+', shape=(arr_len,)) arr = np.memmap(filename, dtype=dtype, mode='w+', shape=(arr_len,))
total_batches = 1024
print(f"writing {filename}...")
idx = 0 idx = 0
for example in tqdm(dset): for batch_idx in tqdm(range(total_batches), desc=f'writing {filename}'):
arr[idx : idx + example['len']] = example['ids'] # Batch together samples for faster write
idx += example['len'] batch = dset.shard(num_shards=total_batches, index=batch_idx, contiguous=True).with_format('numpy')
arr_batch = np.concatenate(batch['ids'])
# Write into mmap
arr[idx : idx + len(arr_batch)] = arr_batch
idx += len(arr_batch)
arr.flush() arr.flush()
# train.bin is ~17GB, val.bin ~8.5MB # train.bin is ~17GB, val.bin ~8.5MB