Skip to content

fix(models): keep Raon DFlash2 verify blocks byte-exact on CUDA - #3476

Merged
inureyes merged 6 commits into
mainfrom
fix/issue-3474-raon-dflash-cuda-exactness
Nov 28, 2026
Merged

inureyes merged 6 commits into
mainfrom
fix/issue-3474-raon-dflash-cuda-exactness

Conversation

@inureyes

@inureyes inureyes commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

On CUDA the Raon-1 mini DFlash2 exactness probe failed, so the drafter was declined (output unchanged, speculative decoding off). Two causes, both fixed so each verify row equals its decode step on every backend:

  • mHC products batched over the positions (basis @ z @ basis_t, aggregate, mix) pick their CUDA kernel by block length. Inside a verify block they now run per position; prefill and decode keep one matmul.
  • Decode steps take the compiled mHC site graphs (feat(perf): speed up Raon-1 mini decode, load and prompt reuse #3461) while verify blocks took the eager ops, and on CUDA the fused graph rounds differently (FMA contraction). Verify blocks now run the same compiled graphs once per position.

compiled_site_equals_the_eager_site_bit_for_bit stays bit-exact on Metal and CPU and allows rounding-level differences on CUDA and ROCm (worst observed 1.6e-7 relative on CUDA, 1 ulp on ROCm, the ROCm case also on main). New a_compiled_verify_block_equals_its_decode_steps_bit_for_bit covers the invariant exactness now relies on.

Validation

  • GB10 (--features cuda): raon 53/53 under every MLXCEL_RAON_DECODE_FUSION value (default, off, selector, mhc); speculative 207, exactness 36, gated_delta 14; clippy -D warnings clean. The four raon1_mini::speculative tests failed on main before this change.
  • Metal (M1 Ultra): raon 53/53 under every fusion value, exactness 36, gated_delta 14; speculative has one failure that is the pre-existing test(models): two Metal block-vs-chain byte-identity tests fail on M1 Ultra #3468 (same on base).
  • ROCm gfx1151 at 060dfeb5: the four DFlash2 tests that failed on main pass; speculative 210, exactness 36, gated_delta 14. The compiled_site byte failure (also on main) is covered by the ROCm tolerance in 29e67acd. native_batched_decode_matches_per_sequence_decode exceeds its 1e-5 tolerance by about 1.2e-6 under off and mhc, also on main, unrelated to this PR.
  • Real checkpoint on Metal (Raon-1-mini-mlx with Raon-1-mini-dflash2): probe passes, temperature-0 output with the drafter equals plain decode and the base, decode tok/s within noise of the base at width 3. Not run on CUDA (no checkpoint on the GB10 host).

Closes #3474

The Raon-1 mini exactness probe failed on CUDA (GB10), so `mtp_exactness_gate` declined the DFlash2 drafter there. Output was unchanged (fail-closed), but speculative decoding was off. Two products made a verify row differ from its decode step in the last bit:

- The mHC route, aggregate and mix multiply batched over the positions (`basis @ z @ basis_t`, `h_pre @ streams`, `h_res @ streams`). CUDA picks the batched kernel, and so the summation order, by the block length. Inside a verify block they now run one position at a time; prefill and decode keep one matmul.
- Since #3461 a decode step takes the compiled mHC site graphs, while a verify block took the eager ops. On CUDA the fused graph can contract a multiply and an add into one FMA, so the two differ by rounding. A verify block now runs the same compiled graphs once per position, so its rows equal the decode steps by construction on every backend.

`compiled_site_equals_the_eager_site_bit_for_bit` stays bit-exact off CUDA and allows rounding-level differences on CUDA (observed worst 1.6e-7 relative). New `a_compiled_verify_block_equals_its_decode_steps_bit_for_bit` covers the invariant exactness now relies on.

Validated on GB10 (`--features cuda`): `raon` 53/53 under every `MLXCEL_RAON_DECODE_FUSION` setting (default, off, selector, mhc), `speculative` 207, `exactness` 36, `gated_delta` 14. Metal and ROCm runs are pending. No Raon-1 mini checkpoint is on this host, so the real-checkpoint probe was not run.

Closes #3474
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:models Model architectures, weights, loading, metadata modeltype:text Text-only language model labels Nov 27, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Metal validation (M1 Ultra, head 060dfeb5)

--profile test-fast --features metal,accelerate, --test-threads=1. Machine load average 8 to 15 during the run (background load).

Suite Result
raon, MLXCEL_RAON_DECODE_FUSION unset 53 passed, 0 failed
raon, off 53 passed, 0 failed
raon, selector 53 passed, 0 failed
raon, mhc 53 passed, 0 failed
speculative 205 passed, 1 failed, 6 ignored
exactness 36 passed, 4 ignored
gated_delta 14 passed, 11 ignored

Named tests, each ok in all four raon runs (the raon1_mini::speculative ones also ok in the speculative run):

  • raon1_mini::speculative::tests::a_verify_block_equals_the_decode_chain_byte_for_byte: ok
  • raon1_mini::speculative::tests::a_steered_verify_block_applies_the_alpha_exactly_as_decode_does: ok
  • raon1_mini::speculative::tests::rollback_after_a_partial_accept_equals_a_fresh_decode_of_the_accepted_tokens: ok
  • raon1_mini::speculative::tests::the_exactness_probe_passes_on_the_tiny_model: ok
  • raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit (byte comparison on Metal): ok
  • raon_mhc::tests::a_compiled_verify_block_equals_its_decode_steps_bit_for_bit: ok

The one speculative failure is unrelated to this PR: models::inkling2::speculative::tests::the_verify_block_matches_the_chain_on_metal panics at src/models/inkling2_speculative_tests.rs:192:13 with passes 1 width 2: Diverges { position: 0, differing_bytes: 28, total_bytes: 120 }. It fails identically 3 of 3 times on this head and 3 of 3 times on the base 89425173, and this PR touches only raon_mhc*.rs. It is the M1 Ultra failure already tracked in #3468.

Not run: the real-checkpoint DFlash2 exactness probe, the temperature-0 drafter on/off output comparison, and the decode tok/s comparison against 89425173. No Raon-1 mini checkpoint (raon-1-mini, raon-1-mini-mlx, raon-1-mini-nvfp4) or DFlash2 drafter for it is present on this host, so the cost of running the compiled site graphs per position in the verify block is still unmeasured on Metal.

@inureyes

Copy link
Copy Markdown
Member Author

ROCm gfx1151 validation at 060dfeb5

Head 060dfeb5cc9c963bb491dec4d358905fe75f1819, built on the host (AMD Radeon 8060S, Strix Halo gfx1151). Every run was under scripts/rocm_gpu_guard.sh --hold.

run result
make test-fast-rocm FILTER=raon, MLXCEL_RAON_DECODE_FUSION unset 52 passed, 1 failed
same, =off 51 passed, 2 failed
same, =selector 52 passed, 1 failed
same, =mhc 51 passed, 2 failed
FILTER=speculative PASS: 206 + 4 passed, 0 failed
FILTER=exactness PASS: 36 passed, 0 failed
FILTER=gated_delta PASS: 14 passed, 0 failed

Requested tests, per fusion mode (unset / off / selector / mhc):

test result
raon1_mini::speculative::tests::a_verify_block_equals_the_decode_chain_byte_for_byte ok / ok / ok / ok
raon1_mini::speculative::tests::a_steered_verify_block_applies_the_alpha_exactly_as_decode_does ok / ok / ok / ok
raon1_mini::speculative::tests::rollback_after_a_partial_accept_equals_a_fresh_decode_of_the_accepted_tokens ok / ok / ok / ok
raon1_mini::speculative::tests::the_exactness_probe_passes_on_the_tiny_model ok / ok / ok / ok
raon_mhc::tests::a_compiled_verify_block_equals_its_decode_steps_bit_for_bit ok / ok / ok / ok
raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit FAILED / FAILED / FAILED / FAILED

The four DFlash2 tests that failed on ROCm at main 894251735 now pass, so the fix holds on gfx1151.

Both remaining failures already exist on main. At main 894251735, run twice per mode, they fail the same way. compiled_site_equals_the_eager_site_bit_for_bit fails in all four modes. native_batched_decode_matches_per_sequence_decode fails under off and mhc and passes under unset and selector. The PR does not cause them.

compiled_site_equals_the_eager_site_bit_for_bit: the assertion is identical in all four modes. One byte differs (203 vs 204), a 1-ulp difference in the first f32 of h_res:

thread 'models::raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit' panicked at src/models/raon_mhc_tests.rs:232:9:
assertion `left == right` failed: d 64 seed 0 dtype 12 rows 1: h_res
  left: [203, 221, 79, 63, 174, 176, 181, 60, 149, 119, 71, 61, 171, 233, 239, 61, 38, 88, 85, 61, 201, 242, 87, 63, 133, 179, 213, 61, 138, 174, 161, 55, 121, 34, 98, 60, 128, 152, 190, 61, 108, 16, 75, 63, 207, 159, 204, 61, 63, 33, 250, 61, 16, 202, 40, 61, 157, 26, 92, 61, 141, 109, 72, 63]
 right: [204, 221, 79, 63, 174, 176, 181, 60, 149, 119, 71, 61, 171, 233, 239, 61, 38, 88, 85, 61, 201, 242, 87, 63, 133, 179, 213, 61, 138, 174, 161, 55, 121, 34, 98, 60, 128, 152, 190, 61, 108, 16, 75, 63, 207, 159, 204, 61, 63, 33, 250, 61, 16, 202, 40, 61, 157, 26, 92, 61, 141, 109, 72, 63]

raon1_mini::tests::native_batched_decode_matches_per_sequence_decode (off and mhc only). The other panics in its output are the harness's expected-panic subcases. The failing assertion:

off: panicked at src/models/batched_decode_harness.rs:665:9:
mixed=true step 1 row 0 exceeds absolute tolerance 0.00001: max |diff| 1.1205673e-5, values [8.106232e-6, -7.1525574e-7, 2.9802322e-7, 3.0994415e-6, 6.914139e-6, -4.708767e-6, -4.887581e-6, 1.1324883e-6, 3.8444996e-6, 8.940697e-7, -1.9073486e-6, 1.1205673e-5, 1.66893e-6, -1.0728836e-6, -4.7683716e-7, -6.5118074e-6, 5.2452087e-6, -4.2915344e-6, -4.7683716e-7, -1.4305115e-6, -8.34465e-7, 5.841255e-6, 4.7683716e-6, 4.7683716e-7, -4.2915344e-6, -6.556511e-7, -1.1250377e-6, 5.9604645e-8, 7.867813e-6, -5.4836273e-6, -5.364418e-6, -5.00679e-6]
mhc: panicked at src/models/batched_decode_harness.rs:665:9:
mixed=true step 1 row 0 exceeds absolute tolerance 0.00001: max |diff| 1.168251e-5, values [8.46386e-6, -8.940697e-7, 1.3709068e-6, 2.503395e-6, 8.34465e-6, -4.2915344e-6, -5.2452087e-6, -3.5762787e-7, 4.7832727e-6, 6.556511e-7, -1.66893e-6, 1.168251e-5, 9.536743e-7, 2.3841858e-7, -4.7683716e-7, -6.1765313e-6, 4.7683716e-6, -3.6358833e-6, 1.4305115e-6, -1.2516975e-6, -1.0728836e-6, 5.2452087e-6, 4.2915344e-6, 0.0, -5.722046e-6, 1.7881393e-7, -1.4975667e-6, 3.427267e-7, 8.404255e-6, -5.364418e-6, -4.351139e-6, -4.529953e-6]

The raon runs stopped at the lib binary because it failed. No integration test matches the raon filter, so no coverage was lost.

@inureyes

Copy link
Copy Markdown
Member Author

Metal real-checkpoint validation (M1 Ultra), follow-up

This covers the items my previous comment listed as not run. Checkpoints were downloaded for this: KRAFTON/Raon-1-mini-mlx (df0153bc) and KRAFTON/Raon-1-mini-dflash2 (b625a6e1). Binaries: release --features metal,accelerate built from this head (060dfeb5) and from the base 89425173.

Exactness probe. MTP exactness probe passed: verify block is byte-identical to the single-token chain block_size=3 was logged in all 12 drafted mlxcel generate runs (6 per binary), and once at startup of mlxcel serve --draft-model models/raon-1-mini-dflash2 on this head. No MTP declined line appeared.

Temperature-0 equality. mlxcel generate -n 256 --temp 0, three prompts (short prose on hash-table collisions; a Python BST; the first 14000 bytes of README.md plus a summary instruction), plain and drafted, both binaries, two rounds: for each prompt all 8 outputs are byte-identical. Drafter on equals drafter off, and this head equals the base. Server on this head, chat completions at temperature 0, presence_penalty 0, 192 tokens, two prompts sent twice: the 4 responses (reasoning and content) from the drafter server are byte-identical to the 4 from a plain server, and the drafter server logged a speculative burst for each request.

Decode tok/s (round 1 / round 2, default width 3, arms interleaved base plain, base drafted, head plain, head drafted per prompt; load average 5.7 at 14:30 and 7.7 at 14:34, background load present):

Prompt Base plain Base DFlash2 Head plain Head DFlash2 Speedup base / head
Short prose 55.44 / 55.68 42.35 / 42.17 55.51 / 55.26 42.73 / 41.92 0.76x / 0.76x
Code 54.82 / 55.75 56.89 / 55.67 55.16 / 52.72 57.12 / 52.65 1.02x / 1.02x
Long prompt 29.91 / 29.27 41.33 / 40.78 30.12 / 29.93 41.62 / 39.89 1.39x / 1.36x

Acceptance is identical between the binaries (rate 0.502 / 0.833 / 0.537, 128 / 96 / 123 rounds). Verify time per round, base against head: short prose 44.4 / 44.1 ms, code 44.4 / 45.8 ms, long prompt 46.4 / 46.9 ms. The head's code round 2 is low in both its plain and drafted arms, which points to machine load and not the verify path. On Metal the per-position compiled site graphs cost within run-to-run noise, at most about 1% per verify round, at width 3.

Not measured: other widths (--draft-block-size 5 and 7), the bf16 + MXFP8 KRAFTON/Raon-1-mini and the ModelOpt Raon-1-mini-nvfp4 exports, and sampled drafting. No counter here shows that the new per-position branch ran. The branch has no backend gate and runs whenever in_verify_block() holds, and the binaries differ, but the attribution comes from reading the code, not from a measurement. Drafting is slower than plain decode on the short prose prompt on this M1 Ultra at width 3 with both binaries, so that is not caused by this PR.

ROCm gfx1151 showed the same 1-ulp `h_res` difference between the compiled site graph and the eager ops that CUDA does (also on main), so `compiled_site_equals_the_eager_site_bit_for_bit` now applies its rounding tolerance on ROCm builds too. Metal and CPU builds still compare bytes. The verify-block test that exactness relies on is unchanged and passes on ROCm.

Refs #3474
@inureyes

Copy link
Copy Markdown
Member Author

Metal verification of head 060dfeb5c on an M3 Ultra (--features metal,accelerate, make test-fast, RUST_MIN_STACK=16777216). Everything passed.

Suite Result
FILTER=raon, MLXCEL_RAON_DECODE_FUSION unset 53 passed, 0 failed
FILTER=raon, off 53 passed, 0 failed
FILTER=raon, selector 53 passed, 0 failed
FILTER=raon, mhc 53 passed, 0 failed
FILTER=speculative 210 passed, 0 failed
FILTER=exactness 36 passed, 0 failed
FILTER=gated_delta 14 passed, 0 failed

These six tests report ok under all four fusion values:

  • raon1_mini::speculative::tests::a_verify_block_equals_the_decode_chain_byte_for_byte
  • raon1_mini::speculative::tests::a_steered_verify_block_applies_the_alpha_exactly_as_decode_does
  • raon1_mini::speculative::tests::rollback_after_a_partial_accept_equals_a_fresh_decode_of_the_accepted_tokens
  • raon1_mini::speculative::tests::the_exactness_probe_passes_on_the_tiny_model
  • raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit: on a non-CUDA build assert_same_or_close compares raw bytes, so this is a byte comparison.
  • raon_mhc::tests::a_compiled_verify_block_equals_its_decode_steps_bit_for_bit

Real checkpoint

Target raon-1-mini-mlx, drafter raon-1-mini-dflash2, mlxcel-server --parallel 1 --no-prompt-cache -c 8192. The drafter resolves block_size=3 ("the Raon DFlash2 drafter's measured verify width"). Every server start, three on this PR and three on main 89425173, logged MTP exactness probe passed: verify block is byte-identical to the single-token chain block_size=3. No declines.

Greedy output (temperature 0, 256 tokens, two chat prompts): the text is byte-identical across drafter on and off, and across this PR and main, for both prompts in every run.

Throughput

The arms were interleaved and rotated per round: 3 rounds x 2 reps x 2 prompts, medians of 6 runs, load average about 2.1. Drafter-on arms set MLXCEL_ENABLE_MTP_B1=1 so the adaptive policy could not decline the burst. DFlash streams each burst at its end, so the rate is end to end, completion tokens divided by the time from request start to the last chunk. Prompts are about 30 tokens.

Arm Prompt 0 tok/s Prompt 1 tok/s
main, drafter off 59.08 (58.76 to 59.50) 59.10 (58.76 to 59.41)
PR, drafter off 59.37 (59.12 to 59.60) 59.38 (59.21 to 59.66)
main, drafter on 68.21 (67.91 to 68.46) 84.81 (84.59 to 85.45)
PR, drafter on 66.04 (65.41 to 66.90) 82.24 (81.59 to 82.90)

With the drafter off, the PR matches main. With the drafter on, the PR is 3.2% and 3.0% below main, and the min-max ranges of the two builds do not overlap. That gap is the measured cost of running the compiled site graphs once per position in the verify block. Acceptance per run: prompt 0 at 0.50 (128 rounds), prompt 1 at 0.77 (75 rounds). The drafter still pays for itself on both prompts (+11% and +39% over drafter off).

Nothing was pushed or merged.

@inureyes

Copy link
Copy Markdown
Member Author

ROCm validation of the new head 29e67acd on gfx1151 (AMD Radeon 8060S, Strix Halo).

make test-fast-rocm FILTER=raon_mhc under scripts/rocm_gpu_guard.sh --hold:

MLXCEL_RAON_DECODE_FUSION Result
unset 9 passed, 0 failed
off 9 passed, 0 failed

compiled_site_equals_the_eager_site_bit_for_bit now passes in both modes. It failed by 1 ulp on the previous head (and on main), and the ROCm tolerance branch added in 29e67acd absorbs that. a_compiled_verify_block_equals_its_decode_steps_bit_for_bit still compares bytes and passes in both modes.

Not re-run on this head: the mhc fusion mode and the full ROCm suite.

@inureyes

Copy link
Copy Markdown
Member Author

Hardening review

Reviewed against #3474. The fix is on the real path (RaonMhc::enter/leave, route, aggregate, mix_parts): inside a verify block the mHC products are formed one position at a time and the compiled site graphs run once per position, so each row takes the decode step's graph. Decode (L=1) and prefill take the same branch as before, and batch > 1 or L > MAX_ROWS falls back to eager, where the probe would decline rather than produce wrong output. The mechanism matches #3475 (row_invariant::per_position in a verify block); #3476 splits on every backend because the gap shows on CUDA and ROCm, and the cost lands only in verify blocks. No code findings; matmul_per_position partly duplicates row_invariant::per_position, which is harmless.

Pushed (bc52889d)

Merges of main (clean) and of 29e67acd (ROCm FMA tolerance in the compiled-site test). No code changes.

Validation (GB10, --features cuda, --profile test-fast, --test-threads=1)

  • fmt and clippy -p mlxcel --lib --tests --features cuda -D warnings clean.
  • raon 54/54 under every MLXCEL_RAON_DECODE_FUSION value; speculative 207 passed, exactness 36, gated_delta 14.
  • Revert experiment: with raon_mhc.rs and raon_mhc_decode.rs from main, 6 tests fail, the four raon1_mini::speculative tests from fix(models): Raon-1 mini DFlash2 verify block is not byte-exact on CUDA #3474 and the two new compiled verify-block tests.
  • Real checkpoint KRAFTON/Raon-1-mini-mlx bf16 + KRAFTON/Raon-1-mini-dflash2, mlxcel generate --temp 0 -n 192: 4 prompts, plain and widths 3/5/8, repeated, with and without MLXCEL_SDPA_DETERMINISTIC=1, all byte-identical to plain decode. The probe passes at every width and drafting really runs (classic_steps=0, acceptance 0.57 to 0.77). On main the probe declines (236633 of 519680 logit bytes differ), and main's plain output equals this branch's.
  • Plain decode, interleaved base/head on a lightly loaded box: 37.95 vs 38.46 tok/s mean, within noise.

Not run: Metal and ROCm (already reported in earlier comments), the NVFP4 and original bf16 exports, and sampled drafting.

@inureyes
inureyes merged commit 3cc7e21 into main Nov 28, 2026
33 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 28, 2026
@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:models Model architectures, weights, loading, metadata modeltype:text Text-only language model priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(models): Raon-1 mini DFlash2 verify block is not byte-exact on CUDA

1 participant