Skip to content

feat: survey speculative exactness and make Inkling verify exact - #3415

Merged
inureyes merged 5 commits into
mainfrom
feature/issue-3409-speculative-exactness-survey
Nov 24, 2026
Merged

inureyes merged 5 commits into
mainfrom
feature/issue-3409-speculative-exactness-survey

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Surveys block-versus-chain exactness across the drafter-capable families on an M3 Ultra (widths 2, 4, 8; short prompts, 600 and 2100 tokens) and makes Inkling's verify block byte-identical to decode, the one family whose cause was dense gemv/gemm.

  • Survey (docs/benchmark_results/speculative-exactness-survey-m3ultra-2026-11-25.md): Qwen 3.5, Qwen3.8-Flash-Next, Gemma 4 12B and 31B, GLM-4.7-Flash and LFM2 are exact on the narrow quantized kernel at every width and context length, and drafter-on text equals classic text past the prefill chunk. Gemma 4 26B A4B declines in its MoE feed-forward and stays declined. The ungated token-only verify round (prompt lookup) differs on every model it takes; on DeepSeek V3 from the layer 0 output, where a single query takes the absorbed MLA path. No adoption there.
  • Diagnostic: models::speculative_exactness_diag (capture, locate, report), generalized from the Gemma 4 trace and the Inkling 2 per-visit test, which now uses it.
  • Inkling: dense products through mlxcel_core::row_invariant; inside a verify block the short convolutions, experts and sliding attention past the window run per position. The probe passes on bf16 inkling-0.6b where it declined at layer 0. Decode 244.4 tok/s with the kernel, 239.3 without (8 ABAB pairs). MLXCEL_INKLING_ROW_INVARIANT=0 is the A/B switch.
  • Probe: a shared draw plan adds one draw past the sliding window for Inkling, Laguna and Muse Glimmer; families without a window run the same draws as before. MLXCEL_MTP_PROBE_LONG_CONTEXT overrides.
  • Kernel fix: row_invariant_matvec failed to build its Metal library for inputs of fewer than 8 elements.

Not measured

MTP throughput on Inkling and whether quantized Inkling-Small passes (those checkpoints were off limits; 0.6B has no MTP head). The long draw on real Laguna and Muse Glimmer checkpoints (none on disk). Inkling 2's probe is untouched (#3410 owns that code). deepseek-v4-flash skipped.

Test plan

  • Seeded-mismatch, sliding-window and unchanged-cost unit tests; tiny Inkling test that differs without the change and is equal with it; ignored real-checkpoint test of the same
  • Narrow lib selections for the touched families, coverage_tests, core row_invariant and inkling
  • clippy (--lib --tests --bins), fmt and the contract checks; the issue's broad commands are left to the gate

Closes #3409

PR #3405 found five reasons an Inkling 2 verify block differed from decode, two of them invisible to the 8-token startup probe. This surveys the other drafter-capable families on an M3 Ultra at widths 2, 4 and 8, after short prompts and after 600 and 2100 tokens, and fixes the one family whose cause is dense gemv/gemm.

- Survey: the quantized gated families (Qwen 3.5, Qwen3.8-Flash-Next, Gemma 4 12B and 31B, GLM-4.7-Flash, LFM2) are exact on the narrow quantized kernel at every width and context length, and their drafter-on text equals classic text on a prompt past the prefill chunk. Gemma 4 26B A4B declines in its MoE feed-forward. The ungated token-only verify round differs on every model it takes. Table in docs/benchmark_results/speculative-exactness-survey-m3ultra-2026-11-25.md.
- Diagnostic: the Gemma 4 probe trace becomes models::speculative_exactness_diag (capture, locate, report), used by the Gemma 4 and Inkling startup probes, the DeepSeek V3 layer loop, the survey test and the Inkling 2 per-visit test.
- Inkling: dense products go through mlxcel_core::row_invariant, and inside a verify block the short convolutions, the experts and sliding attention past the window run per position. The probe now passes on the bf16 0.6B checkpoint, where it declined at layer 0 before. Decode is 244.4 tok/s with the kernel against 239.3 without (8 ABAB pairs). MLXCEL_INKLING_ROW_INVARIANT=0 restores the old products.
- Probe: models::speculative_exactness_draws owns the draw plan. Families with a sliding layer (Inkling, Laguna, Muse Glimmer, Gemma 4 as before) add one draw past the window; the others run the draws they ran before. MLXCEL_MTP_PROBE_LONG_CONTEXT moves the gate.
- Kernel: row_invariant_matvec indexes its inputs instead of taking device pointers, because MLX binds an array of fewer than 8 elements as constant and the Metal library then failed to build (a tiny test model's row).

Validated with the narrow lib selections for the touched families, clippy and the contract checks. Not measured: MTP throughput on Inkling and the long draw on Laguna and Muse Glimmer checkpoints, none of which is on disk.

Refs #3409
@inureyes inureyes added status:review Under review type:performance Performance improvements priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) platform:macos macOS (Apple Silicon) specific labels Nov 24, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 24, 2026
@inureyes
inureyes marked this pull request as ready for review November 24, 2026 22:58
@inureyes
inureyes merged commit 40b129d into main Nov 24, 2026
34 checks passed
@inureyes
inureyes deleted the feature/issue-3409-speculative-exactness-survey branch November 24, 2026 22:58
inureyes added a commit that referenced this pull request Nov 25, 2026
## 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

- **Gemma 4 26B A4B.** The narrow-kernel divergence starts at layer 0 `MoE experts` (shared MLP and router agree): `Experts::forward` picks 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 now `equal` on the narrow kernel at widths 2, 4, 8, at startup, 600 and 2100 tokens, so the gate engages as on 12B and 31B.
- **Token-only rounds.** On `DeepSeekV3Model` 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, 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: `equal` on gigachat3 bf16; `equal` with `MLXCEL_QMV_WIDE=0` on 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).
- **Off by default.** Prompt lookup on a copy-heavy reply drops from 261.7 to 148.5 tok/s on bf16 and from 343.8 to 260.8 on 8-bit. Plain decode does not regress. No gate was added.
- Arcee, K2 Horizon and OLMoE are located (layer 0 output) and kept as documented.

## Not met

- No 26B A4B drafter is on disk, so MTP throughput there is unmeasured.
- Item 2's `equal` holds only with the opt-in (plus `MLXCEL_QMV_WIDE=0` on quantized checkpoints).
- DeepSeek V3.2 and Kimi Linear share the cause and are unchanged.

## Test plan

- [x] New tiny-model Metal tests: `gemma4::moe_verify_tests`, `deepseek_v3::verify_block_tests`, a GLM routing test. Each has a companion asserting the pre-change path differs.
- [x] Narrow lib suites under the GPU lock: gemma4, deepseek_v3, xing4_0, glm4_moe_lite, llama3, arcee, olmoe, youtu, speculative_exactness, `coverage_tests`.
- [x] `survey_block_vs_chain` on the checkpoints above; ABAB decode (8 pairs) and prompt lookup (4 cycles) in `docs/benchmark_results/speculative-exactness-followup-m3ultra-2026-11-25.md`.
- [x] `cargo clippy --lib --tests --bins` and `-p mlxcel-core --lib --tests` with `-D warnings` (narrow stand-ins for the issue's `--all-targets`), `cargo fmt --check`, contract scripts.

Closes #3418
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata platform:macos macOS (Apple Silicon) specific priority:medium Medium priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Survey speculative exactness across drafter models, adopt row_invariant

1 participant