devnull37 commited on
Commit
5648e53
·
verified ·
1 Parent(s): 0650b2b

Upload ROOT_CAUSE_BUDGET28.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. ROOT_CAUSE_BUDGET28.md +215 -0
ROOT_CAUSE_BUDGET28.md ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Root cause: budget28 run (28B tokens) produced an incoherent model
2
+
3
+ Date: 2 Jul 2026 (UAE). Run: distill→SFT→GRPO on 1×H100, preset `budget28`
4
+ (~28B tokens, ~$358). Pipeline completed mechanically; all checkpoints valid and
5
+ loadable. The final model does not produce coherent text.
6
+
7
+ > **UPDATE (2 Jul 2026, evening): the primary root cause was found and is NOT
8
+ > what the first analysis below concluded.** See "Definitive root cause (found
9
+ > by experiment)" at the end. In particular, "the model learned unigram
10
+ > statistics and stopped" is **refuted**: the budget28 model reconstructs
11
+ > *unseen* English text with 98–100% accuracy from up to 90% noise. The model
12
+ > learned strong conditional structure; it is blind only at exactly t=1.0 —
13
+ > the pure-noise starting point of every generation. The KD-off finding below
14
+ > remains true and still matters, but it is secondary.
15
+
16
+ ## Symptom
17
+
18
+ All three checkpoints (`distill/final.pt`, `sft/final.pt`, `grpo/final.pt`)
19
+ emit individually-plausible English tokens with **no grammatical structure**
20
+ ("word salad"). SFT/GRPO look slightly *more* degenerate than the distill base
21
+ (collapse toward "is/the/0"; GRPO adds digit-spam from math RL). No prompt is
22
+ answered; e.g. "What is 2 + 3?" gets unrelated tokens.
23
+
24
+ ## Ruled out
25
+
26
+ 1. **Checkpoint corruption** — strict load 0 missing / 0 unexpected vs embedded
27
+ config (after the 49152→49154 block-CoT vocab override). No NaN/Inf.
28
+ 2. **Wrong/undersized architecture at load** — verified d_model=576, 30 layers,
29
+ weight-tied, matches config.
30
+ 3. **Sampler/schedule mismatch** — the model was trained with
31
+ `use_flow_matching=True`; tested BOTH `sample_from_model` (DDIM/DPM++, wrong
32
+ family) AND the correct `sample_from_model_flow` (Euler n=20; Heun n=50;
33
+ T∈{0.3, 0.8}; top_k=50). Word salad under every schedule. Not a decoding bug.
34
+ 4. **SFT/GRPO malfunction** — SFT ran its full two-stage schedule (~13,960
35
+ stage-1 + ~3,780 stage-2 steps, ~4h13m, stable loss ≈0.29–0.33). GRPO ran all
36
+ 2000 math steps, stable, kl<0.13 throughout. Both executed correctly — on a
37
+ base they could not fix. The pipeline *logged its own preconditions*:
38
+ - "SFT cannot fix an incoherent / undertrained base."
39
+ - "GRPO cannot bootstrap signal from an incoherent policy."
40
+ Both were violated; the warnings do not gate, so the run proceeded anyway.
41
+
42
+ ## Evidence: the Stage-3 loss plateaued at ~1.6B of the 28B tokens
43
+
44
+ Stage-3 diffusion CE (batch 64 × seq 512 on H100):
45
+
46
+ | step (frozen /549,316) | loss |
47
+ |---|---|
48
+ | 50 | 13.50 |
49
+ | 250 | 1.57 |
50
+ | 50,000 (~1.6B tok) | **0.360** |
51
+ | 100,000 | 0.357 |
52
+ | 300,000 | 0.374 |
53
+ | 549,316 (end, 18B tok) | 0.377 |
54
+ | unfrozen 50,000 | 0.360 |
55
+ | unfrozen 305,176 (end, +10B tok) | 0.349 |
56
+
57
+ Loss reached ~0.35 within ~1.6B tokens and did not improve for the remaining
58
+ ~26B. **Token budget was not the bottleneck; the model converged to a bad
59
+ optimum almost immediately.** (Loss floor ~0.09–0.10 was touched only in early
60
+ transients.) The output signature — correct marginal token distribution, no
61
+ conditional structure — matches a model that learned unigram statistics and
62
+ stopped.
63
+
64
+ ## Root cause (two compounding design gaps)
65
+
66
+ ### 1. The teacher was only connected for 1,000 steps out of ~855k
67
+
68
+ ```
69
+ stage1 (matrix align → teacher attn): 500 steps
70
+ stage2 (hidden align → teacher residual): 500 steps
71
+ stage3 (ALL 28B tokens): kd_weight = 0.0 ← teacher unused
72
+ ```
73
+
74
+ Stage 3 — 99.9% of compute — was **from-scratch diffusion pretraining** of a
75
+ 135M model with no KD signal, from a warm init. That is not distillation; the
76
+ 28B tokens carried none of SmolLM's competence. Diffusion LMs are substantially
77
+ more sample-hungry than AR models at equal size; 28B tokens from-scratch at
78
+ 135M is far below what coherence requires under this objective.
79
+
80
+ ### 2. Double distribution gap: AR→diffusion AND causal→bidirectional
81
+
82
+ The teacher (SmolLM-135M) is causal autoregressive; the student is a
83
+ bidirectional flow-matching denoiser. The config's own comment acknowledges the
84
+ signal dilution. Stage-1/2 alignment (1,000 steps total, stage2 ended at loss
85
+ 0.556 — not obviously converged) is far too little bridge for both gaps at
86
+ once, and then the bridge was removed entirely for Stage 3.
87
+
88
+ ## Why the babysitting metrics looked "healthy"
89
+
90
+ - Distill loss ~0.35 stable → read as converged-and-training; the *absolute*
91
+ level of a min-SNR-weighted x0-prediction loss is not interpretable like AR
92
+ CE, so "flat and low-ish" hid "flat because collapsed".
93
+ - GRPO flat reward 0.00 was attributed to 135M math weakness; it was actually
94
+ the policy having no coherent behaviour to reward at all.
95
+ - **Lesson:** loss curves cannot substitute for a generation-based coherence
96
+ gate between phases.
97
+
98
+ ## Fixes for the next run (in order of importance)
99
+
100
+ 1. **Keep KD on through Stage 3** (`kd_weight > 0`, e.g. anneal 1.0→0.3).
101
+ Teacher forward on the same batch; distill logits (and optionally hidden
102
+ states) into the denoiser's x0 prediction. This is the single change most
103
+ likely to matter. Costs a teacher forward pass — at 135M this is cheap
104
+ relative to the student's diffusion step.
105
+ 2. **Make the coherence gate BLOCKING.** After Stage 3 (and again after SFT),
106
+ run N fixed prompts through `sample_from_model_flow`; require a minimal
107
+ grammaticality/perplexity bar (e.g. teacher-scored PPL of samples under a
108
+ threshold) before the pipeline advances. The warnings already exist —
109
+ convert them to hard asserts.
110
+ 3. **Stop on plateau, don't burn the budget.** Early-stop Stage 3 when loss
111
+ improvement < ε over a window (this run: would have saved ~26B tokens ≈ 93%
112
+ of Stage-3 compute for reallocation or refund).
113
+ 4. **Longer Stage-1/2 alignment** (≥5–10k steps each, until stage2 hidden-align
114
+ loss actually flattens), since these 1,000 steps are the only bridge across
115
+ the AR→diffusion gap.
116
+ 5. **Consider staging the conversion:** distill SmolLM → *causal AR* Mamba-2
117
+ first (pure MOHAWK, known-good regime, 3–5B tokens), verify coherence, THEN
118
+ convert AR-Mamba → diffusion with the AR model as teacher. One gap at a
119
+ time, each with a checkable intermediate.
120
+ 6. **Cheap validation before any big spend:** the plateau shows up by ~1.6B
121
+ tokens (~3–4 H100-hours). Any candidate fix can be validated with a ~1–2B
122
+ token run + the blocking coherence gate before committing to a full budget.
123
+
124
+ ## Definitive root cause (found by experiment, 2 Jul 2026 evening)
125
+
126
+ A chain of cheap controlled experiments (~$3 total, scratchpad scripts) located
127
+ the true failure. All on the exact production architecture (d_model=576, 30
128
+ layers, flow matching, logit-normal t, bf16).
129
+
130
+ ### Experiment chain
131
+
132
+ 1. **Overfit contract test** (`overfit_test.py`): train from scratch on 8 fixed
133
+ sentences with the *identical* stage-3 loss path until memorized.
134
+ Result: t=0 clean-pass reconstruction accuracy **1.000**, yet
135
+ `sample_from_model_flow` produced unigram soup ("in in the the, and…").
136
+ → the train→sample contract itself is broken; no token budget or KD signal
137
+ could ever have produced coherent generations.
138
+ 2. **Diffusion-LM clamp trick** (`clamp_sample_test.py`): snapping x0̂ to the
139
+ nearest token embedding each ODE step (all-steps and late-steps variants,
140
+ Euler/Heun). **Refuted** — still soup. Not a sampler-level fix.
141
+ 3. **Partial-noise recovery ladder** (`partial_noise_test.py`) — the decisive
142
+ experiment. Noise a known row to level t_start, integrate the flow ODE to 0:
143
+
144
+ | t_start | 0.1 | 0.3 | 0.5 | 0.7 | 0.8 | 0.9 | **1.0** |
145
+ |---|---|---|---|---|---|---|---|
146
+ | recovery (overfit model) | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | **0.02** |
147
+ | recovery (budget28, UNSEEN text) | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.98–1.00 | **0.00–0.01** |
148
+
149
+ A razor-sharp cliff at exactly t=1.0. The model is an excellent denoiser
150
+ whenever *any* true signal exists and blind only at pure noise — which is
151
+ where every real generation must start.
152
+
153
+ ### Mechanism
154
+
155
+ Two compounding terms in `compute_dimba_losses`:
156
+
157
+ - **min-SNR weighting kills the high-t gradient.** `snr_flow = ((1−t)/t)²`
158
+ clamped to [1e-3, 5]: at t=0.9 the diffusion loss weight is ~0.012, at t≈1 it
159
+ is 1e-3. The model gets essentially no gradient pressure to make its x0̂
160
+ *depend on the input noise* at high t, so it converges to a constant
161
+ posterior-mean blend there.
162
+ - **The unweighted CE anchor actively teaches unigram output at high t.** CE is
163
+ applied at full strength at every t; from pure noise its optimum is the
164
+ marginal token distribution. The model is literally trained to emit
165
+ "in/the/and/," when shown noise.
166
+
167
+ At sampling time the ODE starts at t=1.0 in exactly that regime: the first
168
+ steps write a noise-independent unigram-blend seed, and the (excellent)
169
+ denoiser then faithfully amplifies that garbage seed into polished soup. This
170
+ also explains why the stage-3 loss plateau was misread: the min-SNR-weighted
171
+ loss was dominated by well-trained mid/low-t regions and could not show that
172
+ the high-t region was dead.
173
+
174
+ ### Fix (validated at overfit scale, `overfit_v2_fixedloss.py`)
175
+
176
+ Two lines in the objective, plus t-coverage:
177
+
178
+ 1. `weight = clamp(snr_flow, min=0.5, max=5.0)` (was min=1e-3) — forces the
179
+ model to learn noise-*dependent* prediction at high t.
180
+ 2. `ce_loss = (ce_per_sample * (1 − t)).mean()` — the CE anchor fades at high
181
+ noise instead of teaching unigram there.
182
+ 3. 50/50 uniform/logit-normal timestep sampling (logit-normal alone
183
+ undersamples t≈1).
184
+
185
+ Result: free generation from pure noise went from pure unigram soup to
186
+ locally-coherent memorized phrases. Remaining known gap: **global mode
187
+ commitment** — the sample stitches fragments of different memorized rows
188
+ (topic drift). Clamp trick and high-t-dense ODE schedules do not fix the
189
+ drift; it appears to need training-scale exposure and/or architectural work
190
+ (bidirectional Mamba's effective range through noise). For natural-language
191
+ (non-memorization) generation, "locally coherent with drift" is the normal
192
+ operating point of weak continuous text diffusion — categorically better than
193
+ budget28's output.
194
+
195
+ ### Consequence for the budget28 checkpoint
196
+
197
+ The dead zone lives in the **weights** (trained under the broken weighting), so
198
+ no sampler patch can rescue `distill/final.pt` as-is. However, the ladder shows
199
+ the 28B tokens bought a genuinely strong denoiser for t ≤ 0.9 on unseen text.
200
+ A **repair finetune** — resume from `final.pt` with the fixed objective,
201
+ oversampling high t — only needs to teach the thin t∈(0.9, 1.0] slice and is
202
+ the cheapest plausible path to recovering the $358 investment (est. 1–4 H100
203
+ hours to first signal, vs 100+ hours to retrain).
204
+
205
+ ## Artifacts
206
+
207
+ - Checkpoints: `checkpoints/{distill,sft,grpo}/final.pt` (+ `grpo/math/`).
208
+ - Full log: `~/dimba_train.log` (filter `grep -vE "httpx|HTTP Request|cas-bridge|examples/s"`).
209
+ - Inference test scripts (correct loaders, incl. flow sampler):
210
+ scratchpad `infer_gpu_cmp.py`, `infer_flow.py`, `infer_cpu_multi.py`.
211
+ - Root-cause experiment scripts (scratchpad, 2 Jul): `overfit_test.py`,
212
+ `clamp_sample_test.py`, `partial_noise_test.py`, `overfit_v2_fixedloss.py`,
213
+ `dense_schedule_test.py`; logs `~/dimba_overfit*.log`; trained probes
214
+ `overfit_model.pt`, `overfit_v2_model.pt` (scratchpad — ephemeral).
215
+ - HF backup repo: `devnull37/d1-135m-50b` (private).