interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-train / streams / math-training / extract_e1.py

34 lines · 1615 bytes Raw Blame History
1# E1 step 1: freeze SmolLM2-1.7B, extract final-norm features X and next tokens Y once, save to .scratch.
2# Splits: fit = GSM8K train examples [0, 6000); val = train [6000, 7473) (for lambda / early stop); test = GSM8K test.
3import os, time, torch
4from common import *
5
6CAP = {"fit": 262144, "val": 32768, "test": 65536}
7
8tok, model = load_model()
9train, test = load_split("train"), load_split("test")
10parts = {"fit": train[:6000], "val": train[6000:], "test": test}
11E = model.model.embed_tokens.weight.detach() # tied LM head, [V, d]
12
13# Check that last_hidden_state is the post-norm state the LM head reads: logits must match.
14ids = encode(tok, parts["test"][:2])
15x, m = next(batches(ids, 2))
16with torch.no_grad():
17 ref = model(input_ids=x.to(DEV), attention_mask=m.long().to(DEV)).logits.float()
18 h = model.model(input_ids=x.to(DEV), attention_mask=m.long().to(DEV)).last_hidden_state
19 mine = (h @ E.T).float()
20md = (ref - mine)[m.to(DEV)].abs().max().item()
21print("logit check max abs diff", md)
22assert md < 1e-2, md
23
24info = {"logit_check_max_abs_diff": md}
25for name, exs in parts.items():
26 t0 = time.time()
27 X, Y = extract_final(model, encode(tok, exs), CAP[name])
28 torch.save({"X": X, "Y": Y}, os.path.join(SCRATCH, f"e1-{name}.pt"))
29 info[name] = {"examples_available": len(exs), "tokens": int(X.shape[0]), "d": int(X.shape[1]),
30 "sha256_X": sha_of_tensor(X), "seconds": time.time() - t0}
31 print(name, info[name])
32torch.save(E.float().cpu(), os.path.join(SCRATCH, "e1-embed.pt"))
33info["peak_gpu_bytes"] = torch.cuda.max_memory_allocated()
34receipt("e1-extract", info)