Commit d8607e9
Codex
Path C blocker 1: fix sparse_mla_fp8_apply softmax score-max indent
The descriptor emitter for the row-phased sparse-MLA FP8 apply body
placed the per-key score-max update and score-weight accumulation
one indent level too deep, which Python parses as the body of the
else-branch of the preceding 'if sparse_index >= 0 ... < seq:' guard.
At runtime this left score_max at -inf for every valid sparse key,
which collapsed the softmax (sumexp -> +inf, context_accum -> 0)
and produced attention_out identically zero end-to-end. The brick
backward then propagated those zeros into every parameter grad slot
fed by the apply (q/kv proj weight+bias, out proj weight+bias, etc.)
and the suffix-loss cotangent bridge sat on top of all-zero
activations.
The fix realigns four code-emit sites in
_append_row_phased_sparse_mla_fp8_apply_body so the score-max
update, the score-weight exponential, the score-weight cache, and
the lse-only sumexp accumulation are siblings of the per-key
if/else (i.e. live in the enclosing 'for k_top:' loop body). End-to-end
launch on the local_gb10_quarter tiny smoke config now produces
attention_out with 8192/8192 non-zero, all-finite entries (sum|.|
~= 4.6e7) instead of all zeros.
Adds tests/test_path_c_sparse_mla_apply_emit_indent.py with three
structural assertions that regression-lock the indent invariants
against the rendered tiny train-block PrimFunc:
- score-max update lives at the same indent as the matching
'if sparse_index >= 0 ...' guard
- score-weight T.exp(...) accumulator lives at that indent
- lse-only sumexp += T.exp(score_accum - score_max) lives at that
indent
Verification:
- ruff clean on the changed file and the new test.
- pyright clean on the changed file and the new test.
- pytest tests/test_path_c_sparse_mla_apply_emit_indent.py -> 3 passed
- pytest tests/test_path_c_fusion_ir.py tests/test_path_c_fusion_templates.py -> 111 passed
- pytest tests/test_path_c_physical_abi.py
tests/test_path_c_fused_plus_eager_runtime.py
tests/test_path_c_fused_suffix_custom_function.py
tests/test_hybrid_lm_path_c_physical_abi_bank_owner.py
tests/test_compiled_train.py -> 91 passed1 parent bd7534d commit d8607e9
2 files changed
Lines changed: 160 additions & 8 deletions
File tree
- cppmega_mlx/runtime
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5099 | 5099 | | |
5100 | 5100 | | |
5101 | 5101 | | |
5102 | | - | |
5103 | | - | |
| 5102 | + | |
| 5103 | + | |
5104 | 5104 | | |
5105 | 5105 | | |
5106 | 5106 | | |
| |||
5113 | 5113 | | |
5114 | 5114 | | |
5115 | 5115 | | |
5116 | | - | |
| 5116 | + | |
5117 | 5117 | | |
5118 | 5118 | | |
5119 | 5119 | | |
5120 | | - | |
| 5120 | + | |
5121 | 5121 | | |
5122 | | - | |
| 5122 | + | |
5123 | 5123 | | |
5124 | 5124 | | |
5125 | 5125 | | |
| |||
5239 | 5239 | | |
5240 | 5240 | | |
5241 | 5241 | | |
5242 | | - | |
5243 | | - | |
| 5242 | + | |
| 5243 | + | |
5244 | 5244 | | |
5245 | 5245 | | |
5246 | 5246 | | |
| |||
5252 | 5252 | | |
5253 | 5253 | | |
5254 | 5254 | | |
5255 | | - | |
| 5255 | + | |
5256 | 5256 | | |
5257 | 5257 | | |
5258 | 5258 | | |
| |||
| 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 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
0 commit comments