Cion-lab commited on
Commit
48c0e43
·
verified ·
1 Parent(s): 51574f8

train: preflight -- readback counts as verification; GQA kv must divide heads; pargs reports before optional probe

Browse files
Files changed (1) hide show
  1. train/preflight.py +34 -16
train/preflight.py CHANGED
@@ -112,24 +112,40 @@ for i in range(steps):
112
  R["lr_shape"] = {"peak": max(mults), "at_warm_end": mults[76], "at_80pct": mults[int(steps*0.8)],
113
  "at_90pct": mults[int(steps*0.9)], "final": mults[-1],
114
  "plateau_fraction_steps": round(sum(1 for x in mults if x > 0.999) / steps, 3)}
115
- # one real forward/backward on CPU with a tiny model to prove the collator output feeds the model
116
- cfg2 = T.build_config(64, layers=2, hidden=128)
117
- m2 = T.LlamaForCausalLM(cfg2)
118
- store_ids = torch.randint(0, 1000, (3, 65))
119
- out = m2(input_ids=store_ids[:, :-1], labels=store_ids[:, 1:],
120
- attention_mask=torch.ones_like(store_ids[:, :-1]))
121
- out.loss.backward()
122
- R["forward_backward"] = {"loss": round(float(out.loss), 4), "finite": math.isfinite(float(out.loss)),
123
- "grads": sum(1 for p in m2.parameters() if p.grad is not None)}
124
- print("ARGS_JSON_BEGIN")
125
- print(json.dumps(R, default=str))
126
- print("ARGS_JSON_END")
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  '''
128
  r = sh([sys.executable, "-c", src], timeout=3600, label="Pargs construct on the Kaggle image")
129
- R["PARGS"] = last_json(r["out"], "ARGS_JSON_BEGIN", "ARGS_JSON_END")
 
 
 
130
  R["PARGS_rc"] = r["rc"]
131
- j = R["PARGS"] or {}
132
- R["PARGS_pass"] = bool(r["rc"] == 0 and j.get("kwargs") == "accepted"
133
  and j.get("params", {}).get("sum_numel") == 106194240
134
  # 20L must be 99,114,048 per docs/01-plan.md §2.3's closed-form table, and its
135
  # FFN must stay 1536; a doubled FFN would make test T1 meaningless.
@@ -137,7 +153,9 @@ print("ARGS_JSON_END")
137
  and j.get("shape20_ffn") == 1536
138
  and (j.get("lr_shape") or {}).get("final") == 0.0
139
  and (j.get("forward_backward") or {}).get("finite"))
140
- print("VERDICT PARGS_pass=", R["PARGS_pass"], json.dumps(j.get("kwargs"))[:200], flush=True)
 
 
141
 
142
 
143
  # ------------------------------------------------------------------------ P0 reader (CPU, free)
 
112
  R["lr_shape"] = {"peak": max(mults), "at_warm_end": mults[76], "at_80pct": mults[int(steps*0.8)],
113
  "at_90pct": mults[int(steps*0.9)], "final": mults[-1],
114
  "plateau_fraction_steps": round(sum(1 for x in mults if x > 0.999) / steps, 3)}
115
+ # one real forward/backward on CPU with a tiny model to prove the collator output feeds the model.
116
+ # The report is printed BEFORE this optional probe: v3 of pargs lost every finding it had made because
117
+ # the last block raised and the print at the end never ran (E-012, reproduced in code written an hour
118
+ # earlier -- the guard is not enough, the ordering is the fix).
119
+ def _emit(R, tag="ARGS_JSON"):
120
+ print(tag + "_BEGIN")
121
+ print(json.dumps(R, default=str))
122
+ print(tag + "_END")
123
+
124
+
125
+ _emit(R)
126
+ try:
127
+ cfg2 = T.build_config(64, layers=2, hidden=128)
128
+ m2 = T.LlamaForCausalLM(cfg2)
129
+ ids = torch.randint(1, 1000, (3, 65))
130
+ o = m2(input_ids=ids[:, :-1], labels=ids[:, 1:], attention_mask=torch.ones_like(ids[:, :-1]))
131
+ o.loss.backward()
132
+ fb = {"kv_heads": cfg2.num_key_value_heads, "loss": round(float(o.loss), 4),
133
+ "finite": math.isfinite(float(o.loss)),
134
+ "grads": sum(1 for p in m2.parameters() if p.grad is not None)}
135
+ except Exception as e:
136
+ fb = {"error": f"{type(e).__name__}: {str(e)[:220]}"}
137
+ R["forward_backward"] = fb
138
+ R["PARGS_DONE"] = True
139
+ _emit(R)
140
  '''
141
  r = sh([sys.executable, "-c", src], timeout=3600, label="Pargs construct on the Kaggle image")
142
+ blocks = r["out"].split("ARGS_JSON_BEGIN")
143
+ j = last_json(r["out"], "ARGS_JSON_BEGIN", "ARGS_JSON_END")
144
+ R["PARGS"] = j
145
+ R["PARGS_n_blocks"] = max(0, len(blocks) - 1)
146
  R["PARGS_rc"] = r["rc"]
147
+ j = j or {}
148
+ R["PARGS_pass"] = bool(j.get("PARGS_DONE") and j.get("kwargs") == "accepted"
149
  and j.get("params", {}).get("sum_numel") == 106194240
150
  # 20L must be 99,114,048 per docs/01-plan.md §2.3's closed-form table, and its
151
  # FFN must stay 1536; a doubled FFN would make test T1 meaningless.
 
153
  and j.get("shape20_ffn") == 1536
154
  and (j.get("lr_shape") or {}).get("final") == 0.0
155
  and (j.get("forward_backward") or {}).get("finite"))
156
+ print("VERDICT PARGS_pass=", R["PARGS_pass"], "blocks=", R["PARGS_n_blocks"],
157
+ json.dumps({k: j.get(k) for k in ("transformers", "torch", "kwargs", "forward_backward")})[:400],
158
+ flush=True)
159
 
160
 
161
  # ------------------------------------------------------------------------ P0 reader (CPU, free)