Cion-lab commited on
Commit
e687c2c
·
verified ·
1 Parent(s): 9bf38c0

preflight: assert the trapezoid SHAPE (off-by-one at the last step is expected, not a bug)

Browse files
Files changed (1) hide show
  1. train/preflight.py +15 -5
train/preflight.py CHANGED
@@ -109,8 +109,9 @@ mults = []
109
  for i in range(steps):
110
  mults.append(sch.lr_lambdas[0](i))
111
  sch.optimizer.param_groups[0]["lr"] = 6e-4 * mults[-1]
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
@@ -145,16 +146,25 @@ _emit(R)
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.
152
  and j.get("shapes_20L", {}).get("sum_numel") == 99114048
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
 
 
109
  for i in range(steps):
110
  mults.append(sch.lr_lambdas[0](i))
111
  sch.optimizer.param_groups[0]["lr"] = 6e-4 * mults[-1]
112
+ R["lr_shape"] = {"peak": max(mults), "at_step76": mults[76], "at_80pct": mults[int(steps*0.8)],
113
  "at_90pct": mults[int(steps*0.9)], "final": mults[-1],
114
+ "hits_zero_only_past_last_step": mults[-1] > 0.0,
115
  "plateau_fraction_steps": round(sum(1 for x in mults if x > 0.999) / steps, 3)}
116
  # one real forward/backward on CPU with a tiny model to prove the collator output feeds the model.
117
  # The report is printed BEFORE this optional probe: v3 of pargs lost every finding it had made because
 
146
  R["PARGS_n_blocks"] = max(0, len(blocks) - 1)
147
  R["PARGS_rc"] = r["rc"]
148
  j = j or {}
149
+ lr = j.get("lr_shape") or {}
150
+ # Test the SHAPE of the schedule, not one value: flat plateau, then linear to ~0 at the final
151
+ # update. (v4 asserted final == 0.0 and failed on 0.0013 -- LambdaLR reaches 0 at step T, which is
152
+ # one past the last update at T-1. Every cosine implementation shares that off-by-one; the honest
153
+ # assertion is "effectively zero at the last step", not "exactly zero".)
154
+ shape_ok = (lr.get("peak") == 1.0 and lr.get("at_80pct") == 1.0
155
+ and 0.45 < lr.get("at_90pct", -1) < 0.55
156
+ and 0.0 <= lr.get("final", 1.0) < 0.005
157
+ and 0.70 < lr.get("plateau_fraction_steps", 0) < 0.85)
158
  R["PARGS_pass"] = bool(j.get("PARGS_DONE") and j.get("kwargs") == "accepted"
159
  and j.get("params", {}).get("sum_numel") == 106194240
160
  # 20L must be 99,114,048 per docs/01-plan.md §2.3's closed-form table, and its
161
  # FFN must stay 1536; a doubled FFN would make test T1 meaningless.
162
  and j.get("shapes_20L", {}).get("sum_numel") == 99114048
163
+ and j.get("shape20_ffn") == 1536 and shape_ok
 
164
  and (j.get("forward_backward") or {}).get("finite"))
165
+ print("VERDICT PARGS_pass=", R["PARGS_pass"], "blocks=", R["PARGS_n_blocks"], "shape_ok=", shape_ok,
166
+ json.dumps({k: j.get(k) for k in ("transformers", "torch", "kwargs", "params", "shapes_20L",
167
+ "lr_shape", "forward_backward")}, default=str)[:700],
168
  flush=True)
169
 
170