Repository navigation
fix(gemma4): make batched MTP verify decode-exact on row-wise geometries - #2203
Merged
Merged
Conversation
inureyes
added a commit
that referenced
this pull request
Oct 7, 2026
18 tasks
inureyes
force-pushed
the
fix/issue-2190-gemma4-batched-mtp-verify
branch
from
October 7, 2026 07:33
4b2192c to
d523512
Compare
inureyes
added a commit
that referenced
this pull request
Oct 7, 2026
The batched Gemma 4 MTP adapter never set `mtp_verify`, so its verify skipped the #2185 row-wise path and B=1 batched runs drifted from the B=1 linear adapter and classic decode on the 31B and the CUDA 12B. The batched adapter now marks verify forwards (prefill stays unmarked). On the row-wise geometries every row is prefilled on its own cache over the classic chunk partition and the caches are stacked with history first and a zero tail, so a short row is a row whose valid end lags the shared offset. A B>1 verify runs each row as its own [1, K] call through the B=1 helpers (Q/K/V, RoPE, attention, o_proj, MLP, LM head) and keeps only the cache write batched, cutting each row's stale gap out of its keys and using the ring cursor for the row's own length. A lagging row that lost sliding keys to shared-offset compaction is reported as an error instead of producing inexact tokens. Refs #2190
Every shipped binary raises MLX's CUDA graph and cuDNN SDPA cache capacities at startup (#818, #1799), but the in-process model tests ran MLX's bare defaults. The new batched-vs-classic test crossed the graph cache's lifetime-miss abort (800 misses at the default 400) partway through its 12B half; at the server's 2000 it passes. A shared helper now applies the same defaults before each in-process test initializes MLX. The batched-vs-classic test also counts only rounds in which every row was still generating when it checks for a divergent accept round. Refs #2190
Batched MTP on the 31B beat classic batched decode on GB10 by 75% at B=2 and 53% at B=4 (null arm within 3%, identical bytes in every arm), so the unconditional row-wise decline in run_mtp_burst_batched becomes a gate. A row-wise window now runs only on CUDA, at B <= 4, with dense FP16 caches, prompts within the sliding window, and max_prompt_len + K * (max_tokens + 1) within the window plus the rollback buffer; anything else declines to classic before drafter IO. The last bound keeps the shared sliding ring from compacting under a lagging row, where the verify would refuse the round mid-burst; a finished row still advances up to K positions a round, hence K * max_tokens. Batched windows now carry each row's classic history-boundary split into the per-row prefill, so prompt-cache serving builds the same prompt KV classic does. The path stays behind MLXCEL_ENABLE_MTP_BATCH. Refs #2190
…ment Adds the GB10 record for issue #2190 with its harness and raw data: exactness evidence for the batched adapter, three interleaved rounds per width with a classic null arm (31B B=2 +75 to 77%, B=4 +53 to 55%, null -2.3 to +3.1%, identical bytes in every arm), a graph-cache budget check, a shipped-binary round, and the decision per pair and width. It also records why a batched window does not form in default serving (classic batched prefill, --ignore-eos token bias, unseeded requests) and that the 12B serves single-slot. CONTINUOUS_BATCHING.md and the MLXCEL_ENABLE_MTP_BATCH row describe when the row-wise geometries now serve a batched window. Refs #2190
The batched-window gate admitted any backend where MLX reports its GPU backend available, which a ROCm build can also satisfy. The admission was measured on CUDA only, so ROCm builds now decline row-wise windows like Metal does. Refs #2190
inureyes
force-pushed
the
fix/issue-2190-gemma4-batched-mtp-verify
branch
from
October 7, 2026 09:43
d523512 to
21f0067
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The batched Gemma 4 MTP adapter never set
mtp_verify, so on the row-wise geometries (31B everywhere, 12B on CUDA) it missed the #2185 decode-exact path:b1_batched_baseline_probefailed on main (31B rows 1, 2, 3 at tokens 1, 9, 17). Batched MTP is now byte-identical to per-sequence classic decode at B=1, 2 and 4, and on CUDA the 31B serves those windows because they measured 53 to 77% faster than classic batched decode.What changed
[1, K]call (Q/K/V, row-wise RoPE at the row's offset,attend_verify_rowson keys physically cut to the row's history plus block, per-row ring cursor,o_proj, MLP, LM head). Only the cache write stays batched, so finalize, rollback and drafter slabs are unchanged. A lagging row that lost sliding keys to shared-offset compaction makes the verify refuse the round.run_mtp_burst_batchedreplaces the unconditional row-wise decline withRowWiseBatchedWindow: CUDA only (Metal and ROCm builds keep declining), B <= 4, dense FP16 caches, prompts within the sliding window, andmax_prompt_len + K * (max_tokens + 1) <= window + 32, so compaction cannot happen mid-burst. Windows carry per-row history boundaries. Still behindMLXCEL_ENABLE_MTP_BATCH.Test plan (GB10, CUDA, release)
speculative_parity --ignored --test-threads=1(full, no env): 9 passed, 0 failed:b1_batched_baseline_probe(now 31B and 12B, all rows identical),divergent_hidden_probe_31b,gemma4_batched::greedy_parity_mtp_gemma4_batched_matches_classic(new: B=2/B=4, equal and ragged, both pairs, 24/24 rows identical to classic, divergent rounds in every case),greedy_parity_dflash_qwen35_4b,greedy_parity_mtp_gemma4_31b,greedy_parity_mtp_gemma4_batched_b4_matches_b1,greedy_parity_mtp_gemma4_batched_b4_ragged_matches_b1,greedy_parity_mtp_gemma4_unified_12b,mtp_gemma4_ragged_throughput_probe. Main: 7 of 8, probe failing.gemma4 speculative_burst: 327 passed. New hermetic tests for verify marking (AC-2), per-row verify vs B=1 linear verify (fails under a shared-cursor mutation and with row mode disabled), cache stacking, the window gate.-D warnings(lib, tests),cargo fmt --check.d54b209b(refactor: one post-sample finish step for every CLI and server decode site #2201, refactor: one prefill plan and one trim hook for the CLI and the server #2205) the lib selectors (327 passed), the full suite (9 passed, 0 failed) and one served B=2 window (batched, bytes identical to classic) were rerun on the pushed head.docs/benchmark_results/gemma4-mtp-batched-gb10-2026-10-07.md, which also records why default serving never forms a window (classic batched prefill,--ignore-eos, unseeded requests) and that the 12B serves single-slot.Not verified on this host
Metal. Metal 31B is row-wise too; changes reaching it are listed on #2158 (verify marking, per-row prefill and stacking, per-row verify and LM head at B>1,
finish_layerextraction). The window gate keeps Metal declined.Closes #2190