AbhishekGhosh1998 commited on
Commit
5e43d89
·
verified ·
1 Parent(s): 15f7f8f

Upload SESSION_LOG_MOONEP_FIX_AND_RERUNS.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. SESSION_LOG_MOONEP_FIX_AND_RERUNS.md +311 -0
SESSION_LOG_MOONEP_FIX_AND_RERUNS.md ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Session log — MoonEP gradient fix, Tier B rerun, Tier A rerun
2
+
3
+ Date: 2026-08-29 → 2026-08-30. Hardware: 8×B200, pod
4
+ `sp-aiinfra-interactive-aghosh-7jtjl`.
5
+
6
+ This records one continuous piece of work: finding and fixing a MoonEP training
7
+ correctness bug, re-measuring Tier B on the fixed stack, and then re-measuring
8
+ the whole Tier A ladder — which turned out to have a second, independent defect
9
+ of its own. It is written so the results can be trusted or challenged without
10
+ the pod existing.
11
+
12
+ ---
13
+
14
+ ## 1. The MoonEP gradient bug
15
+
16
+ ### Symptom
17
+
18
+ The mandatory ECHO-vs-MoonEP correctness gate failed with 55 differences. The
19
+ forward pass was **bit-exact on all 8 ranks** — router logits, probabilities, MoE
20
+ output, and a loss matching to 16 digits — and all 4 structural gates passed.
21
+ Only gradients differed: **0/32 expert gradients exact**, and post-step weights
22
+ diverged on exactly ranks 1, 5 and 6.
23
+
24
+ ### Two false leads, both discarded on evidence
25
+
26
+ A uniform `0.800259×` under-scale on every reduced gradient looked like a second
27
+ defect. It was not: `clip_grad=1.0`, ECHO's grad norm was 1.888 and MoonEP's
28
+ 2.359, and `1.888 / 2.359 = 0.80034`. It was gradient clipping responding to an
29
+ already-wrong gradient. **One bug, not two.**
30
+
31
+ Two of my own hypotheses were also wrong and were retracted:
32
+
33
+ * a pointer-based alias mismatch — meaningless under VMM, which maps the same
34
+ physical pages at different virtual addresses. A sentinel write/read showed
35
+ `aliases=YES`.
36
+ * intra-segment padding pollution — MoonEP already zeroes it via
37
+ `zero_fill_ranges`.
38
+
39
+ Ruled out by direct measurement: the `reduce_grad` kernel itself
40
+ (`delta/sum=1.0000`, `cos=1.0000`, 12/12 and 5/5 tests pass), prefetch slot
41
+ weights (byte-exact), padding, memory aliasing, and the incoming gradients.
42
+
43
+ ### Root cause
44
+
45
+ With `--overlap-grad-reduce`, DDP multiplies each expert bucket by
46
+ `1/dp_size` **during backward**, as soon as every parameter it owns has reported
47
+ (`param_and_grad_buffer.py:313`). MoonEP's prefetch-slot parameters are
48
+ deregistered from `nn.Module` before DDP is built, so DDP never waits for them;
49
+ the replica weight-gradient lands in MoonEP's process-global pool, outside the
50
+ DDP buffer, and `reduce_grad` folds it into the home rows *after* the multiply.
51
+
52
+ The result is `(1/8)·home + replica` where `(1/8)·(home + replica)` was intended
53
+ — the duplicated-expert contribution ends up **8× too large**.
54
+
55
+ This is not specific to async: within a layer's backward the weight-gradient
56
+ hooks fire before `MoonEPDispatch.backward` runs `reduce_grad`. Proven by A/B —
57
+ with overlap off the grad norm is exactly ECHO's 1.888.
58
+
59
+ ### The fix, and a wrong turn on the way
60
+
61
+ **Option 4 (signal-at-launch, then `stream.wait_event` before scaling) is
62
+ correct but catastrophic for performance.** The scaling runs on the *main*
63
+ stream, so waiting there drags the deferred side-stream reduce onto the critical
64
+ path: async overlap collapsed from 96.6% to **0.0%**, exposing all 5.6 ms/iter.
65
+ I had recommended Option 4 over Option 2 in writing; that recommendation was
66
+ wrong and is corrected in the docs.
67
+
68
+ **Option 2 is the answer.** A bucket that has external contributors never
69
+ auto-starts its sync; `finish_grad_sync` runs it from `finalize_model_grads`,
70
+ after `join_all_pending_reduce_grad`. Correct ordering, **zero added
71
+ synchronisation**.
72
+
73
+ | metric | pre-fix | fixed |
74
+ | --- | ---: | ---: |
75
+ | grad norm, graph off (ECHO = 1.888) | 2.359 | **1.888** |
76
+ | grad norm, graph on | 2.322 | **1.880** |
77
+ | expert gradients exact | 0/32 | **32/32** |
78
+ | `reduce_grad` overlap | 96.6% | **96.3%** |
79
+ | gate failures | 55 | 6 (benign) |
80
+
81
+ The 6 residual failures are the gate's sensitivity, not a defect: the differing
82
+ elements have **median |grad| exactly 0.0**, the gate runs `lr=1e-2` with no
83
+ warmup, and Adam's first step is `lr·sign(g)` — so a meaningless sign flip on a
84
+ zero gradient moves a weight by `2·lr` = 2e-2, exactly the observed `max_abs`.
85
+ The fix is to compare only non-zero-gradient elements, or lower the gate's lr —
86
+ **not** to widen the tolerance. This remains open for a decision.
87
+
88
+ The fix is Megatron-side only; MoonEP itself is unmodified. It was cherry-picked
89
+ to all three composite branches so probe and memory campaigns cannot mistrain:
90
+
91
+ | branch | head |
92
+ | --- | --- |
93
+ | `moonep_backend_async_grad_reduce` | `2e68c8ad` |
94
+ | `..._token_routing_analysis` | `a6a1a221` |
95
+ | `..._better_memory_dump_support` | `7949f384` |
96
+
97
+ ---
98
+
99
+ ## 2. Tier B rerun on the fixed stack
100
+
101
+ Study root `tierb-fixed-moonep-full/`, GBS 8.
102
+
103
+ **All four models now fit.** QWEN3_235B 182,589 → **120,129 MiB** and QWEN3_30B
104
+ 175,959 → **116,419 MiB**, both previously `DOES_NOT_FIT`. The saving is 32–46
105
+ GiB and comes from the DDP-owned symmetric-parameter MoonEP source branch, not
106
+ from the gradient fix: the pre-fix stack genuinely held two copies of every
107
+ expert weight. **The old `DOES_NOT_FIT` verdicts are obsolete and must not be
108
+ reused.**
109
+
110
+ Async overlap on real models, 8 devices: 96.0% (QWEN3_235B), 96.0% (QWEN2_57B),
111
+ 91.8% (DSV2_LITE), 88.4% (QWEN3_30B) — the load-bearing evidence that the
112
+ correctness repair costs no exposed time.
113
+
114
+ Iteration time (ms, mean of 3; ECHO/UltraEP carried over from the previous
115
+ campaign, identical config):
116
+
117
+ | model | ECHO | UltraEP | MoonEP |
118
+ | --- | ---: | ---: | ---: |
119
+ | QWEN3_235B | 312.04 | **297.87** | 317.52 |
120
+ | QWEN3_30B | 389.66 | **353.69** | 354.68 |
121
+ | DSV2_LITE_L24 | 587.49 | **579.99** | 593.03 |
122
+ | QWEN2_57B | **178.75** | 192.45 | 180.37 |
123
+
124
+ ---
125
+
126
+ ## 3. Tier A rerun
127
+
128
+ Study root `tiera-rerun-fixed-moonep/`, GBS 16, seq 4096.
129
+
130
+ Tier A had **two** defects: its MoonEP column came from the mistraining stack,
131
+ and every cell ran at a hardcoded capacity of 1.25 that nothing had verified.
132
+
133
+ ### The capacity finding
134
+
135
+ Measured zero-drop requirement per rung:
136
+
137
+ | rung | ECHO | UltraEP | ran at | verdict |
138
+ | --- | ---: | ---: | ---: | --- |
139
+ | **G1** | **1.859** | **2.406** | 1.25 | **both backends dropped tokens** |
140
+ | G2 | 1.082 | 1.063 | 1.25 | fine |
141
+ | G3 | 1.072 | 1.063 | 1.25 | fine |
142
+ | G4 | 1.068 | 1.096 | 1.25 | fine |
143
+
144
+ G4 needed *less* than 1.25, not more. G1 is a factor-of-two outlier because 8
145
+ experts at top-2 across 8 ranks has almost nothing to average imbalance over.
146
+ That the cause is imbalance rather than shape is settled by the probe's
147
+ force-balanced control: **G1 needs only 1.01** when balancing is forced.
148
+
149
+ The defect is therefore isolated to G1 — and G1 is precisely the rung the
150
+ published headline rested on. A dropping run does less expert work and looks
151
+ faster, so that row cannot support the claim.
152
+
153
+ ### Why one global capacity was impossible
154
+
155
+ The global max is 2.40625, driven entirely by G1. Rather than discover the
156
+ consequence after a full timing stage, I gated it on the two extreme rungs
157
+ directly (CUDA graphs on, one cell each, ~1 minute):
158
+
159
+ | gate | capacity | peak | verdict |
160
+ | --- | ---: | ---: | --- |
161
+ | G4/echo | 2.40625 | 182,627 MiB | **OOM** (ceiling 182,630) |
162
+ | G1/echo | 2.40625 | 161,863 MiB | OK |
163
+
164
+ So the campaign uses **one capacity per rung**. Within a rung every backend still
165
+ shares one capacity, so the backend comparison stays valid; only the cross-rung
166
+ trend must be read alongside the capacity column. Evidence preserved in
167
+ `capacity_gate/`.
168
+
169
+ The probe's own ladder could not resolve G1 — ECHO tops out at 2.00 and UltraEP
170
+ starts at 1.25 and was still dropping at 1.8125. A dropping run **under-reports**
171
+ demand, because `actual_valid_recv` is clipped at the buffer, which is why
172
+ UltraEP's estimate climbed 1.72 → 2.31 as capacity rose. G1 was re-probed at a
173
+ 3.00 ceiling, where both backends measured cleanly with zero drops.
174
+
175
+ ### Results
176
+
177
+ 81 timing rows, 3 unprofiled repeats each, zero drops, zero failures.
178
+
179
+ `a2` (ms) and peak memory (MiB):
180
+
181
+ | rung | ECHO | UltraEP | MoonEP | ECHO mem | UltraEP mem | MoonEP mem |
182
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
183
+ | G1 | **466.8** | 892.7 | 480.6 | 161,723 | 129,475 | **96,849** |
184
+ | G2 | **415.4** | 492.3 | 432.2 | 145,691 | 112,315 | **97,665** |
185
+ | G3 | **437.2** | 459.7 | 559.9 | 147,933 | 113,951 | **99,409** |
186
+ | G4 | 486.7 | **482.9** | 782.8 | 168,485 | 132,437 | **106,031** |
187
+
188
+ MoonEP async overlap falls sharply with expert size — 97.2% at G2 but **53.5% at
189
+ G1**, where the reduce is 58 ms/iter, too large to hide behind one layer's
190
+ backward. At G4 the expert is 16× narrower, the reduce costs 10.8 ms, and 94%
191
+ disappears.
192
+
193
+ ### MoonEP can run the one-slot phases after all
194
+
195
+ `RESULTS.md` claimed MoonEP cannot appear in `a1`/`ponly` by construction. **That
196
+ is true only for G2–G4.** MoonEP forces `B = E/R`, which conflicts with the
197
+ one-slot policy only when `E/R > 1`; G1 and PONLY are both `E=8`, so at `R=8` the
198
+ forced value already *is* one slot. A blanket backend-level skip in
199
+ `phase_a1`/`phase_ponly` was discarding runnable cells.
200
+
201
+ New numbers: MoonEP `a1` at G1 = 479.1 ms, and MoonEP `ponly` = **165.2 ms** at
202
+ seq 4096 (fastest of the three) and 300.6 ms at seq 8192. As an internal check,
203
+ MoonEP G1 in `a1` (479.1) and `a2` (480.6) are the same `B=1` configuration
204
+ measured twice and agree to 0.3%.
205
+
206
+ PONLY inherited G1's capacity rather than being probed, on the grounds that it
207
+ shares `E=8`/`K=2`. A higher capacity cannot cause drops so this is safe, but it
208
+ is an inheritance, not a measurement.
209
+
210
+ ### Two published conclusions do not survive
211
+
212
+ *"ECHO wins only at the coarsest rung; UltraEP wins everywhere finer."* Not
213
+ reproduced. ECHO wins G1, G2 and G3; UltraEP wins only G4, by 0.8%.
214
+
215
+ *"UltraEP is 30–35 GB lighter than ECHO at every rung."* Still true of that pair,
216
+ but **MoonEP is now the lightest backend at every rung**, 97–106 GB against
217
+ UltraEP's 112–132 GB — down from its published 154–166 GB.
218
+
219
+ MoonEP's throughput also moved from slowest everywhere to second at G1/G2, though
220
+ it still degrades fastest along the ladder. **This is not a speedup measurement:**
221
+ the published stack computed something different, so the difference across the
222
+ fix is not an optimization delta. Treat the new column as a first correct
223
+ baseline.
224
+
225
+ ---
226
+
227
+ ## 4. Bugs found in the harness
228
+
229
+ Six, all of which fail *quietly*, which is why each is recorded.
230
+
231
+ **`[ cond ] && return 0` inside a function under `set -e`.** When the condition
232
+ is false the list evaluates non-zero, and because that is the function's value
233
+ the whole driver exits with no error message. The Tier B campaign stopped after
234
+ the timing stage looking like a clean finish. Fixed with explicit `if`.
235
+
236
+ **`auto_study` refused to resume past any historical failure.** Its final line
237
+ was `grep -q '^FAIL' "$STEPS_TSV" && exit 1`, judging the whole accumulated file.
238
+ One superseded failure made every later `run_auto` return 1, which `set -e`
239
+ turned into a silent exit — stage 9 never reached its MoonEP block. Exit status
240
+ now covers only the rows the current invocation appended, judged by most-recent
241
+ status per campaign/phase.
242
+
243
+ **Completion markers ignored the axis a repeated phase varies.** The Tier A
244
+ per-rung memory sweep runs `tierbmem` once per rung, but the key was
245
+ `campaign__phase__gbs`. G1 completed, wrote `echo__tierbmem__gbs16`, and
246
+ G2/G3/G4 were skipped as "already completed" — allocator dumps for one rung out
247
+ of four, reported as success. Fixed with `STEP_KEY_SUFFIX` plus per-rung marker
248
+ assertions.
249
+
250
+ **`--no-nsys` cannot be applied globally.** `auto_study` gates stage 9 itself on
251
+ `NSYS`, so a global flag silently skips every trace. Per-cell tracing was
252
+ doubling the timing stage (13 min/cell → 3.9 with it off), so the flag is now
253
+ scoped to non-trace stages.
254
+
255
+ **MoonEP cells were tagged with a capacity they ignore.** `train_moe.sh` already
256
+ downgrades `CAPACITY_MODE=static` to `none` for MoonEP, so the run was never
257
+ affected — but the capacity went into the run-directory tag and the results
258
+ table, and would have re-tagged byte-identical cells as new measurements when the
259
+ capacity changed. Tier A now tags them `capnone`, as Tier B already did.
260
+
261
+ **`campaign.env` leaked onto `granularity-base`** via a blanket
262
+ `git add -A granularity/` made while on `granularity-echo`, making every
263
+ base→campaign merge conflict add/add. Removed from base; echo's copy restored.
264
+
265
+ A guard was also added for the class of error that started all this:
266
+ `run_ladder.sh` now refuses to run MoonEP unless the gradient fix is present in
267
+ the checkout. `STRICT_MOONEP_GRAD_FIX=0` overrides it, deliberately explicitly.
268
+
269
+ ---
270
+
271
+ ## 5. What was added to this repository
272
+
273
+ | file | status | purpose |
274
+ | --- | --- | --- |
275
+ | `run_tiera_rerun.sh` | new | Tier A driver: probe → capacity decision → timing → memory → traces |
276
+ | `tools/tiera_global_capacity.py` | new | derives global and per-rung capacities, enforces the executable grid |
277
+ | `TIERA_RERUN.md` | new | Tier A runbook, capacity methodology, results |
278
+ | `TIERB_FIXED_MOONEP_RESULTS.md` | new | Tier B results on the fixed stack |
279
+ | `TIERB_HF_ARTIFACT_INVENTORY.md` | new | what is on the hub and how to read it |
280
+ | `MOONEP_GRAD_BUG_AND_FIX.md` | new | the bug in full (Megatron repo, `moonep_grad_correctness`) |
281
+ | `lib/phases.sh` | changed | one-slot guard relaxed; `_tiera_cap`/`_tiera_capmode` |
282
+ | `lib/common.sh` | changed | `moonep_has_grad_fix`, `assert_moonep_grad_fix` |
283
+ | `run_ladder.sh` | changed | enforces the MoonEP fix assertion |
284
+ | `auto_study.sh` | changed | stage 3 runs all phases for MoonEP; `STEP_KEY_SUFFIX`; scoped exit status |
285
+ | `RESULTS.md` | changed | Tier A marked superseded; one-slot claim corrected |
286
+
287
+ Shared code lives on `granularity-base` and is merged outward; all four branches
288
+ carry byte-identical copies of every file above.
289
+
290
+ ## 6. Where the data is
291
+
292
+ HuggingFace `MoE-CUDA-Graph-Analysis/tierb-b200-gbs8` — a **model** repo, not a
293
+ dataset. Querying it as a dataset returns a 404 that looks like an auth failure.
294
+
295
+ | directory | files | contents |
296
+ | --- | ---: | --- |
297
+ | `tiera-rerun-fixed-moonep/` | 2,684 | Tier A: probe, a1/ponly/a2, memory, 12 traces, capacity gate |
298
+ | `tierb-fixed-moonep-full/` | 911 | Tier B on the fixed stack, 12 traces |
299
+ | `tierb-patch-rerun-.../moonep-grad-bug-analysis/` | 16 | rank dumps that isolated the bug |
300
+ | `tierb-patch-rerun-.../moonep-grad-bug-fix/` | 13 | fix validation, graph-on A/B |
301
+
302
+ ## 7. Open items
303
+
304
+ * The 6 residual correctness-gate failures need a decision: compare only
305
+ non-zero-gradient elements, or lower the gate's lr. Not a tolerance change.
306
+ * Synchronous MoonEP reduce with `--overlap-grad-reduce` is untested; it selects
307
+ a different branch.
308
+ * The fix's cost at `edp > 1` is unmeasured. Both campaigns ran `edp = 1`, so the
309
+ expert-gradient collective was a no-op.
310
+ * Whether real models ever produce more than one expert bucket is unverified.
311
+ * PONLY's capacity is inherited from G1, not measured.