Commit 9f74055
committed
fix(path-c): clear Metal FORWARD watchdog gate — row-chunk independent heavy fwd ops; isolate them per watchdog-bounded segment
Clears the full-scale direct-chain FORWARD watchdog blocker (region
..._chain_4_6 / seg[2] FORWARD), the forward analog of the already-merged
backward fix (54332ac). The full-scale local_gb10_quarter (depth=13 hidden=3584
max_seq=4096) Metal direct-chain --execute previously tripped the macOS GPU
watchdog (kIOGPUCommandBufferCallbackErrorTimeout) at ~9.6s in seg[2] FORWARD,
because the heavy FORWARD ops attention_qkv_projection + sparse_mla_fp8_apply ran
as a monolithic grid_chunks command buffer over S=4096.
FIX (Metal-gated; CUDA unchanged; explicit by target/op; RULE #1: no silent
fallback):
* _ROW_CHUNKED_INDEPENDENT_FORWARD_OPS = {attention_qkv_projection,
sparse_mla_fp8_apply} -- the per-row-INDEPENDENT heavy FORWARD ops. Both
produce per-row outputs with NO carried cross-row state:
- attention_qkv_projection: per-token Q/KV projection + RoPE + FP8 prepare;
output row R reads input hidden row R + shared weights only. Its
q_fp8/q_scale/kv_fp8/kv_scale outputs are caller-owned full-sequence
KV-history workspace buffers, written across the K row-launches.
- sparse_mla_fp8_apply: per-query-row attention out + LSE; query row R reads
its own q row + the SHARED full-sequence KV-history workspace
(kv_fp8/kv_scale, top-k indices all <= R for causal), produced by the
SEPARATE earlier attention_qkv_projection segment.
* The forward fusion cap is lowered to 1 for any forward window containing a
row-chunked forward op (_effective_forward_max_segment_nodes_for_window), so
attention_qkv_projection and sparse_mla_fp8_apply each land ALONE in their own
segment. That (a) makes each its own watchdog-bounded command buffer and
(b) guarantees sparse_mla reads a FULLY-MATERIALIZED KV workspace (a fused row
window would read KV positions not yet written) -> forward parity preserved.
Mirrors the backward cap=1 isolation of the independent heavy bwd ops.
* Each isolated heavy forward segment is switched to launcher_chunks
row-windowing, so the existing runtime row-chunk loop drives it as K command
buffers over the independent ROW axis. NO carry buffers are added
(_row_phased_launcher_carry_buffers_for_nodes adds carries ONLY for
mamba3/m2rnn, never for these). The runtime
(run_path_c_direct_fusion_chain_route) needed NO change: it keys off the
compiled prim_func's row_dispatch_mode=='launcher_chunks' and is phase-agnostic.
* Gated on _path_c_default_target()=="metal" AND the forward cap being active
(forward_row_chunk_isolation): a caller passing forward_max_segment_nodes=None
disables ALL Metal forward mitigations together; CUDA resolves the cap to None,
keeping the monolithic grid_chunks forward path + greedy fusion byte-for-byte
unchanged.
NEW GROUPING (Metal, full + smoke scale): 12 segments. Forward grew 4->5:
seg0 [entry_rmsnorm,mamba3_mimo] grid
seg1 [residual_rmsnorm,m2rnn] grid
seg2 [residual_rmsnorm] grid (split off)
seg3 [attention_qkv_projection] launcher (isolated)
seg4 [sparse_mla_fp8_apply] launcher (isolated)
Backward unchanged (7 segments): seg5 sparse_mla_bwd(launcher),
seg6 attn_qkv_bwd(launcher), seg7 rmsnorm_bwd(grid), seg8 m2rnn_bwd(launcher),
seg9 rmsnorm_bwd(grid), seg10 mamba3_bwd(launcher), seg11 entry_rmsnorm_bwd(grid).
VERIFIED (real, on-device M4 Max):
* FORWARD GATE CLEARED. Full-scale repro_fullscale_directchain.py --execute now
runs ~3686s (~61 min) and gets PAST the entire FORWARD phase + backward
segments 5-9 with ZERO forward watchdog timeout (was killed at 9.6s in seg[2]
FORWARD). All 12 segments plan + native-compile (newComputePipelineState ok in
~5s). The execute now dies DEEPER, at seg[10] BACKWARD (region ..._chain_12_13,
op mamba3_mimo_bwd) on its FIRST launcher launch (chunk=0,subchunk=0) with
kIOGPUCommandBufferCallbackErrorTimeout -- this is the SAME mamba3_mimo_bwd
deeper blocker already documented on 54332ac (a SINGLE 114-MSL-loop reverse
scan launch still exceeds the watchdog even row-windowed). That is the NEXT
gate (progress, not a regression of this change): mamba3_bwd is a backward op
this forward-only change does not touch.
* FORWARD PARITY (smoke scale): the row-chunked forward activations are BITWISE
IDENTICAL to the canonical maximally-fused (greedy all-grid_chunks) forward --
6/6 forward activations (q_fp8/q_scale/kv_fp8/kv_scale + sparse_mla out/lse)
diff=0.0 at two seeds, no NaN (scripts/_fwd_rowchunk_parity.py --greedy-
reference). Confirmed launcher_chunks==grid_chunks for the SAME isolation
(diff=0.0), and that the SHIPPED cap=2 grouping's pre-existing FP8-quantization
divergence from greedy is unrelated to row-chunking (it diverges with NO
row-chunking too), so greedy is the correct parity oracle.
* NO REGRESSION. test_path_c_fusion_ir.py: 119 passed (the
forward_max_segment_nodes=None greedy tests are unchanged -- the row-chunk
isolation is bound to the same switch). test_m04_train_step.py: the direct-chain
executor test passes after updating the legitimately-changed forward grouping
(segment_count 11->12, 4->5 forward segments, time-chunked launcher indices
{4,5,7,9}->{3,4,5,6,8,10}, and the kernel_arg_count formula: forward launcher
segments bind 2 launcher index scalars, backward launcher segments bind 3).
Remaining 10 m04 failures are PRE-EXISTING on baseline (CLI/data/env/'tokens'
array), unchanged by this change (verified via stash).
Forward parity harness: scripts/_fwd_rowchunk_parity.py (greedy-reference A/B).1 parent f687b4f commit 9f74055
3 files changed
Lines changed: 454 additions & 38 deletions
File tree
- cppmega_mlx/runtime
- scripts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
197 | 245 | | |
198 | 246 | | |
199 | 247 | | |
| |||
611 | 659 | | |
612 | 660 | | |
613 | 661 | | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
614 | 703 | | |
615 | 704 | | |
616 | 705 | | |
| |||
14548 | 14637 | | |
14549 | 14638 | | |
14550 | 14639 | | |
| 14640 | + | |
| 14641 | + | |
| 14642 | + | |
| 14643 | + | |
| 14644 | + | |
| 14645 | + | |
| 14646 | + | |
| 14647 | + | |
| 14648 | + | |
| 14649 | + | |
| 14650 | + | |
| 14651 | + | |
| 14652 | + | |
| 14653 | + | |
| 14654 | + | |
14551 | 14655 | | |
14552 | 14656 | | |
14553 | 14657 | | |
| |||
14593 | 14697 | | |
14594 | 14698 | | |
14595 | 14699 | | |
| 14700 | + | |
| 14701 | + | |
| 14702 | + | |
| 14703 | + | |
| 14704 | + | |
| 14705 | + | |
| 14706 | + | |
| 14707 | + | |
| 14708 | + | |
| 14709 | + | |
| 14710 | + | |
| 14711 | + | |
| 14712 | + | |
| 14713 | + | |
| 14714 | + | |
| 14715 | + | |
| 14716 | + | |
| 14717 | + | |
| 14718 | + | |
| 14719 | + | |
14596 | 14720 | | |
14597 | 14721 | | |
14598 | | - | |
14599 | | - | |
| 14722 | + | |
| 14723 | + | |
14600 | 14724 | | |
14601 | 14725 | | |
14602 | 14726 | | |
14603 | | - | |
14604 | | - | |
| 14727 | + | |
| 14728 | + | |
| 14729 | + | |
| 14730 | + | |
| 14731 | + | |
| 14732 | + | |
| 14733 | + | |
| 14734 | + | |
14605 | 14735 | | |
14606 | 14736 | | |
14607 | 14737 | | |
| |||
14693 | 14823 | | |
14694 | 14824 | | |
14695 | 14825 | | |
| 14826 | + | |
| 14827 | + | |
| 14828 | + | |
| 14829 | + | |
| 14830 | + | |
| 14831 | + | |
| 14832 | + | |
| 14833 | + | |
| 14834 | + | |
| 14835 | + | |
| 14836 | + | |
| 14837 | + | |
| 14838 | + | |
| 14839 | + | |
| 14840 | + | |
| 14841 | + | |
| 14842 | + | |
| 14843 | + | |
| 14844 | + | |
| 14845 | + | |
| 14846 | + | |
| 14847 | + | |
| 14848 | + | |
| 14849 | + | |
| 14850 | + | |
| 14851 | + | |
| 14852 | + | |
| 14853 | + | |
| 14854 | + | |
| 14855 | + | |
| 14856 | + | |
| 14857 | + | |
| 14858 | + | |
| 14859 | + | |
| 14860 | + | |
| 14861 | + | |
| 14862 | + | |
| 14863 | + | |
14696 | 14864 | | |
14697 | 14865 | | |
14698 | 14866 | | |
| |||
0 commit comments