Repository navigation
feat(models): add Raon-1 mini (raon1_mini) hybrid architecture - #3441
Merged
Merged
Conversation
KRAFTON/Raon-1-mini (revision 6691a076) runs from its original bf16 + MXFP8 checkpoint. The port follows the checkpoint's Transformers code at every rounding point: four-stream Raon_mHC residuals on the Helmert chart (raon_mhc.rs), RDA gated-delta layers with f32 short convs, the write ratio and the lower-bounded decay (raon_rda.rs), the gated NoPE MLA shared with Kimi K3 through a new NopeMlaSpec, SiTU MLPs, and a sigmoid-routed MoE whose MXFP8 experts are reinterpreted as MLX's native mxfp8 layout without changing a byte. The reasoning-effort steering vectors are loaded in f32 and not applied (alpha 0, the reference at max effort; #3435). The vendor MLX export and other quantized exports are refused at load by name (#3437). Prefill runs in one pass and batched decode is per row, as for the other recurrent hybrids. scripts/raon1_mini_oracle_trace.py runs the checkpoint's own modeling code for greedy and teacher-forced comparison. Unit tests cover the Helmert basis, doubly stochastic residuals, aggregate and mix, the layer partition, SiTU, the RDA ratio and decay, NoPE MLA order invariance, sanitize, MXFP8 against dequantize-then-matmul, and prefill against chunked prefill and decode with a left-padded row. Refs #3225
The standard Metal gated-delta kernel casts the float32 decay `g` and the incoming state to the activation dtype and stores the outgoing state in it. In bf16 a decay just below 1 has a step of 2^-8 (0.998 becomes 0.996), so long-memory RDA heads drift once per token. The checkpoint's reference keeps the log decay and the recurrent state in fp32. With bit-identical bf16 q, k, v and beta at layer 0, the core output was 0.045 relative error against an fp32 reference forward, against 0.0022 for the reference's own bf16 forward. RDA now calls the existing precise kernel path through a new `gated_delta_ops_precise` (no casts, f32 state). Other gated-delta families are unchanged. On the 871-token chat prompt plus continuation, the teacher-forced trace against Transformers goes from p99/max logit delta 1.125/10.25 to 0.75/2.0 and perplexity from +0.475% to +0.337%. The 4x256 corpus stays at 0 of 578 decided disagreements. A new unit test checks that a 0.998 decay survives 64 steps with a float32 state; it fails on the standard kernel. Refs #3225
The KV estimator did not know raon1_mini: its config has kv_lora_rank, so it fell to the DeepSeek V2 decompressed branch and sized all 25 layers at 40 heads x 320 elements per token, about 80 times the real cache (7 MLA layers x 576 latent elements). Server context sizing and prompt-cache snapshot budgets read that estimate. - raon1_mini joins MLA_LATENT_CACHE_FAMILIES (not QUANTIZED_LATENT_FAMILIES, so an int8 request resolves to fp16 until an int8 latent trace is run), and kv_arch counts the MLA layers from rda_config.rda_layers as it does from Kimi's kda_layers. - RDA decay with a null gate_lower_bound now follows the reference, exp(-softplus(exp(A_log) * (a + dt_bias))). It went through compute_g, which puts exp(A_log) outside the softplus. Both published Raon-1 configs set -5.0, so their output is unchanged; the reusable block was wrong for a null bound. Tests: a 25-layer Raon config sizes 7 x (512 + 64) per token; the decay test checks the null-bound form by hand. Raon, latent-family and mlxcel-core MLA tests and clippy pass. Refs #3225
`presence_penalty=None` does not turn the penalty off: `Raon1MiniForCausalLM.generate` only overrides the generation config when the argument is not None, so the loaded `generation_config.json` value of 1.5 stayed and `_get_logits_processor` applied it to every greedy step. The oracle therefore was not plain greedy.
That explains the one flip on the 871-token prompt ("Linux and Windows" against mlxcel's "Linux/Windows"): `/` had already been generated in "Linux/CUDA", the penalty took 1.5 off it, and its 1.125 lead over " and" went away. Passing 0.0 skips the processor. Rerun on the same prompt, the reference now emits the same 43 tokens as mlxcel, ending in "Linux/Windows as secondary targets.<|im_end|>".
Refs #3225
Member
Author
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
|
config.json and the checkpoint are untrusted input, and several Raon-1 mini load paths turned a malformed value into a panic or a process abort instead of a named load error. - validate_layer_partition sized a bitmap from num_hidden_layers, so a count of usize::MAX overflowed and a large one allocated from the config alone. It now uses a set sized by the listed entries and scans at most listed + 1 layers. - Raon1MiniConfig::validate now refuses zero widths (an RDA head_dim of 0 made the query scale inf), raon_mhc_streams above 64, and any dimension or shape product that does not fit MLX's i32, which `as i32` casts would otherwise truncate into a match with a crafted tensor. - stack_mxfp8_experts checks every expert against expert 0 before stacking: MLX stack throws on mismatched shapes, and a throw across the cxx bridge aborts. - RaonMhc::from_weights returns an error for fewer than 2 streams instead of underflowing (n - 1). New unit tests cover each case; cargo test --lib raon and clippy -D warnings pass. Refs #3225
Raon-1 mini declared BatchedDecodeKind::PerRowFallback, so the server ran one full forward per active sequence every step and read every weight (the experts, the 260K-row head) once per row. Aggregate decode stayed flat as concurrency grew: about 30 tok/s at 1, 2 and 4 concurrent requests on M3 Ultra. Batched decode is now native, following Kimi Linear and Kimi K3. The RDA conv and recurrent states of the rows are stacked into one [B, ...] state for the step and split back, and the MLA layers go through KimiK3MLAAttention::forward_batched_decode against each row's own latent cache, so rows of different lengths share the step. A multi-token step, a mask, or rows whose recurrent state is not uniform (a fresh row next to a started one) still run one row at a time. The decoder layer's two mHC sites and FFN are shared between both paths through forward_with_mixer. The model-owned batched decode harness (multistep, paged lengths, fresh and mixed rows, B=1 transitions) passes against per-sequence decode at 1e-5. On models/raon-1-mini (M3 Ultra, release server, 128 tokens per request) aggregate decode goes from 29.8 / 30.7 / 29.8 tok/s at 1 / 2 / 4 concurrent requests to 29.9 / 75.0 / 127.0 tok/s. Greedy output of four prompts run concurrently matched the solo runs for two prompts and diverged late (after about 280 characters) for the other two, the usual bf16 batch-shape effect of batched matmuls. Refs #3225
Member
Author
Security and performance reviewFixed on this branch:
Checked, no change needed:
Remaining (not fixed here):
|
…sals The MoE router had no direct test: a new hand computation checks that selection uses sigmoid scores plus e_score_correction_bias (the bias lifts a third expert over the unbiased runner-up) while the weights come from the unbiased scores, renormalized with 1e-20 and scaled by routed_scaling_factor, and that both are float32. Detection of model_type raon1_mini is now tested, including a vendor MLX export config, which must still reach Raon1MiniConfig so it is refused by name. The config refusal cases now cover all four vendor export keys and the MLX `quantization` block. Validation: cargo test --profile test-fast --features metal,accelerate --lib raon (20 passed); clippy --lib --tests with -D warnings and cargo fmt --check are clean. Refs #3225
docs/supported-models.md told users to pass `--reasoning off`, which only the server binaries accept. It now says the template gates thinking only on enable_thinking, that `mlxcel generate` always renders the template default (thinking on), and that `mlxcel serve` and `mlxcel-server` take a per-request chat_template_kwargs.enable_thinking, a --chat-template-kwargs default, or --reasoning off. The CHANGELOG entry now records the float32 RDA decay and state, the latent KV sized for the seven MLA layers only, native batched decode, and the server thinking switch. Validation: make verify-versions verify-used-by verify-env-var-docs verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat and scripts/ci/check_cross_repo_refs.py pass. Refs #3225
inureyes
marked this pull request as ready for review
November 26, 2026 07:50
5 of 6 tasks
This was referenced Nov 26, 2026
inureyes
added a commit
that referenced
this pull request
Nov 26, 2026
## 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
2 of 3 tasks
inureyes
added a commit
that referenced
this pull request
Nov 27, 2026
## Summary Six Raon-1 mini performance follow-ups, measured on an M3 Ultra against `main` at `477564e2e` (`docs/benchmark_results/raon-perf-m3ultra-2026-11-26.md`). Three are kept, one is a validation, two were measured and not kept. - **1. Prompt cache, kept.** Raon donates and restores exact-prefix snapshots (RDA conv window, f32 state and offset; MLA latent pair). TTFT of a repeated 2132-token chat turn: 1.00 s to 0.04 s; follow-up turns 1.04 s to 0.08 to 0.17 s; replies identical. A restore refuses another family, a snapshot that lacks a layer, and RDA state whose rank, batch or offset does not match, so the request prefills cold instead. A DFlash2 burst stores no snapshot, and its prefill now follows the classic split so drafted text still equals plain text. - **2. Decode, kept in part.** 33.5 to 54.2 tok/s (target 38). Profiling found the step bound by one product, not by dispatch count: a one-row mHC selector product ran MLX's transposed gemv kernel (255 us against 35 us row-major, 50 sites per token). One-row products now take the row-major form (51.5 tok/s alone); compiled mHC site graphs add the rest and are bit-identical. Fused RDA projections were dropped: +0.6 to +0.8%, and not bit-identical at the real width. - **3. Batched DFlash2, not enabled.** A probe measured an exact verify block at 42 to 59% more for two rows than for one, against 9% for a batched decode step. The ceiling on batched drafting is 13 to 22% below classic batched decode at four rows and within a few percent of it at two, before the draft cost and the uniform accept. `supports_batched` stays `false` and no B > 1 code was added. Since #3459 the served default `presence_penalty` of 1.5 also keeps default-setting requests out of batched speculative windows. - **4. DFlash2 on the NVFP4 exports, validated.** The gate allows widths 3, 5 and 7 on both exports and drafted text equals plain text in 36 of 36 runs. - **5. ModelOpt NVFP4 load, kept.** 63 to 70 s to 2.2 s; resident memory and decode unchanged. The base profile was 50 s of host weight copy, 10 s of scale decode and 3 s of re-encode; canonical triplets are now reinterpreted on the device, and a loader that already decoded the scales keeps the host path. - **6. One host read per sampled verify block, not kept.** It was slower (49.5 against 48.7 ms per verify round): the rows past the first mismatch are sampled for nothing. The per-row loop is unchanged, so seeded sampled drafted runs keep their behavior. ## Behavior changes to review - Plain greedy text can differ from earlier builds at a near tie, because a decode step's selector product sums in another order. It did on both NVFP4 exports and not on the original for the essay prompt. `MLXCEL_RAON_DECODE_FUSION=mhc` keeps the earlier bytes at 34.5 tok/s; an unrecognized value logs a warning and keeps all fast paths. - Cold Raon chat on the server now splits its prefill at the history boundary, so cold server text can differ from earlier builds and from `mlxcel generate` at a near tie. A cache miss costs 1.14 s against 1.00 s. - The second identical request still misses: the scheduler's warm-up supersedes the boundary entry, as for every snapshot family. The third request hits. - The DFlash2 default width moves from 5 to 3, which the issue did not ask for. With the faster decode step width 5 fell to 0.97x plain decode on prose; width 3 averages 1.18x over nine prompt and checkpoint pairs against 1.11x. ## Correctness - Transformers trace on the #3441 4 x 256 corpus: 0 of 578 decided positions differ on the prefill path and on the decode path. - Greedy drafted text equals plain text in 54 of 54 CLI runs across the three checkpoints and in the server check (36 texts: plain cold, cache hit and drafted). NVFP4 planes are byte-identical to the host transcode, except that scale byte `0xFF` (a NaN) is no longer rewritten to `0x7F`. - A snapshot is never reused across reasoning efforts (scheduler test). ## Test plan - [x] New tests cover snapshot round trip and refusal, the scheduler cache hit and effort miss, compiled against eager mHC, the NVFP4 gate and planned burst prefill, and the device transcode route. - [x] `make verify` locally after merging `main` at `d43915faf`; the issue's `test-fast` filters, fmt and clippy again after merging `main` at `db3a23141`. - [ ] CUDA and ROCm were not run. Closes #3458
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the KRAFTON Raon-1 mini architecture (
raon1_mini,KRAFTON/Raon-1-miniat6691a076), run from the original bf16 + MXFP8 checkpoint inmlxcel generate,mlxcel-serverandmlxcel arch. Rounding followsmodeling_raon1_mini.pywherever the issue body and the reference disagree.raon_mhc.rs): route, aggregate, mix and the stream-mean final norm each rounded where the reference rounds.raon_rda.rs): f32 short convs, L2 norm at eps 1e-6, write ratio, bf16 beta, lower-bounded decay (and the reference form when the bound is null), f32 head norm with a sigmoid gate. The recurrence runs through a newgated_delta_ops_precise, which keeps the decay and recurrent state in f32; the standard Metal kernel rounds both to bf16, which compounded over long prompts (a 0.998 decay becomes 0.996). Other families keep the standard kernel.NopeMlaSpec(KimiK3MLAAttention::from_spec); Kimi K3 behavior is unchanged. Only the seven MLA layers hold KV, as a latent pair, andkv_arch/ the MLA latent-family list size it that way (the generic path overestimated it about 80x). An int8 latent request resolves to fp16 until an int8 trace is run.mxfp8layout; the routed sum is rounded before the shared expert is added. Steering vectors are loaded in f32 and not applied (alpha 0; feat(models): support the Raon-1-mini release with reasoning-effort steering #3435).scripts/raon1_mini_oracle_trace.pyis the Transformers reference arm (generateandtracemodes, presence penalty forced to 0).Validation (M3 Ultra)
mlxcel archlists Raon-1 mini. The issue'sgeneratecommand answers42; with the template'senable_thinking=falserendering through--no-chat-templateit emits42<|im_end|>, the same ids as the reference.set_reasoning_effort("max")): identical on the short prompt and on the 871-token prompt (43 tokens). An earlier flip came from the oracle leavinggeneration_config.json's presence penalty 1.5 active; fixed in the script.compare_logit_traces.py --decided 1): 4 x 256 tokens, 0 of 578 decided positions disagree, perplexity +0.19%. Long prompt plus continuation: p99 / max logit delta 0.75 / 2.0, perplexity +0.34%, and 1 of 549 decided positions disagrees (row 866, the token after<|im_start|>assistant). That row is reference-side bf16 noise: the reference flips its own top-1 there when run in f32 (f32 picks\nlike mlxcel, gap 0.48), and its bf16 variants (prompt-only, cached prefill, longer context) all agree with each other. Treated as exempt from the zero-disagreement criterion.mlxcel-serverstreaming: thinking on puts the reasoning inreasoning_contentand42incontent;chat_template_kwargs.enable_thinking=falsegives42with no reasoning.verify-*contract targets and the full localmake verifygate pass.Known gaps (follow-up)
presence_penaltyfromgeneration_config.jsonis not read yet; the default stays 0.0 for all families.Tensor parallel, DFlash2 (#3436), NVFP4 (#3437) and nano (#3438) are out of scope.
Closes #3225