Repository navigation
fix(inkling2): make speculative verify blocks byte-identical to decode - #3405
Merged
Merged
Conversation
The block-versus-chain probe declined the bundled DSpark drafter of Inkling 2 Mini and Small at every width, so the drafter stayed off unless MLXCEL_MTP_ALLOW_INEXACT=1. A per-visit hidden-state comparison found three causes: MLX multiplies one row with gemv and several with gemm, which sum in different orders; the per-query sink column sat after the newest key, so its index differed between a step and a block and moved the SDPA reduction; and the looped core's message read is a batched matmul over the block length. Add mlxcel_core::row_invariant, an opt-in scope plus dense/linear/per_row/per_position helpers backed by a new Metal matvec (row_invariant_matvec) whose summation order depends on K and N only, for up to 16 rows. Inkling 2 enters the scope for every text forward and routes all dense products through it, places the sink column before the keys, and reads messages per position inside a verify block. With MLXCEL_INKLING2_KERNELS=0 or off Metal a verify block multiplies one row at a time, which stays exact. The probe now passes at widths 2, 4 and 8 on Mini and Small, drafter-on output equals classic decode, and decode is 1.4% (Mini) and 0.9% (Mini 4-bit) faster with the kernel. build.rs now watches the Inkling 2 kernel sources, which were never rebuilt after an edit. Refs #3280
Once the context exceeds a sliding layer's 1024-token window, row r of a verify block also saw the r oldest keys, masked out, which a decode step had already dropped. The extra columns shifted the SDPA reduction, so rows 1 and later differed from decode on Mini at 1100, 3000 and 8000 tokens while the probe, which uses a short prompt, still passed. Inside a verify block a sliding visit now attends row by row over the keys from that row's window start. Dense (unquantized) experts are split per token too, since gather_mm also changes kernel with the row count. The tiny model's head_dim goes from 8 to 64 so its attention takes the fused SDPA kernel real checkpoints use; with it the tiny probe test passes. The per-visit diagnostic gains INKLING2_DIAG_PROMPT and a tiny-model variant. Refs #3280
The DSpark path prefilled the whole prompt in one forward while classic decode prefills in MLXCEL_PREFILL_CHUNK (2048) token chunks, so a longer prompt left caches that differ in the last bits and the drafter-on text left classic decode within the first sentences on a 2006-token prompt. Both the text and the VL speculative targets now prefill through Inkling2Model::prefill_speculative, which runs the classic chunks, evaluates each, keeps the last chunk's logits and concatenates the captures. That prompt now gives byte-identical text with and without the drafter. The benchmark record gains the window and prefill causes, the long-prompt run, and the mlx-vlm parity re-measurement after moving the sink column (Mini 4-bit text trace: 31 / 1024 top-1 differences, 0 / 372 at decided positions, against 33 and 0 before). Refs #3280
Adds the bilingual technical report for the Inkling 2 verify exactness work and its CHANGELOG entry, and fixes three clippy findings (a redundant rebinding and two needless borrows) left by moving the chunked prefill into Inkling2Model::prefill_speculative. Refs #3280
This was referenced Nov 24, 2026
inureyes
marked this pull request as ready for review
November 24, 2026 16:50
This was referenced Nov 24, 2026
Closed
inureyes
added a commit
that referenced
this pull request
Nov 25, 2026
## Summary - Inkling-Small MTP verify is now byte-identical to classic decode at every width the gate admits. The probe on `inkling-small-mlx-4bit` passed at widths 2 to 8 but declined at 10 (the MTP default) from layer 0: past 8 queries MLX's fused SDPA leaves the per-query kernel a decode step runs. A verify block now attends in groups of at most 8 queries. The probe passes at widths 2, 3, 4, 8, 10 and 16, after short, 600- and 2100-token prompts. - A partial accept keeps the verify block's own state (KV tail trim, convolution states from the block's recorded input windows) instead of restoring a snapshot and replaying the kept prefix. The replay ran outside the verify scope, so it did not rebuild classic decode's state (the old width-3 prose stream left classic), and it was a second target forward per round. The snapshot/replay path remains for blocks outside the row-invariant scope. - The Inkling 2 half of the issue was finished by #3405 and #3417; Inkling 2 code is untouched. ## Measured (M3 Ultra, 128 greedy tokens, ABAB) | Mode | Prose before | Prose after | Code before | Code after | |---|---|---|---|---| | classic | | 45.1 | | 44.4 | | width 2 | 25.9 | 39.7 | 27.0 | 41.6 | | width 3 | 23.6 (differs) | 34.6 | 24.4 | 34.9 | | width 10 (adaptive) | 10.4 (override, differs) | 12.7 | 10.6 (override, differs) | 12.7 | Mean accepted length is 1.43 to 1.63, nearly all from the first draft. The drafter matches mlx-vlm 466069f5 in chain indexing, hidden-state source and logit path (upstream: 1.59). An experiment starting post-seed drafts at block 1 left acceptance unchanged. No width beats classic, so MTP stays opt-in (`--draft-model`). The #3417 adaptive width belongs to the DFlash loop and does not apply to the MTP loop. Details: `docs/benchmark_results/inkling-small-mtp-m3ultra-2026-11-25.md`. ## Test plan - [x] New `mtp_partial_accept_keeps_the_single_token_chain_state_on_metal` and widths 10, 16 in `the_verify_block_matches_the_chain_on_metal`: both fail on the previous code, pass now - [x] `survey_block_vs_chain` on `inkling-small-mlx-4bit`, widths 2, 3, 4, 8, 10, 16; ignored real-checkpoint probe test (now with width 10) on the bf16 0.6B and the 4-bit Small checkpoints - [x] Narrow selectors: `models::inkling` (covers `inkling2`), `coverage_tests`, `inkling_mtp`, `speculative_exactness`, `speculative_burst`, mlxcel-core `inkling` and `row_invariant` - [x] fmt, both clippy gates, and the contract scripts; the broad gate is left to CI Closes #3280
This was referenced Nov 27, 2026
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.
Makes an Inkling 2 speculative verify block byte-identical to single-token decode, so the block-versus-chain probe passes and the bundled DSpark drafter runs without
MLXCEL_MTP_ALLOW_INEXACT=1. Refs #3280 (the issue also covers the first Inkling generation, so it stays open).Causes
A per-visit hidden-state comparison of an 8-row verify block against 8 decode steps found five, none of them in the quantized expert path:
query @ bank^Tis a batched matmul over the block length.Change
mlxcel_core::row_invariant: an opt-inScope/Modeplusdense,linear,per_rowandper_position, backed by a new Metal kernelrow_invariant_matvec(1 to 16 rows, summation order fixed by K and N). Outside a scope the helpers are plainmatmul/forward, so other models are untouched.MLXCEL_INKLING2_KERNELS=0or off Metal a verify block multiplies one row at a time (exact, slower). Dense experts are split per token there too.build.rsnow watches the Inkling 2 kernel sources; edits to them were never rebuilt.Results (M3 Ultra)
Details:
docs/benchmark_results/inkling2-verify-exactness-m3ultra-2026-11-24.md; report:TECHNICAL_REPORTS/3405-inkling2-verify-exactness-20261125.{en,ko}.md.