Commit 8936ce4
committed
wip(metal-mamba3-bwd): root-cause Metal pipeline crash + dedup forward-recompute
ROOT CAUSE (isolated by bisection at full local_gb10_quarter scale, hidden=3584,
seq=4096, the mamba3_mimo_bwd segment chain_12_13):
The crash at Metal newComputePipelineState (XPC_ERROR_CONNECTION_INTERRUPTED in
MTLCompilerService) is NOT primarily MSL byte-size. It is caused by
``T.sync_threads()`` (threadgroup_barrier) emitted INSIDE the data-dependent
reverse-time checkpoint-replay loop. Evidence (each variant compiled+run-probed
in isolation via CPPMEGA_MAMBA3_BWD_CHOP):
- init-only (zero grads, 22.8 KB) -> COMPILES (ok, 512 launches)
- reverse loop + checkpoint loads, no replay (no_replay) -> COMPILES (ok)
- replay loop + trivial body, no barriers (bare_replay) -> COMPILES (ok)
- replay loop + recompute (barriers in loop, 53.5 KB) -> XPC CRASH
- full kernel minus h_prev snapshot (no_snapshot) -> XPC CRASH
Cross-check: m2rnn_bwd uses the SAME for-replay_offset checkpoint-replay pattern
and COMPILES on Metal (65 KB) precisely because its replay loop body is
barrier-free (first T.sync_threads is AFTER the replay loop closes). mamba3's
_mamba3_emit_recompute_row emits multiple barriers BETWEEN lane-partitioned
phases, and those barriers land inside the replay loop -> Metal backend crash.
Calibration (per-segment MSL on Metal; <~94 KB segments compile, mamba3 crashes
even at 53 KB recompute-only): sparse_mla_fp8_apply_bwd 93.8 KB ok,
attention_qkv_projection_bwd 44.4 KB ok, m2rnn_bwd 65.0 KB ok,
mamba3_mimo_bwd 130.0 KB crash -> size is necessary-not-sufficient; barriers are
the decisive factor.
THIS COMMIT (verified-correct partial, does not yet clear the crash):
Merge the duplicated forward-recompute. _mamba3_emit_recompute_row was INLINED
TWICE per reverse step (once in the replay loop for replay_time<time_idx, once
for time_idx outside the loop); the two copies are byte-identical (~26-28 KB MSL
each). Merge into ONE emission replaying [checkpoint_start, time_idx] inclusive,
snapshotting h_prev at the start of the time_idx iteration (== post-(time_idx-1)
state, exactly as before).
- MSL 130.0 KB -> 104.3 KB (-25.7 KB); for-loops 113 -> 93; exp 27 -> 19.
- Gradient parity (tiny local_gb10_quarter smoke direct chain, random inputs,
forward+backward executed on Metal): max-abs-diff vs pre-merge = 0.000e+00
(BITWISE IDENTICAL) across all 15 non-zero mamba3 grad buffers + hidden grad.
- Identical on all targets; CUDA unaffected. 119/119 fusion IR tests pass.
FOLLOW-UP (durable fix): make the replay-loop recompute barrier-free (each lane
replays its own h_next/angle_cumsum slice independently, m2rnn-style), keeping
the single barrier'd current-step recompute OUTSIDE the replay loop. That removes
all barriers from the data-dependent loop and is the change that actually clears
newComputePipelineState. Repro: scripts/_bwdgate_per_segment_probe.py --only-index 9;
size attribution: scripts/_mamba3_msl_characterize.py; parity:
scripts/_mamba3_bwd_parity.py.1 parent 54332ac commit 8936ce4
4 files changed
Lines changed: 327 additions & 12 deletions
File tree
- cppmega_mlx/runtime
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11192 | 11192 | | |
11193 | 11193 | | |
11194 | 11194 | | |
| 11195 | + | |
| 11196 | + | |
| 11197 | + | |
| 11198 | + | |
| 11199 | + | |
| 11200 | + | |
| 11201 | + | |
| 11202 | + | |
| 11203 | + | |
| 11204 | + | |
| 11205 | + | |
| 11206 | + | |
| 11207 | + | |
| 11208 | + | |
| 11209 | + | |
| 11210 | + | |
| 11211 | + | |
| 11212 | + | |
| 11213 | + | |
| 11214 | + | |
| 11215 | + | |
| 11216 | + | |
| 11217 | + | |
| 11218 | + | |
| 11219 | + | |
| 11220 | + | |
| 11221 | + | |
11195 | 11222 | | |
11196 | 11223 | | |
11197 | 11224 | | |
11198 | 11225 | | |
11199 | | - | |
11200 | | - | |
11201 | | - | |
11202 | | - | |
11203 | | - | |
11204 | | - | |
11205 | | - | |
| 11226 | + | |
| 11227 | + | |
11206 | 11228 | | |
11207 | | - | |
| 11229 | + | |
11208 | 11230 | | |
11209 | 11231 | | |
11210 | | - | |
11211 | | - | |
| 11232 | + | |
| 11233 | + | |
11212 | 11234 | | |
11213 | | - | |
11214 | | - | |
| 11235 | + | |
| 11236 | + | |
11215 | 11237 | | |
11216 | 11238 | | |
11217 | 11239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
0 commit comments