Commit 7945625
committed
feat(mamba3-pathc): Stage 3 — LIVE region-build backward 1->3 surface flip (B2/B1/B0)
Mirrors the forward Stage-2 region flip for the backward (design §2/§3.1/§7):
- _emit_mamba3_chunked_bwd_model_brick_surfaces emits the 3 _bwd surfaces
(B2->B1->B0, the transpose of F2->F1->F0) when the flag is ON, wired by the
per-brick grad-handoff buffers (dchunk_states B2->B1, dstates B1->B0,
dinp_diag/dA_cumsum_y B2->B0, dA_cumsum_tail B1->B0). REUSES the forward-
materialized cb/dA_cumsum/prev_states (no 8x checkpoint-replay). Invoked from
the flag-ON _emit_mamba3_chunked_model_brick_surfaces (the forward owner_output
surfaces carry no AOT autograd, so the backward is emitted explicitly).
- 6 backward grad-handoff buffers registered: _buffer_shape (fp32 region shapes),
_buffer_dtype (fp32 recurrent-grad precision), and the force-spill set
DESCRIPTOR_MAMBA3_CHUNKED_BWD_HANDOFF_ABI_BUFFERS.
- FIX: _path_c_schedule_node_execution_phase classified ANY op in the (now-shared)
delegation set as forward; excluded *_bwd so the 3 backward ops classify as
BACKWARD phase. The per-node backward stage planner already isolates each into
its own single-node stage (interpose requires len(nodes)==1).
Verified (tests/test_mamba3_chunked_backward_b0b1b2.py, 11 tests):
- flag OFF: no chunked _bwd surfaces, serial mamba3_mimo unchanged (merge-safe).
- flag ON: 3 _bwd surfaces, all backward-phase, each own backward stage, correct
B2->B1->B0 grad-handoff + prev_states reuse, fp32 force-spilled handoff buffers.
- region-build flip inspection: 7 nodes (entry_rmsnorm + 3 fwd + 3 bwd), stages
g0..g3 forward / b0..b2 backward single-node each.
Flag-OFF unchanged: 151 forward + path_c template/IR tests green (1 Stage-2 test
updated to count forward-only chunked nodes). Flag default OFF (merge-safe).1 parent 7cc15a4 commit 7945625
4 files changed
Lines changed: 265 additions & 8 deletions
File tree
- cppmega_mlx/runtime
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1936 | 1936 | | |
1937 | 1937 | | |
1938 | 1938 | | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
1939 | 1958 | | |
1940 | 1959 | | |
1941 | 1960 | | |
| |||
2042 | 2061 | | |
2043 | 2062 | | |
2044 | 2063 | | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
2045 | 2070 | | |
2046 | 2071 | | |
2047 | 2072 | | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
2048 | 2170 | | |
2049 | 2171 | | |
2050 | 2172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
268 | 282 | | |
269 | 283 | | |
270 | 284 | | |
| |||
725 | 739 | | |
726 | 740 | | |
727 | 741 | | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
735 | 754 | | |
736 | 755 | | |
737 | 756 | | |
| |||
4663 | 4682 | | |
4664 | 4683 | | |
4665 | 4684 | | |
| 4685 | + | |
| 4686 | + | |
4666 | 4687 | | |
4667 | 4688 | | |
4668 | 4689 | | |
| |||
14375 | 14396 | | |
14376 | 14397 | | |
14377 | 14398 | | |
| 14399 | + | |
| 14400 | + | |
| 14401 | + | |
| 14402 | + | |
| 14403 | + | |
| 14404 | + | |
| 14405 | + | |
| 14406 | + | |
14378 | 14407 | | |
14379 | 14408 | | |
14380 | 14409 | | |
| |||
14502 | 14531 | | |
14503 | 14532 | | |
14504 | 14533 | | |
| 14534 | + | |
| 14535 | + | |
| 14536 | + | |
| 14537 | + | |
| 14538 | + | |
| 14539 | + | |
| 14540 | + | |
14505 | 14541 | | |
14506 | 14542 | | |
14507 | 14543 | | |
| |||
14594 | 14630 | | |
14595 | 14631 | | |
14596 | 14632 | | |
| 14633 | + | |
| 14634 | + | |
| 14635 | + | |
| 14636 | + | |
| 14637 | + | |
| 14638 | + | |
| 14639 | + | |
14597 | 14640 | | |
14598 | 14641 | | |
14599 | 14642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
| 602 | + | |
| 603 | + | |
602 | 604 | | |
603 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
604 | 609 | | |
605 | 610 | | |
606 | 611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 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 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
173 | 260 | | |
174 | 261 | | |
175 | 262 | | |
| |||
0 commit comments