Repository navigation
fix: trace and fix the last two speculative verify mismatches - #3420
Merged
Merged
Conversation
The exactness survey (#3415) left two places where a K-row verify block is not the K decode steps it stands for. Gemma 4 26B A4B declined the MTP probe on both quantized kernels. The narrow divergence starts at the layer 0 expert output, because `Experts::forward` picks its kernel by token count. A verify block now runs the routed experts per position, and the 26B A4B geometry joins the row-wise verify attention set on Metal. The probe is equal on the narrow kernel at widths 2, 4 and 8, up to 2100 prompt tokens. Classic decode is unchanged (132.65 against 132.90 tok/s). The token-only verify round (prompt lookup, a full-model drafter) differs on the DeepSeek V3 family because one query takes the fused absorbed MLA kernel and a block takes SDPA. `MLXCEL_MLA_ROW_INVARIANT=1` runs each block row as that single query on `DeepSeekV3Model` and Xing4.0, and routes the GLM-4.7-Flash engine block to its row-wise verify forward. It is off by default: byte identity costs prompt lookup 24% to 43% of its throughput, and quantized checkpoints also need `MLXCEL_QMV_WIDE=0`. No gate was added. Arcee, K2 Horizon and OLMoE are located and kept as documented. Validated with narrow lib suites under the GPU lock, both narrow clippy commands and the contract checks. Measurements: docs/benchmark_results/speculative-exactness-followup-m3ultra-2026-11-25.md. Closes #3418
6 of 7 tasks
Review of the #3418 change found two gaps. `linear_whole_block` took the dense route outside a scope, which skips a named LoRA adapter; it is now the layer's own forward there, so a model that enters the scope only on request is untouched. And Xing4.0 still parted from the chain in one optiq cell (width 8, 2100 tokens, layer 38), because its hyper connection mixes through a dense `matmul` and a batched matmul over the positions. The mixer now takes `row_invariant::dense` and `hc_expand` multiplies each position alone inside a verify block; both Xing4.0 checkpoints are equal in 9 of 9 cells with `MLXCEL_MLA_ROW_INVARIANT=1` and `MLXCEL_QMV_WIDE=0`. The tiny DeepSeek V3 test now also runs a rope width the fused MLA kernel takes, and counts the MLA paths so every block row is shown to take the single-query path. Refs #3418
inureyes
marked this pull request as ready for review
November 25, 2026 02:13
This was referenced Nov 25, 2026
inureyes
added a commit
that referenced
this pull request
Nov 25, 2026
…ilies (#3424) ## Summary Extends the opt-in exact token-only verify scope (`MLXCEL_MLA_ROW_INVARIANT=1`, #3420) to the families #3418 left open. With the variable unset no forward enters a row-invariant scope, so the default path is unchanged (decode ABAB below). - DeepSeek V3.2: every verify-block row runs the decode step's single DSA query over its prefix of the stored `[latent | indexer key]` window with its own indexer top-k; projections (indexer included), gate and LM head row-invariant; float experts per position. - DeepSeek V2 (in): a verify block appends and attends one row at a time on both the latent and the decompressed layout. - `Llama3Model` (K2 Horizon) and Arcee: the fused QKV split goes through `row_invariant::linear_whole_block` (the layer's own forward outside a scope); inside one the fused rope and compiled MLP launchers give way to the composed graph, and a block attends one row at a time. - OLMoE: a verify block runs routing and experts per position (the fused single-token MoE kernel) and attends per row. - MLA path stats count a per-row verify block once per layer (`mla::stats::as_one_call`). Open points: Kimi Linear, Kimi K3 and LongCat are out. The token-only round refuses them (model-owned KDA or n-gram state without a verify rewind), so no block forms and the KDA layers never see one; the survey reports "not run" on every cell and a test per family pins the refusal. DeepSeek V2 is in: it takes the round and carries the same split. ## Measurements (M3 Ultra) Survey, engine path, widths 2/4/8 at 8/600/2100 tokens: off, every cell differs on both kernels (first difference layer 0 output). On: afm-4.5b and k2-horizon-0.9b equal on bf16 (9/9); deepseek-v2-lite and olmoe equal with `MLXCEL_QMV_WIDE=0` (9/9). Decode ABAB against main, variable unset, same tokens: K2 Horizon 211.50 vs 211.80, OLMoE 410.21 (421.24 without a cold first run) vs 421.21, V2-Lite 173.28 vs 174.58 tok/s. Details in `docs/benchmark_results/speculative-exactness-followup-m3ultra-2026-11-25.md` section 3. Not done: `deepseek-v3.2-4bit` not loaded (tiny-model test only); the diagnostic names the first layer, not the op inside it; prompt-lookup throughput with the variable on was not measured for these families. ## Test plan - [x] Tiny-model block-versus-chain tests for V3.2, V2, Llama 3, Arcee, OLMoE (float and 4-bit), widths 2/4/8/12; each fails without the scope - [x] Extended path-count test in `deepseek_v3_verify_block_tests.rs` plus V3.2 and V2 equivalents - [x] Narrow selectors: `models::llama3 models::arcee models::olmoe models::deepseek_v2 models::deepseek_v32 models::deepseek_v3 models::kimi_linear models::longcat coverage_tests`, core `mla::stats row_invariant qkv` - [x] Contract checks, clippy (lib/tests/bins and mlxcel-core), fmt; broad gate left to the orchestrator Closes #3421
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
Traces the two block-versus-chain mismatches the exactness survey (#3415) left open, fixes Gemma 4 26B A4B, and adds an opt-in exact verify block for the token-only round on the MLA families.
What changed
MoE experts(shared MLP and router agree):Experts::forwardpicks its kernel by token count. A verify block now runs the experts per position (MLXCEL_GEMMA4_MOE_VERIFY_PER_POSITION, on). The next divergence was the batched block's attention, so the 16/8/2 geometry joins row-wise verify on Metal. The probe is nowequalon the narrow kernel at widths 2, 4, 8, at startup, 600 and 2100 tokens, so the gate engages as on 12B and 31B.DeepSeekV3Modelone query takes the fused absorbed MLA kernel and a block takes SDPA.MLXCEL_MLA_ROW_INVARIANT=1runs each block row as that single query, uses the row-invariant matvec kernel for dense products and per-position float experts, covers Xing4.0 (including its hyper connection's two products), and routes the GLM-4.7-Flash engine block to its row-wise verify forward. Result:equalon gigachat3 bf16;equalwithMLXCEL_QMV_WIDE=0on gigachat3 8-bit, Kimi-VL, moonlight, Xing4.0 8-bit and optiq, and GLM. Prompt-lookup text then matched plain decode on 6 of 6 pairs (4 of 6 without).Not met
equalholds only with the opt-in (plusMLXCEL_QMV_WIDE=0on quantized checkpoints).Test plan
gemma4::moe_verify_tests,deepseek_v3::verify_block_tests, a GLM routing test. Each has a companion asserting the pre-change path differs.coverage_tests.survey_block_vs_chainon the checkpoints above; ABAB decode (8 pairs) and prompt lookup (4 cycles) indocs/benchmark_results/speculative-exactness-followup-m3ultra-2026-11-25.md.cargo clippy --lib --tests --binsand-p mlxcel-core --lib --testswith-D warnings(narrow stand-ins for the issue's--all-targets),cargo fmt --check, contract scripts.Closes #3418