Skip to content

perf: Trace the two remaining speculative verify mismatches: Gemma 4 26B A4B MoE and token-only verify rounds #3418

Backlog

Description

@inureyes

Background

PR #3415 (closes #3409) surveyed whether a K-row speculative verify block is byte-identical to K single-token decode steps. Two mismatches were left untraced. Numbers, model list and commands are in docs/benchmark_results/speculative-exactness-survey-m3ultra-2026-11-25.md and TECHNICAL_REPORTS/3415-speculative-exactness-survey-20261125.en.md. Tools: the per-layer diagnostic src/models/speculative_exactness_diag.rs, the ignored survey models::speculative_exactness_survey_tests::survey_block_vs_chain (EXACTNESS_SURVEY_MODEL, _WIDTHS, _PROMPTS, _PATH, _DIAG=1), and the opt-in fix module mlxcel_core::row_invariant (per_row, per_position, dense, linear).

Implement both items in one PR, run the local gate once at the end, and keep pushes to a minimum.

1. Gemma 4 26B A4B MoE verify block

models/gemma-4-26b-a4b-it-4bit declines the MTP startup probe on both the wide and narrow kernels; on narrow the first divergence is layer 0 MLP output (src/models/gemma4.rs:2970). The feed-forward is ffn_branch (src/models/gemma4.rs:3053): shared MLP, Router::forward (:1064), Experts::forward (:1115), combine. One likely cause: Experts::forward takes the fused single-token GeGLU kernel when b * s == 1 and SwitchGeGLU with gather_qmm otherwise. Confirm with the diagnostic before fixing.

  • Add diag::capture points inside ffn_branch (shared MLP, router indices and weights, experts, combine) and record which product differs first.
  • Make the block exact inside a verify scope, for example per-position experts via row_invariant::per_position as src/models/inkling2/moe.rs:231 (expert_projections) does, or a row-invariant quantized path. Outside a verify block, decode must take today's kernels unchanged.
  • Measure decode tok/s ABAB on M3 Ultra (8 pairs, mlxcel generate --temp 0 --profile). If exactness costs more than the drafter gains, keep the checkpoint declined and record the measurement in the survey doc.

Acceptance:

  • The survey doc names the first differing product.
  • survey_block_vs_chain with EXACTNESS_SURVEY_MODEL=models/gemma-4-26b-a4b-it-4bit reports equal at widths 2, 4, 8, startup, 600 and 2100 tokens on at least one kernel, and the probe accepts the drafter; or the doc records why it stays declined.
  • A tiny-model Metal test for a Gemma 4 MoE layer that fails on current code (block differs from chain) and passes after the fix.
  • No decode regression in the ABAB table.

2. Token-only verify rounds

All 10 models on the engine path (prompt lookup, FullModelDrafter) differ at row 0 at every width and length (survey doc, "Models without a gate"). On DeepSeek V3 the diagnostic puts it at layer 0 output: use_absorbed_mla (src/lib/mlxcel-core/src/mla/mod.rs:371) always absorbs l == 1, and the block at src/models/deepseek_v3.rs:374 usually takes the decompressed path. The contract (docs/speculative-acceptance.md:92, :149) allows this, but xing4.0 8-bit diverged end to end once on the long prompt.

  • DeepSeek V3 family (deepseek_v3.rs, and deepseek_v32.rs:420, kimi_linear.rs:650 if they share the cause): inside the verify block, take the same MLA path a single query takes, and check that the absorbed block equals the fused single-query kernel row for row (the fused kernel and the composed fallback may differ).
  • Other families (xing4_0, GLM engine path, arcee, k2_horizon, OLMoE): run EXACTNESS_SURVEY_DIAG=1, then make exact or keep as documented, by cost.
  • Do not add a gate that disables prompt lookup.

Acceptance:

  • EXACTNESS_SURVEY_PATH=engine reports equal on gigachat3 bf16 and 8-bit, Kimi-VL and moonlight at all widths and lengths, if the ABAB decode and prompt-lookup cost is acceptable.
  • A tiny DeepSeek V3 test where a 2- and 4-row block in the speculative append scope matches the chain; fails on current code.
  • The survey doc and docs/speculative-acceptance.md record the decision per family.

Out of scope

First-generation Inkling MTP throughput and the inkling-small probe (#3280). Inkling 2 (#3405, #3417).

Verification

Large checkpoints on this host run under the GPU lock:

/usr/bin/lockf -k /Users/devops/Development/.mlxcel-gpu.lock \
  env EXACTNESS_SURVEY_MODEL=models/gemma-4-26b-a4b-it-4bit EXACTNESS_SURVEY_DIAG=1 \
  cargo test --profile test-fast --features metal,accelerate --lib \
  models::speculative_exactness_survey_tests -- --ignored --nocapture
cargo clippy --features metal,accelerate --all-targets -- -D warnings
cargo fmt --check

Activity

  1. added
    status:ready
    type:performance
    priority:medium
    area:models
    area:inference
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:inferencearea:modelspriority:mediumstatus:readytype:performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions