Commit ac412fb
committed
feat(path-c): intra-segment TIME-CHUNKING for mamba3 mimo backward (Metal watchdog fix)
The mamba3 mimo BACKWARD direct-chain segment is a reverse-time recurrent scan
over the whole sequence (S serial time steps) inside ONE threadgroup. Under the
default grid_chunks dispatch the entire scan is encoded into ONE Metal command
buffer; once its GPU time exceeds the macOS watchdog window it is killed with
kIOGPUCommandBufferCallbackErrorTimeout (verified: monolithic seg dies at 6.35s
for S=16384; time-chunked completes clean).
Two-edit fix (Python only, no tilelang C++ rebuild):
1. plan_path_c_direct_fusion_chain_for_region: switch ONLY the mamba3_mimo_bwd
backward segment's schedule_target to row_dispatch_mode=launcher_chunks
(max_rows_per_launch=64). Its compiled kernel then declares
path_c_row_chunk_index / path_c_row_subchunk_index and emits the per-row
reverse scan body (for time_rev in serial(row, row+1)). Every other segment
(all forward + non-mamba3 backward) keeps grid_chunks unchanged.
_kernel_parameter_count_for_target now counts only params that bind a device
buffer (present in buffer_map), not scalar params. The portable limit (31) is
Metal's buffer-argument cap; the launcher index scalars are passed by value
and consume no buffer slot. Without this the launcher-chunked mamba3 backward
was spuriously blocked at 34 'buffers' when it binds only 30.
2. run_path_c_direct_fusion_chain_route: for a launcher-chunked segment on Metal,
loop over (chunk_index, subchunk_index) in [0,S) (mirroring the eager replay
driver order), write the two index scalars into a per-launch copy of the args
at their recorded segment-dependent positions, call the artifact per launch,
and commit each launch as its own command buffer (eval+synchronize). The
reverse adjoint scan state (dh<->h0_grad, angle_grad<->mamba3_angle_grad_state)
carries across launches via caller-owned buffers (relaxed atomic_add already
accumulates correctly); path_c_first_row_launch zeroes owner grads exactly
once on the first launch. CUDA branch unchanged; non-launcher-chunked segments
keep the single-call path. No fallback: missing index scalar slots or a commit
failure RAISE.
Verification (Metal, S=512 bench shape and beyond):
- native executor test runs all 7 segments incl. the time-chunked seg#5: PASS.
- gradient parity time-chunked vs monolithic: worst mamba3 grad diff 5.59e-5,
within the inherent fp8/bf16 atomic run-to-run noise floor (4.71e-5); no NaN.
- watchdog: monolithic mamba3 backward raises kIOGPUCommandBufferCallbackError
Timeout at 6.35s (S=16384); time-chunked (2048 launches, 3.84ms each)
completes in 7.86s with NO timeout.
No new test regressions (the 5 pre-existing failures in test_m04_train_step.py /
test_path_c_fusion_ir.py fail identically on the pristine baseline).1 parent c9b5aac commit ac412fb
3 files changed
Lines changed: 220 additions & 1 deletion
File tree
- cppmega_mlx/runtime
- scripts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14232 | 14232 | | |
14233 | 14233 | | |
14234 | 14234 | | |
| 14235 | + | |
| 14236 | + | |
| 14237 | + | |
| 14238 | + | |
| 14239 | + | |
| 14240 | + | |
| 14241 | + | |
| 14242 | + | |
| 14243 | + | |
| 14244 | + | |
| 14245 | + | |
| 14246 | + | |
| 14247 | + | |
| 14248 | + | |
| 14249 | + | |
| 14250 | + | |
| 14251 | + | |
| 14252 | + | |
| 14253 | + | |
| 14254 | + | |
| 14255 | + | |
| 14256 | + | |
| 14257 | + | |
| 14258 | + | |
| 14259 | + | |
| 14260 | + | |
| 14261 | + | |
| 14262 | + | |
| 14263 | + | |
| 14264 | + | |
| 14265 | + | |
14235 | 14266 | | |
14236 | 14267 | | |
14237 | 14268 | | |
| |||
14483 | 14514 | | |
14484 | 14515 | | |
14485 | 14516 | | |
14486 | | - | |
| 14517 | + | |
| 14518 | + | |
| 14519 | + | |
| 14520 | + | |
| 14521 | + | |
| 14522 | + | |
| 14523 | + | |
| 14524 | + | |
| 14525 | + | |
| 14526 | + | |
| 14527 | + | |
| 14528 | + | |
| 14529 | + | |
14487 | 14530 | | |
14488 | 14531 | | |
14489 | 14532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6497 | 6497 | | |
6498 | 6498 | | |
6499 | 6499 | | |
| 6500 | + | |
| 6501 | + | |
| 6502 | + | |
| 6503 | + | |
| 6504 | + | |
| 6505 | + | |
| 6506 | + | |
| 6507 | + | |
| 6508 | + | |
| 6509 | + | |
| 6510 | + | |
| 6511 | + | |
| 6512 | + | |
| 6513 | + | |
| 6514 | + | |
| 6515 | + | |
| 6516 | + | |
| 6517 | + | |
| 6518 | + | |
| 6519 | + | |
| 6520 | + | |
| 6521 | + | |
| 6522 | + | |
| 6523 | + | |
| 6524 | + | |
| 6525 | + | |
| 6526 | + | |
| 6527 | + | |
| 6528 | + | |
| 6529 | + | |
| 6530 | + | |
| 6531 | + | |
| 6532 | + | |
| 6533 | + | |
| 6534 | + | |
| 6535 | + | |
| 6536 | + | |
| 6537 | + | |
| 6538 | + | |
| 6539 | + | |
| 6540 | + | |
| 6541 | + | |
| 6542 | + | |
| 6543 | + | |
| 6544 | + | |
| 6545 | + | |
| 6546 | + | |
| 6547 | + | |
| 6548 | + | |
| 6549 | + | |
| 6550 | + | |
| 6551 | + | |
| 6552 | + | |
| 6553 | + | |
| 6554 | + | |
| 6555 | + | |
| 6556 | + | |
| 6557 | + | |
| 6558 | + | |
6500 | 6559 | | |
6501 | 6560 | | |
6502 | 6561 | | |
| |||
6626 | 6685 | | |
6627 | 6686 | | |
6628 | 6687 | | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
| 6692 | + | |
6629 | 6693 | | |
6630 | 6694 | | |
6631 | 6695 | | |
| |||
6642 | 6706 | | |
6643 | 6707 | | |
6644 | 6708 | | |
| 6709 | + | |
6645 | 6710 | | |
6646 | 6711 | | |
6647 | 6712 | | |
| |||
6669 | 6734 | | |
6670 | 6735 | | |
6671 | 6736 | | |
| 6737 | + | |
| 6738 | + | |
| 6739 | + | |
| 6740 | + | |
| 6741 | + | |
| 6742 | + | |
| 6743 | + | |
| 6744 | + | |
| 6745 | + | |
| 6746 | + | |
| 6747 | + | |
| 6748 | + | |
| 6749 | + | |
| 6750 | + | |
| 6751 | + | |
| 6752 | + | |
| 6753 | + | |
| 6754 | + | |
| 6755 | + | |
| 6756 | + | |
| 6757 | + | |
| 6758 | + | |
| 6759 | + | |
| 6760 | + | |
| 6761 | + | |
| 6762 | + | |
| 6763 | + | |
| 6764 | + | |
| 6765 | + | |
| 6766 | + | |
| 6767 | + | |
| 6768 | + | |
| 6769 | + | |
| 6770 | + | |
| 6771 | + | |
| 6772 | + | |
| 6773 | + | |
| 6774 | + | |
| 6775 | + | |
| 6776 | + | |
| 6777 | + | |
| 6778 | + | |
| 6779 | + | |
| 6780 | + | |
| 6781 | + | |
| 6782 | + | |
| 6783 | + | |
| 6784 | + | |
| 6785 | + | |
| 6786 | + | |
| 6787 | + | |
| 6788 | + | |
| 6789 | + | |
| 6790 | + | |
| 6791 | + | |
| 6792 | + | |
| 6793 | + | |
| 6794 | + | |
| 6795 | + | |
| 6796 | + | |
| 6797 | + | |
| 6798 | + | |
| 6799 | + | |
| 6800 | + | |
| 6801 | + | |
| 6802 | + | |
| 6803 | + | |
| 6804 | + | |
| 6805 | + | |
| 6806 | + | |
| 6807 | + | |
| 6808 | + | |
| 6809 | + | |
| 6810 | + | |
| 6811 | + | |
| 6812 | + | |
| 6813 | + | |
| 6814 | + | |
| 6815 | + | |
| 6816 | + | |
| 6817 | + | |
| 6818 | + | |
| 6819 | + | |
| 6820 | + | |
| 6821 | + | |
| 6822 | + | |
| 6823 | + | |
| 6824 | + | |
| 6825 | + | |
6672 | 6826 | | |
6673 | 6827 | | |
6674 | 6828 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3624 | 3624 | | |
3625 | 3625 | | |
3626 | 3626 | | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | + | |
3627 | 3645 | | |
3628 | 3646 | | |
3629 | 3647 | | |
3630 | 3648 | | |
| 3649 | + | |
| 3650 | + | |
| 3651 | + | |
| 3652 | + | |
3631 | 3653 | | |
3632 | 3654 | | |
3633 | 3655 | | |
| |||
0 commit comments