Skip to content

feat(perf): speed up Raon-1 mini decode, load and prompt reuse - #3461

Merged
inureyes merged 6 commits into
mainfrom
feature/issue-3458-raon-serving-perf
Nov 27, 2026
Merged

inureyes merged 6 commits into
mainfrom
feature/issue-3458-raon-serving-perf

Conversation

@inureyes

@inureyes inureyes commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

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 fix(models): close Raon-1 mini correctness and validation gaps #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 feat(models): add Raon-1 mini (raon1_mini) hybrid architecture #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

  • 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.
  • 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

Raon-1 mini served correctly but slowly in three places (#3458): the server never reused a prompt prefix, a decode step took 30 ms, and the ModelOpt NVFP4 export took over a minute to load.

- Prompt cache: the model donates and restores exact-prefix snapshots (RDA conv window, float32 state and offset; MLA latent pair). A state that does not hold exactly the keyed tokens donates nothing, so a DFlash2 burst, which runs on its own caches, stores no snapshot. The burst's prefill now follows the classic partition, which splits at snapshot boundaries, so drafted text still equals plain text.
- Decode: profiling put a third of the step in one product per mHC site. A one-row selector product ran MLX's transposed gemv kernel (about 255 us against 35 us row-major, at 50 sites per token), so one-row products (decode steps and verify rows) take the row-major form; multi-row products are unchanged. The small ops of a single-position site run as two compiled graphs, bit-identical to the eager ops. `MLXCEL_RAON_DECODE_FUSION` selects either or neither.
- ModelOpt NVFP4 load: a canonical triplet is reinterpreted on the device (E4M3 scale bytes passed through, packed weight viewed as uint32) instead of copied to host and re-encoded. Shared by every ModelOpt NVFP4 family that reads through MLX's safetensors loader.

Measured and not kept: fusing the seven RDA input projections (under 1 percent, not bit-identical at the real width), one host read per sampled verify block (slower, because the rows past the first mismatch are sampled for nothing), and a batched DFlash2 burst (an exact verify block costs more per row than a batched decode step). Numbers are in the benchmark document added next.

Refs #3458
Brings in the Raon-1 mini correctness follow-ups (#3459) and the Jamba XLA support (#3448). Both branches appended tests to `raon1_mini_tests.rs`; main's file is kept as is and this branch's snapshot test moves to `raon1_mini_snapshot_tests.rs`, next to the module it covers, which also keeps the file under the size limit.
Adds `docs/benchmark_results/raon-perf-m3ultra-2026-11-26.md` with the measurements behind #3458: decode by fast path, the selector product microbenchmark and its accuracy, prefill and decode traces against Transformers, TTFT with the prompt cache, DFlash2 on all three checkpoints, the ModelOpt load profile, and the three options that were measured and not kept.

The DFlash2 default verify width moves from 5 to 3. With an 18 ms decode step a verify block costs about 2.4 decode steps at width 5 and 1.9 at width 3, so width 5 fell to 0.97x plain decode on low-acceptance prose while width 3 stays at or above it on the original checkpoint and averages 1.18x against 1.11x over the nine prompt and checkpoint pairs measured. An explicit `--draft-block-size` is unaffected.

Refs #3458
@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) modeltype:text Text-only language model labels Nov 26, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Six Raon-1 mini serving performance follow-ups from #3458, each kept only if it measures faster and holds the correctness bar, with dropped items measured and recorded.

Findings Addressed

No CRITICAL or HIGH findings, so no fixes were pushed.

Remaining Items

  • nvfp4_device_transcode_matches_the_host_transcode_byte_for_byte also passes on main, because both inputs take the host transcode there. Nothing asserts that the u8 triplet actually takes the device route, so a change that silently disables it would keep the test green and bring back the 63 to 70 s load. (MEDIUM)
  • Regenerating the same request still misses (the warm-up entry supersedes the boundary entry), and a cold miss now costs 1.14 s against 1.00 s because the prefill splits at the history boundary and copies a 67 MB state. Both are disclosed. The cause is the shared scheduler policy, so this belongs in a follow-up issue. (MEDIUM)
  • Cold Raon chat requests on the server now split their prefill at the history boundary, so cold server text can differ from earlier builds and from mlxcel generate at a near tie. The benchmark doc mentions the split under miss cost, but the PR body's behavior-change list does not. (LOW)
  • MLXCEL_RAON_DECODE_FUSION=mhc, (trailing comma) turns on all instead of mhc. This matches the documented "any other value keeps all" rule, but it is the opposite of what the operator asked for. (LOW)

Verification

  • All stated requirements implemented (items 2a, 3 and 6 dropped with recorded measurements; their checkboxes stay unchecked)
  • No placeholder/mock code remaining (no fused-projection, B > 1 or one-read code in the tree)
  • Integrated into project code flow (mlxcel generate and mlxcel-server both reach the mHC paths, the transcode and the width default; snapshots are reached through the scheduler)
  • Project conventions followed
  • Existing modules reused where applicable (kv_snapshot, recurrent_snapshot, PrefillPlan, prefill_burst)
  • No unintended structural changes
  • Tests pass (52 targeted tests locally on Metal: snapshot, mHC, scheduler cache, sanitize, speculative, CLI width)

@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

Scope: snapshot isolation and memory, the new mHC bridge functions, the NVFP4 device transcode, and regressions outside the targeted paths. The implementation review already covered correctness. No CRITICAL or HIGH findings, so nothing was pushed.

Checked and fine

  • Isolation. The snapshot key carries model_id, the LoRA id and a template_sig that every chat front-end (chat, responses, responses compact/run, anthropic) builds through chat_template_signature, which folds the resolved effort. Raw completions use the sentinel bucket and run at the model default. A restore copies every tensor through ffi::copy into a fresh cache whose in-place marker is unset, so a later sequence writes through slice_update and never into the stored buffer. A DFlash burst declines an adopted prefix and never donates, because its state offsets do not match the key.
  • Memory. Each entry is sized by ModelStateSnapshot::nbytes at insert and held to snapshot_capacity_bytes by the existing LRU, so many distinct prompts evict older entries instead of growing memory.
  • NVFP4 device path (sanitize.rs:1270). It runs only for an exactly 2-D uint8 weight with packed_dim % 8 == 0, a uint8 scale plane of shape [out, packed/8] and a one-element weight_scale_2. That is at least as strict as the host path, and anything else falls back to it. view to uint32 runs after contiguous, and MLX's View copies when the offset is not word-aligned. There is no host-side indexing, so no out-of-bounds read. The eval_all call has a SAFETY note.
  • Non-Raon models gain no per-token work: the new bridge functions and the selector form are called from Raon modules only. The load profiling adds only timers.

MEDIUM

  • Cold-miss TTFT for Raon goes from 1.00 s to 1.14 s (+14%), from the boundary-split prefill plus the state copy, and the second identical request still misses because the warm-up supersedes the boundary entry. This is a documented trade-off. A follow-up could skip the split when no boundary entry can be reused.

LOW

  • raon_mhc_decode.rs:116-128: DecodeFusion::parse falls back to ALL on any unknown token (of, selector,bogus) and logs nothing. An operator who sets the variable to get the earlier bytes back would silently get the new ones. Suggest a tracing::warn! that names the token.
  • raon1_mini_snapshot.rs:70 and :113: unlike restore_standard, the RDA restore checks neither the conv/ssm shapes nor the layer count. A layer with no stored tensors comes back empty, with offset = token_len. Today the store is per model, so only a snapshot from another Raon model under the same id would reach this. A shape and presence check would make a restore fail cold instead of decoding from an empty state.
  • mlx_cxx_bridge.cpp:8145,8160: the compile is fixed-shape, so there is one trace per batch width and dtype. That is bounded by the maximum batch size, and the shapeless audit does not cover it. Like the sibling bridge functions, these return no Result, so an MLX throw aborts the process. The inputs are model-internal, so no request can trigger it.
  • raon_mhc.rs:191-229: the row-major selector copy is about 17 MB for Raon-1 mini, and it is built even when the selector path is turned off. This is negligible.

Focused tests rerun locally under the GPU lock: raon_mhc (9), the Raon snapshot round trip, the scheduler effort-isolation test and both NVFP4 device-transcode tests, 12 of 12 pass.

…e checks

The device NVFP4 transcode test also passed when the route was silently off, so a regression to the 63 to 70 s host path went unnoticed. nvfp4_device_transcode is now visible to the tests, which assert Some for a canonical uint8 scale triplet and None for f16 scales.

DecodeFusion::parse now logs one warning naming an unrecognized MLXCEL_RAON_DECODE_FUSION value before falling back to all fast paths; the fallback is stated in docs/environment-variables.md and the parse test covers malformed values.

The Raon-1 mini RDA restore checks the conv and recurrent state ranks, batch agreement and offset, and a snapshot that lacks an RDA or MLA layer is refused, so the scheduler prefills cold. The benchmark doc states the presence_penalty setting of each measurement and its effect on batched DFlash2 windows, and the doc, supported-models page and CHANGELOG disclose the cold-prefill split at the history boundary.

Validation: cargo test --lib for the touched tests and the raon filters (52 passed), cargo fmt --check, cargo clippy --lib --tests -D warnings, scripts/ci/check_env_var_docs.py.

Refs #3458
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata modeltype:text Text-only language model priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Raon-1 mini serving performance follow-ups

1 participant