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 / own-fp4 / prep_data.py
| 1 | # prep_data.py (L284 oracle): SearchQA web-snippet text already on this Spark -> uint16 token files. |
| 2 | # Arrow files are read as raw bytes (no pyarrow here): every printable UTF-8 run of >= 200 chars is kept as text. |
| 3 | # Tokenizer: TinyLlama-1.1B tokenizer.json (32000 ids). Train = searchqa-train.arrow, held-out val = searchqa-validation.arrow. |
| 4 | import sys, re, hashlib, numpy as np |
| 5 | from tokenizers import Tokenizer |
| 6 | D = sys.argv[1]; OUT = sys.argv[2]; TOK = sys.argv[3] |
| 7 | tok = Tokenizer.from_file(TOK) |
| 8 | run = re.compile(rb'[\x20-\x7e\xc2-\xf4\x80-\xbf\n]{200,}') |
| 9 | for split, cap in (("validation", 4_000_000), ("train", 400_000_000)): |
| 10 | raw = open(f"{D}/searchqa-{split}.arrow", "rb").read() |
| 11 | texts = [m.group(0).decode("utf-8", "ignore") for m in run.finditer(raw)] |
| 12 | ids = []; n = 0 |
| 13 | for i in range(0, len(texts), 2000): |
| 14 | for enc in tok.encode_batch(texts[i:i + 2000], add_special_tokens=False): |
| 15 | ids.append(np.asarray([1] + enc.ids, dtype=np.uint16)); n += len(enc.ids) + 1 |
| 16 | if n >= cap: break |
| 17 | arr = np.concatenate(ids)[:cap] |
| 18 | arr.tofile(f"{OUT}/{split}.u16") |
| 19 | print(split, "texts", len(texts), "tokens", arr.size, "sha256", hashlib.sha256(arr.tobytes()).hexdigest()[:16], flush=True) |