Repository navigation
Description
Problem / Background
Qwen 3.5 never takes DFlash speculative decoding on CUDA by default. PR #1944 (d8020beb, closing #1935) made Qwen35Model::probe_block_chain_exactness return NotRun for head_dim 256 or 288 while MLXCEL_SDPA_VECTOR_LARGE_D is on, because on GB10 the served width 2 and 4 greedy completions on qwen3.5-4b-4bit + qwen3.5-4b-dflash part from classic decode at generated token 105, and the probe could not see it. The burst is worth 1.18x to 1.22x over classic on that pairing (docs/benchmark_results/dflash-sdpav-options-qwen35-gb10-2026-09-21.md), all of it forfeited today.
PR #2185 (#2160, 97f35bca) found that Gemma 4's equivalent CUDA failure was not the attention kernel alone: MLX's CUDA RoPE runs rope_single for B=1, L=1 and the general rope kernel otherwise, and the two differ in the last float bit, so a width-B verify block cannot be byte-identical to single-token decode. It fixed that by rotating Q and K one row at a time (TECHNICAL_REPORTS/pr-2185-gemma4-mtp-cuda-verify.en.md, Follow-up: "Qwen 3.5 DFlash's CUDA residual (#1935) may be the same RoPE kernel choice; untested here"). This issue tests that, and either fixes it or records the negative result.
Current Behavior
- The Qwen 3.5 full-attention verify forward is
Qwen3NextAttention::forward_hidden_with_position_ids_verify(src/models/qwen3_next.rs:679). Attention is already per row (attend_per_position,:811), so thesdpa_vectorhalf of fix(gemma4): make MTP verify byte-identical to decode on CUDA #2185 is already done here. RoPE is not:fast_roperotates the whole[B, H, L, D]block for Q and K at once (:750-761), and the block-rotated K is then written into the KV cache byupdate_and_fetch(:764). If the two kernels differ, the difference persists in the cache for every accepted token, which fits the residual's shape (first differing row 36 tokens past the prompt, first differing layer 15, a full-attention layer, position-dependent rather than round-dependent). - The decline is
Qwen35Model::cuda_sdpa_vector_verify_hazard(src/models/qwen3_5.rs:1635-1662), called first inprobe_block_chain_exactness(:1664-1691). Widths 8 and 16 also decline for a separate, real reason (MLX'sM * B < 8switch fromqmvtoqmm_sm80), which the probe observes and per-row RoPE will not change. - The evidence behind fix(speculative): decline the Qwen 3.5 DFlash burst the probe cannot vet #1944 does not exclude RoPE.
docs/benchmark_results/dflash-width-2-4-residual-qwen35-gb10-2026-09-21.md:73-75,105says the per-row Q/K/V tensors have "the same values in both paths", but that was inferred from copy predicates and a slice-copy A/B, not from capturing post-RoPE Q and K. Its in-processLARGE_D=0result (1 of 201 disagreements to 0) counts argmaxes, not logit bytes, and the record notes an unexplained 0/201 vs 1/201 discrepancy across sessions. qwen3.5-4b-4bitloads asLoadedModel::Qwen35VLMand its config declaresrope_parameters.mrope_interleaved: true,partial_rotary_factor: 0.25,head_dim: 256.src/models/qwen3_5.rs:2121says text-only requests takefast_rope(position_ids = None), but which branch the served verify actually takes has to be confirmed, because the mrope branch (qwen3_next.rs:723-749) usescos/sinmultiplies and no RoPE kernel at all.
Proposed Solution
Step 1, attribution (GB10, real checkpoints /home/inureyes/models/mlx/qwen3.5-4b-4bit and qwen3.5-4b-dflash).
- Confirm which RoPE branch the verify block and classic decode take on this checkpoint (a temporary log or capture in
forward_hidden_with_position_ids_verify). - Op-level check:
fast_ropeon a[1, 16, 4, 256]bf16 tensor (and the K shape[1, 4, 4, 256]) withdims 64, traditional false, base 1e7, scale 1.0, against fourL=1calls atoffset + row, compared in bytes, over several offsets (include ~194) and random draws. - Model-level capture, the fix(gemma4): make MTP verify byte-identical to decode on CUDA #2185 method: a temporary capture of post-RoPE Q and K inside the attention layer, comparing verify row r against the decode step at the same absolute position, at every full-attention layer, over the first ~60 positions past the perf(speculative): the default draft block width of 16 loses on GB10 #1797 harness's 158-token prompt. Drive it from the existing
block_versus_chain_byte_bisect_on_the_real_transcriptdiagnostic (src/models/qwen3_5_dflash_probe_tests.rs:974; envMLXCEL_Q35_PROBE_PROMPT,MLXCEL_Q35_PROBE_REFERENCE,MLXCEL_Q35_PROBE_BLOCK,MLXCEL_Q35_PROBE_ACCEPTS) and record the first differing sub-op (post-RoPE Q, post-RoPE K, attention output, o_proj, MLP). - Attribution matrix in logit bytes, not argmaxes, n >= 3 repeats per cell: per-row RoPE experiment {off, on} x
MLXCEL_SDPA_VECTOR_LARGE_D{1, 0}, at widths 2 and 4. Add one cell checking that the dense MLP activation (compiled_silu,qwen3_next.rs:909) runs the same graph at M=1 and M>1; fix(gemma4): make MTP verify byte-identical to decode on CUDA #2185's compiled-vs-eager cause has no visible switch here, so this is a check, not a hypothesis. Do not rerun the gated-delta chain-parity control; fix(speculative): prefill the Qwen 3.5 DFlash burst like classic decode #1939 excluded it.
Decision rule: if post-RoPE K bytes differ between block and decode and the per-row RoPE cell with LARGE_D=1 makes the bisect report zero differing rows, RoPE is the cause; go to Step 2. If post-RoPE Q/K are byte-identical, or per-row RoPE leaves the divergence in place, go to Step 3.
Step 2, fix (only if Step 1 implicates RoPE).
- In
forward_hidden_with_position_ids_verify, on thefast_ropebranch only, whentarget_verify && l > 1 && b == 1on CUDA, rotate Q and K one row at a time: slice rowralong axis 2,fast_rope(..., offset + r),concatenate_manyalong axis 2. MirrorAttention::head_rows_like_decode(src/models/gemma4_attention.rs:163); do not call it (it is an inherent method on Gemma'sAttention). Readmlxcel_core::cuda_is_available()once at construction into a field, as Gemma'smtp_row_ropedoes (src/models/gemma4.rs:1704), not per call. - Make the probe able to see the hazard before trusting it. The shipped probe compares one block right after prefill and reported byte-identity at widths 2 and 4 at every prompt length from 8 to 512 while the served path diverged. Add a long draw to
probe_block_chain_exactnessthat walks blocks and the chain together for at least 64 positions past the prompt, following Gemma 4's long buffered draw (mtp_probe_prompt_lengths,src/models/gemma4.rs:290-296). Then delete thecuda_sdpa_vector_verify_hazarddecline. - Widths 8 and 16 must still decline through the probe's measured verdict. Do not change the
MLXCEL_MTP_ALLOW_INEXACToverride ormtp_exactness_gate.
Step 3, negative result. Leave the decline in place, add a record under docs/benchmark_results/ with the matrix and captures, and comment on #1935 with the result and the first differing sub-op.
Scope
In scope: src/models/qwen3_next.rs (verify RoPE), src/models/qwen3_5.rs (probe long draw, hazard removal), src/models/qwen3_5_dflash_probe_tests.rs (capture diagnostics), tests/speculative_parity.rs (greedy_parity_dflash_qwen35_4b at :740, assert_server_byte_equality_at_widths at :305), a record under docs/benchmark_results/, and a technical report under TECHNICAL_REPORTS/ for the PR.
Out of scope: patching MLX's rope.cu (it would move classic decode numerics for every CUDA model, as #2185 notes); the mrope/image branch; Qwen 3.5 MTP on CUDA (mtp_exactness_allows requires Metal); the width 8/16 qmm_sm80 decline; the default draft width (#1797).
Acceptance Criteria
- The attribution is recorded under
docs/benchmark_results/with the RoPE-branch confirmation, the op-level result, the first differing sub-op from the capture, and the full matrix with n >= 3 per cell in logit bytes. - If fixed: a test in
qwen3_5_dflash_probe_tests.rsshows the new long probe draw returns a divergent verdict at width 2 or 4 with the fix reverted and the decline bypassed, andEqualwith the fix. Without this a passing probe proves nothing, because the old probe also passed. - If fixed: on GB10 with no env overrides,
mlxcel-server --draft-kind dflashlogs a passing probe and completed bursts at widths 2 and 4, and greedy/v1/completionsoutput at temperature 0 is byte-identical to the drafter-less server on three prompts (the chat prompt in the test returns emptycontenton this checkpoint, so it does not count). - If fixed:
greedy_parity_dflash_qwen35_4brequires a completed burst and byte-equal completions at widths 2 and 4, and accepts a decline at 8 and 16 only with the probe's divergent-verdict reason. - If fixed: throughput at the width main resolves for this pairing on GB10, against classic, measured with
docs/benchmark_results/data/dflash-sdpav-options-gb10-2026-09-21/harness/price_options.pyin n >= 3 interleaved rounds with a classic-vs-classic null arm; report paired deltas and treat any gap inside the null arm's spread as unresolved. - Metal is unchanged by construction (CUDA-gated). If any shared code path changes, list it in test: Apple Silicon verification pass for 2026-10-06 CUDA-only changes #2158.
- If not fixed: the decline stays, and fix(speculative): Qwen 3.5 DFlash verify diverges from classic decode #1935 has a comment with the evidence. (Not applicable: fixed in perf(qwen35): byte-identical CUDA DFlash verify via per-row RoPE #2207; fix(speculative): Qwen 3.5 DFlash verify diverges from classic decode #1935 has a comment with the evidence anyway.)
Verification
cargo build --release --features cuda
cargo test --release --features cuda -p mlxcel --lib -- --ignored --test-threads=1 --nocapture models::qwen3_5::qwen3_5_dflash_probe_tests
cargo test --release --features cuda --test speculative_parity -- --ignored greedy_parity_dflash_qwen35_4b --test-threads=1 --nocapture
cargo clippy -p mlxcel --lib --tests --features cuda -- -D warnings
cargo fmt --check
--test-threads=1 is required on CUDA. Run GPU work under gpu-lock run --tag dflash-qwen35 -- ... and build outside the lock. Record driver, kernel and MLX_CUDA_ARCHITECTURES in the record.
Activity
docs(bench): record the Qwen 3.5 DFlash verify RoPE attribution
inureyes commentedon Oct 7, 2026
Findings for PR #2207. RoPE is the cause, so the fix is in.
fast_ropebranch onqwen3.5-4b-4bit. Classic runs 96 decode calls atl=1. The verify block runs 32 calls atl=4and 8 atl=2. No call took MRoPE. A temporary log on the served path showed this.fast_ropeon a block against decode-shaped rows differs in 1 byte across 144 cases. Rotating row by row gives 0.compiled_silumatches the per-row result exactly (0 bytes).o_projand the MLP never differ first.LARGE_D=1and 129 atLARGE_D=0, at both width 2 and width 4. With per-row RoPE, 0 rows differ in all four cells. The decision rule therefore points to RoPE.The new long-draw test lives in
qwen3_5_rope_attribution_tests.rsrather thanqwen3_5_dflash_probe_tests.rs, which is already over 1000 lines. With the fix reverted, the test diverges at walk position 19; with it applied, both widths returnEqual. Record:docs/benchmark_results/qwen35-dflash-verify-rope-gb10-2026-10-07.md.docs(bench): note the round-2 CI gate field in the #2191 data README
perf(qwen35): rotate the CUDA DFlash verify block's RoPE row by row
test(qwen35): time the verify block with and without per-row RoPE
docs(bench): record the Qwen 3.5 DFlash verify RoPE attribution
docs(bench): note the round-2 CI gate field in the #2191 data README
perf(qwen35): byte-identical CUDA DFlash verify via per-row RoPE (#2207)