Repository navigation
feat(models): add Raon-1 mini DFlash2 speculative drafting - #3455
Conversation
Raon-1 mini ships a DFlash2 speculator (KRAFTON/Raon-1-mini-dflash2) that reads the four mHC streams at five tap layers and proposes a block through a grouped block conv, context-window attention and a candidate selector. This adds the drafter (mlxcel-core `drafter::raon_dflash2`, loaded by `load_drafter` and detected as a DFlash config) and the Raon-1 mini speculative target. The verify forward keeps every row equal to its decode step: RDA conv and recurrence run per position and record their state for the rollback, MLA runs one decode step per position, and the mHC selector, router, SiTU MLPs, RDA projections and head go through `row_invariant`. The burst caches carry the request's reasoning-effort alpha, so the server passes the sequence id into `run_dflash_on_target`. Server and offline `generate` dispatch Raon-1 mini behind the shared exactness gate. Tiny-model tests cover the drafter contract (grouped conv block boundary, hand-computed selector chain, named target_layer_ids error) and the target (capture order, steered and unsteered verify equal to decode byte for byte, rollback equal to a fresh decode). Refs #3436
The drafter's attention went through the bridge's plain SDPA, which broadcasts KV heads and aborted on the release's 20 query over 5 KV heads; it now uses the fast kernel, and the tiny test config is grouped so the unit tests cover it. Widths past the drafter's trained 8-row block are refused (drafter, offline CLI and the exactness probe), and `--draft-block-size` defaults to 5 for this drafter instead of the flat DFlash 16. On the real checkpoint (M3 Ultra) drafted temp-0 text equals plain decode at widths 3, 5 and 7 on three prompts including a 3137-token one, and on the server at reasoning effort high and low; width 5 runs 1.3x to 1.8x plain decode. Adds the benchmark doc, the supported-models and CHANGELOG entries, and documents MLXCEL_RAON_ROW_INVARIANT. Refs #3436
The DFlash round loop accepted only by argmax, so a sampled request fell back to classic decode. The DFlash2 draft is a function of the context alone, and for such a draft sampling each verify row with plain decode's sampler and accepting while the sample equals the draft is the speculative rule (accept with p(x), resample without x on rejection), so the output keeps plain sampling's distribution. `drafter::dflash::sampled_verify` samples the rows with the history plain decode would hold (prompt, first bonus, emitted tokens, accepted drafts), stops at the first mismatch, and feeds the unchanged walk. A drafter opts in with `Drafter::supports_sampled_verify` (Raon DFlash2 only); Mirostat declines to classic decode on the server and is refused offline. Penalties and a token bias go through the same path at temperature 0. Tests drive the real round loop with a Markov target: the joint distribution of two emitted tokens matches plain sampling at widths 2 and 4, and a presence penalty sees the accepted drafts (a mutation dropping that history fails it). On the checkpoint, sampled width 5 runs at 1.51x plain and the server serves a sampled request through the burst. Refs #3436
…on-dflash2-drafter # Conflicts: # CHANGELOG.md # docs/supported-models.md
The sampled verify rows call the stateless sampler once per row, so an adaptive-p request restarted its EMA on every row and left plain sampling's distribution. Only Mirostat was declined. The gate now uses needs_sampler_feedback_state, which covers both, in the round loop, the offline Raon path and the server burst. Sampled rows also returned log-probabilities from the raw verify logits, while plain decode reports them from the sampler-adjusted logits (penalties and token bias applied). sample_verify_rows now returns the adjusted rows and the round loop reports from them. Greedy runs without penalties keep the argmax walk and are unchanged. Validated with the sampled_verify, raon_dflash2, round_loop and raon1_mini speculative tests and narrow clippy on both crates. Refs #3436
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
Drafter math checked against the vendor |
The Raon-1 mini prefill captured every prompt row at the five tap layers (four mHC streams each, 51200 bf16 features per row) although the DFlash2 drafter keeps only the newest swa_window_size (2048) positions. At a 32K prompt that held about 3.3 GB of tap streams plus the same again once concatenated, for rows the drafter dropped before fc. The drafter now reports its window (Drafter::context_window), the target captures only that many of the newest prompt rows (Raon1MiniModel::limit_prefill_capture, wired through a no-op DFlashTargetModel hook on the server and directly in mlxcel generate), and the round loop hands the uncaptured row count to the drafter after reset (Drafter::skip_context), so the context lands at the same absolute RoPE positions as before. The drafter's state and drafts are unchanged; the target logits are untouched. Hardening from the same review: RaonDFlash2DraftModel::add_context returns a DraftFailed error on a feature width the drafter does not read instead of panicking, the draft checks the drafter is bound, the config rejects head and feature dimension products that do not fit an i32 tensor dimension (they wrapped in the shape check), and the sampled verify rows take the round's history by value instead of copying it a second time. Tests: a limited prefill keeps the newest rows byte for byte and the same logits; skipping the uncaptured rows drafts as the whole prompt does; a wrong feature width is an error; overflowing dimensions are rejected; the first context start counts the uncaptured rows. Greedy equality against plain decode re-run on the release checkpoint at width 5 for a short prompt and a prompt past 2048 tokens. Refs #3436
|
Security and performance review, fixes in ad9d715. No CRITICAL or HIGH findings. The drafter is loaded from an operator-supplied checkpoint and the draft width is a server flag, not a request field, so no request input reaches the drafter's shapes. Fixed:
Verification: greedy output with the drafter at width 5 matched plain decode exactly on the release checkpoint, for a short prompt and for a 3284-token prompt (past the window). Left open (LOW, not changed): sampled verify syncs to the host once per verify row, which the early stop needs. Each round copies the context window into a new buffer with concatenate (about 26 MB). The five full-length tap tensors still live until the first draft evaluates the trimmed concat, because MLX slices share the source buffer. |
After review, prefill captures the mHC streams only for the drafter's 2048-position window, and Mirostat and adaptive-p requests decline sampled verify (named error in generate, classic decode in the server). The supported-models Raon entry, the changelog line and the benchmark doc now say so, and the speculative drafter table gains a Raon DFlash2 row. Validation: make verify-env-var-docs verify-used-by, cargo fmt --check and cargo clippy --features metal,accelerate --lib --tests -D warnings pass. Existing tests already cover the new code (sampled_verify feedback decline, first_context_start, limited prefill capture, drafter window skip). Refs #3436
## Summary Closes the nine correctness and validation gaps the Raon-1 mini PRs (#3441, #3445, #3453, #3455) left open, in one change. - **1. presence_penalty (server only).** `GenerationConfigDefaults` reads `presence_penalty`; `resolve_generation_sampling_defaults` overlays it when `--presence-penalty` was not passed (new `presence_penalty_was_set`), logging the source. A request's own value still wins; `mlxcel generate` keeps 0.0. Negative or non-numeric values are ignored with a warning. The llama-server manifest entry moves to `by_design`, like `--top-p`. - **2. Input widths at load.** New `UnifiedLinear::check_input_width` and `SwitchLinear::check_input_width` (quantized planes through `validate_quantized_packing` with the loaded layout, dense ones by the last axis), called for every RDA, MLA, dense MLP, routed and shared expert projection and `lm_head`. Errors name `{prefix}.weight` and both widths. `KimiK3MLAAttention::check_input_widths` exists but Kimi K3 does not call it yet. - **3. Scales leading axes.** `check_scales_leading_axes` runs in `UnifiedLinear::from_weights_with_mode` and `SwitchLinear::from_stacked_parts` before reconciliation, for every quantized family. `validate_quantized_packing` and Raon's `check_scales_match_weight` delegate to it. - **4. KV estimate.** With `rda_config`, `total_bytes` adds `rda_layers * (H*D*D*4 + (K-1)*3*H*D*2)` per sequence (48.8 MB on Raon-1 mini); `marginal_bytes_per_token` is unchanged and the detail line names the state. - **5. Oracle digests.** `PINNED_CODE_DIGESTS` for revision `6691a076` (verified against the local files' HF etags), checked before the checkpoint code is imported; `--allow-unpinned-code` warns and writes `code_pin unpinned` into the header. - **6. RMSNorm double rounding.** `rms_norm_round_once` added and measured; Raon keeps `fast_rms_norm` (table below). - **7. Bounded gate.** `compute_g_lower_bounded` casts `a` to f32 before adding `dt_bias`. - **8. Steering on unsupported paths.** Startup fails, naming the path and the model, when a `reasoning_effort_steering` model is served pipeline-parallel (in-process, remote, or as a stage peer), as a disaggregated prefill or decode node, or on XLA. The guard is `src/server/reasoning_steering_startup_guard.rs`; its tests live next to it rather than in `startup_tests.rs`, because `start_server` cannot be unit-tested per path. - **9. Bounded echo.** The invalid-level error echoes at most 32 characters, Debug-escaped, plus `... (N bytes)`. ### Item 1: affected families under `models/` Only Raon checkpoints set `presence_penalty`: `raon-1-mini`, `raon-1-mini-mlx`, `raon-1-mini-nvfp4` (1.5) and `raon-1-nano` (1.5, not loadable yet, #3438). The other checkpoints under `models/` are unaffected. Side effect on DFlash2 serving: a nonzero presence penalty makes `needs_token_history()` true, and `sampling_config_eq` (`src/server/batch/speculative_burst.rs`) keeps such requests out of batched speculative windows. Concurrent Raon requests that name no penalty therefore draft as single-request bursts under the new 1.5 default (output unchanged); `--presence-penalty 0` or a per-request value restores batching. Lifting this needs per-row token history in the batched window, a separate follow-up. The docs note this next to the presence_penalty default. ### Item 6: measurement and decision Teacher-forced traces against the existing Transformers reference (bf16, CPU, `--effort max`), `compare_logit_traces.py --decided 1`. Arms differ only in Raon's decoder and final norms (input, post-attention, final); the MLA latent norms and the f32 RDA `o_norm` were left as they are. Decode is `mlxcel generate`, 256 tokens, temp 0, ABAB in one lock hold on M3 Ultra (load average 13.7 to 8.3, the sibling unit was building). | Arm | 4 x 256 decided disagree | 4 x 256 ppl delta | 871-token decided disagree | 871-token ppl delta | Decode tok/s (r1 / r2) | |---|---|---|---|---|---| | `fast_rms_norm` | 0 / 578 | +0.186% | 1 / 549 | +0.337% | 33.30 / 33.31 | | `rms_norm_round_once` | 0 / 578 | +0.225% | 0 / 549 | +0.607% | 32.26 / 32.26 | Decision: keep `fast_rms_norm`. Round-once removes the one decided disagreement (row 866, which #3441 traced to reference-side bf16 noise) but slows single-stream decode 3.1%, above the 2% bar, and raises perplexity delta on the long prompt. No family's norm changes in this PR. ### Item 7: CUDA and ROCm coverage No CUDA or ROCm host was reachable from this run (no local GPU tools, `spark-101` / `spark-102` do not resolve, no SSH keys). The fix and its test ran on Metal only, where the test passes before and after as designed. `make test-fast-cuda FILTER=gated_delta` and the Raon tiny-model suites on CUDA and ROCm remain to be run. ## Test plan - [x] New tests fail on main (pre-fix binary): `a_projection_with_the_wrong_input_width_fails_the_load_by_name`, `unified_linear_refuses_scales_with_fewer_rows_than_the_weight`, `stacked_switch_linear_refuses_scales_with_fewer_rows_than_the_weight`, `raon1_mini_counts_its_rda_state_once_per_sequence`, `an_oversized_level_is_echoed_truncated`, and the digest tests against main's oracle script. Items 1 and 8 add new API, so their tests do not compile on main. `bounded_gate_upcasts_a_bf16_input_before_adding_dt_bias` passes on Metal before and after. - [x] Targeted suites pass: raon, generation_config, kv_arch, reasoning_steering, gated_delta, switch_layers, server startup and cli_input, kimi_k3, core layers and rms_norm. - [x] All three Raon checkpoints and two other quantized families load and generate with the new checks. - [x] `make verify-llama-compat`, `make verify-python-tooling`, and `make verify` locally. - [ ] `make test-fast-cuda FILTER=gated_delta` and the Raon tiny-model suites on CUDA and ROCm (no host available). Closes #3457
Summary
Adds KRAFTON's DFlash2 speculator for Raon-1 mini (
KRAFTON/Raon-1-mini-dflash2) onmlxcel generateand the server, through the existing--draft-model/--model-draftflags (auto-detected as--draft-kind dflash).mlxcel-core::drafter::raon_dflash2): config with named errors (a mismatchedtarget_layer_idsor stream count fails at load; dimension products that overflow i32 are rejected), sanitize that refuses the vendor NVFP4 key format, the grouped block conv, the 2048-position context window, non-causal attention over grouped KV heads, and the candidate selector chain. It borrows the target's embedding and head. A feature-width mismatch at run time is aDraftFailederror, not a panic.models/raon1_mini_speculative.rs): captures the four mHC streams after layers 1, 6, 11, 16 and 21 ([n, 51200], layer then stream). The verify forward is byte-identical to decode: RDA conv and recurrence and MLA run per position, and the dense products (RDA projections, mHC selector, router, SiTU MLPs, head) go throughrow_invariant. The request's reasoning-effort alpha is carried in the burst caches, and rollback restores the recorded RDA state and trims the MLA cache. Gated bymtp_exactness_gate.Drafter::context_window,Drafter::skip_context,Raon1MiniModel::limit_prefill_capture, a no-opDFlashTargetModelhook for other targets), so a long prompt no longer materializes[L, 51200]features for every row. Context positions, drafts and target logits are unchanged.drafter::dflash::sampled_verify, opt-in per drafter throughDrafter::supports_sampled_verify). That is the speculative rule, so the output keeps plain sampling's distribution, and logprobs come from the sampler-adjusted logits as in plain decode. Samplers that carry feedback state (Mirostat, adaptive-p) fall back to classic decode on the server and are refused offline.MLXCEL_RAON_ROW_INVARIANT=1uses the row-invariant matvec kernel for every forward (faster drafting, but plain greedy text changes), so it stays off by default.Shared Raon files touched with small local edits:
raon_rda.rs(forward_recording,RdaStep),raon_mhc.rs,raon1_mini_moe.rs,raon1_mini.rs,raon1_mini_lm.rs. Merged with main after #3453 (NVFP4 exports); both sides' behavior is kept.Results (M3 Ultra)
Greedy drafted text equals plain decode at widths 3, 5 and 7 on three prompts, including a 3137-token prompt past the context window, and on the server at reasoning effort high and low. After the prefill-window change, width 5 was re-checked on a short prompt and a 3284-token prompt and is still identical. Width 5 runs at 1.30x to 1.76x plain decode and width 3 at 1.39x to 1.76x; sampled width 5 runs at 1.51x. Numbers are in
docs/benchmark_results/raon-dflash2-m3ultra-2026-11-26.md. Drafting is on whenever a drafter is passed, because the exactness gate passes and every width is faster than plain decode.Known limits: concurrent batches decode classically (no batched DFlash for this target); the drafter is not yet checked against the NVFP4 exports from #3453, where the exactness gate decides at startup.
Changes during review
add_contextpanic were fixed.Test plan
raon_dflash2unit tests: block-boundary conv, hand-computed 3-step selector chain, namedtarget_layer_idserror, sanitize, trained-block cap, feature-width error, dimension overflow, skipped context rowsraon1_mini::speculativetests: capture order, verify equal to decode steered and unsteered, probe at widths 3/5/7, rollback after a partial accept equal to a fresh decode, limited prefill capturesampled_verifytests: Markov joint distribution at widths 2 and 4; a presence penalty sees accepted drafts; feedback samplers never take the sampled rows; adjusted-logit logprobs--lib --tests, both crates), workspace fmt and clippy, env-var docs and Used-by checksCloses #3436