Repository navigation
fix(tests): make the mamba2 batched decode check deterministic - #2815
Merged
Merged
Conversation
The mamba2 fresh/mixed test failed every standalone run at its 1e-5 assertion. Giving the assertion a message showed the delta was NaN, not a tolerance miss, and only at the native -> B=1 transition with a mixed state (`mixed=true step=1 row=0`). The hand-rolled body never evaluated a forward, so the transition read its own pending recurrent-cache write. The test now calls `batched_decode_harness::assert_model_owned_fresh_mixed_and_transition`, which runs the same scenario through the shared harness and evaluates every forward before the next reference is built, instead of keeping a sixth copy. `assert_rows_absolute` now takes a context string and reports it with the row and the max absolute difference, so a failure names the iteration and how far it missed; before, the message carried neither. The four sibling copies (`falcon_h1`, `granitemoehybrid`, `nemotron_h`, `plamo2`) have no transition step and pass standalone, so they are unchanged. Verification: fmt; clippy -D warnings on mlxcel (cuda); the mamba2 test standalone three times; the full models:: suite twice (2531 passed); models::mamba. Revert experiment: restoring the old hand-rolled body reproduces `mixed=true step=1 row=0 delta=NaN` in the same process where the consolidated test passes.
inureyes
added a commit
that referenced
this pull request
Nov 1, 2026
…ce (#2816) The #2587 acceptance run found reproducible batched decode losses on M1 Ultra (pythia-1b fell from 230 to 165 tok/s at B=2, below its B=1). There were two causes. - **Dense products with 2 or more rows.** GPU generations 13 and 14 are excluded from `gemv_wide` and fall to the steel GEMM tile, which costs several times a one-row GEMV. A new matmul overlay runs up to 6 rows through the existing GEMV kernel as a batch, in one dispatch. `MLXCEL_DENSE_GEMV_ROWS=0` restores upstream dispatch. - **The gate/up kernel at B >= 2.** `SwitchGLU::forward` tried #2514's kernel ahead of `gather_qmm`. #2514 measured M3 Ultra only; on M1 Ultra it loses about 10%. `forward` now uses it at one token, or on M3 and later. `forward_activated` (Inkling) is unchanged. ## Results Aggregate tok/s, `--parallel 4`, 512-token prompt, 128 tokens. | checkpoint | before epic B=2 / B=4 | db41244 B=2 / B=4 | this PR B=2 / B=4 | |---|---|---|---| | pythia-1b | 229 / 243 | 165 / 263 | 285 / 340 | | ling-lite-1.5 | 102 / 85 | 70 / 105 | 112 / 141 | | paddleocr-vl-bfloat16 | 229 / 237 | 199 / 274 | 320 / 319 | | moondream2 | 82 / 87 | 66 / 82 | 91 / 96 | | qwen3-30b-a3b-4bit | 89 / 114 | 94 / 115 | 104 / 124 | | qwen3-omni-30b-a3b-instruct-4bit | 107 / 119 | 92 / 112 | 102 / 121 | The PR column is one round; the others are medians of 2 to 4. Tables and the upstream arm are in `docs/benchmark_results/few-row-dense-matmul-m1ultra-2026-11-01.md`. ## Validation - All 49 rows of the #2587 matrix on this branch: B=4 vs B=1 trace has 0 disagreements at decided positions, and `generate` text and image output matches db41244. The ladder is a single round on this branch. - Batched GEMV rows are bitwise equal to the same rows alone (`metal_few_row_dense_matmul_matches_single_rows`, plus the probe example). - Quantized controls (Qwen3-4B, Llama 3.1 8B, Command R7B) stay within 2% with the route on or off over two more rounds per arm. - `make verify-test`: 14906 passed, 0 failed, 490 ignored. fmt and clippy clean. Not measured: base M1, M1 Pro and Max, M2, and CUDA or ROCm (neither path changes there). Tested before rebasing over #2815, a test-only change. Remaining: stablelm, phi-2 and mixtral stay 5 to 8% under the old per-row fallback at B=2, and Command R7B 5% at B=4. Neither change affects them. Refs #2587
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.
Closes #2807
The mamba2 fresh/mixed test failed every standalone run at its 1e-5 assertion. Giving the assertion a message showed the delta was
NaN, not a tolerance miss, and only at the native -> B=1 transition with a mixed state (mixed=true step=1 row=0). The hand-rolled body never evaluated a forward, so the transition read its own pending recurrent-cache write.The test now calls
batched_decode_harness::assert_model_owned_fresh_mixed_and_transition, which runs the same scenario through the shared harness and evaluates every forward before the next reference is built, instead of keeping a sixth copy.assert_rows_absolutenow takes a context string and reports it with the row and the max absolute difference, so a failure names the iteration and how far it missed instead of only the raw vector.The four sibling copies (
falcon_h1,granitemoehybrid,nemotron_h,plamo2) have no transition step and all pass standalone, so they are unchanged.Validation
-D warningson mlxcel (cuda)models::twice (2531 passed);models::mambamixed=true step=1 row=0 delta=NaNin the same process where the consolidated test passes