aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / streams / data / extract.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Data preparation only (not the product path): stream the `text` column of FineWeb-Edu parquet |
| 3 | shards to stdout as length-prefixed documents: u32 little-endian byte length, then UTF-8 bytes. |
| 4 | Usage: extract.py <shard.parquet> [--skip-docs N] [--max-docs N] [--max-bytes N] |
| 5 | Prints nothing else on stdout. Run with the pyarrow venv.""" |
| 6 | import sys, struct, argparse |
| 7 | import pyarrow.parquet as pq |
| 8 | ap = argparse.ArgumentParser() |
| 9 | ap.add_argument("shard"); ap.add_argument("--skip-docs", type=int, default=0) |
| 10 | ap.add_argument("--max-docs", type=int, default=1 << 62); ap.add_argument("--max-bytes", type=int, default=1 << 62) |
| 11 | a = ap.parse_args() |
| 12 | out = sys.stdout.buffer |
| 13 | seen = emitted = nbytes = 0 |
| 14 | for batch in pq.ParquetFile(a.shard).iter_batches(batch_size=2048, columns=["text"]): |
| 15 | for t in batch.column(0).to_pylist(): |
| 16 | seen += 1 |
| 17 | if seen <= a.skip_docs: continue |
| 18 | if emitted >= a.max_docs or nbytes >= a.max_bytes: sys.exit(0) |
| 19 | b = t.encode("utf-8") |
| 20 | out.write(struct.pack("<I", len(b))); out.write(b) |
| 21 | emitted += 1; nbytes += len(b) |