Commit 77c154c
committed
fix(path-c): reflect CUDA bridge buffer writes back to owner (fused forward was silently dropped)
run_path_c_direct_fusion_chain_route runs segment artifacts against a route-local buffers
dict. On Metal the kernel mutates caller-owned arrays in-place (zero-copy); on CUDA the
MLX<->torch bridge writes results as NEW mlx arrays into the route-local dict only, and the
route never reflected them back to logical_owner.buffers. So value_and_grad re-read the owner
(still seeded zeros) after the forward route -> fused forward outputs silently dropped ->
degenerate loss -> near-zero cotangents -> near-zero fused grads. This made fused-CUDA
training silently produce GARBAGE gradients.
Fix: after the segment loop, reflect the route-local buffers back into logical_owner.buffers /
logical_buffers. CUDA-gated (_path_c_default_target()=="cuda") so Metal is byte-for-byte
unchanged; env CPPMEGA_PATH_C_DISABLE_CUDA_WRITEBACK=1 disables it for verification calibration.
Found + verified by a standalone b0 ABI verifier (drives the real fused mamba3 backward via the
production banked-ABI runtime at seq=8): with the fix the fused forward delta matches eager to
~2% and loss to 0.002 (was: total changed 0/71, output exactly 0.0). Metal direct-chain route
tests 7 passed.1 parent 8798113 commit 77c154c
1 file changed
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6419 | 6419 | | |
6420 | 6420 | | |
6421 | 6421 | | |
| 6422 | + | |
| 6423 | + | |
| 6424 | + | |
| 6425 | + | |
| 6426 | + | |
| 6427 | + | |
| 6428 | + | |
| 6429 | + | |
| 6430 | + | |
| 6431 | + | |
| 6432 | + | |
| 6433 | + | |
| 6434 | + | |
| 6435 | + | |
| 6436 | + | |
| 6437 | + | |
| 6438 | + | |
| 6439 | + | |
| 6440 | + | |
| 6441 | + | |
| 6442 | + | |
| 6443 | + | |
| 6444 | + | |
| 6445 | + | |
6422 | 6446 | | |
6423 | 6447 | | |
6424 | 6448 | | |
| |||
0 commit comments