Skip to content

feat(models): support Ricursive Ripple-65B (ricursive) - #3729

Open
Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:feat/3224-ripple-ricursive
Open

Jaeyeong-CHOI wants to merge 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:feat/3224-ripple-ricursive

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

Closes #3224.

Adds Ricursive Ripple-65B-Preview (model_type: ricursive, RicursiveForCausalLM) for text generation and serving. The decoder follows mlx-vlm's ricursive port (Neywa-Labs/mlx-vlm#2697) step for step, including where it rounds. On GB10 the frogggias/Ripple-65B-Preview-MLX-4bit checkpoint writes the acceptance function, its greedy output matches mlx_vlm.generate token for token on a 16- and a 17-token prompt and on a 1,708-token prompt up to one word of its reasoning in some runs (below), and mlxcel-server streams chat with the checkpoint's template. Teacher-forced logit traces against mlx-vlm on the 8-bit checkpoint have zero disagreements at decided positions, including a 1,536-token prefill that crosses the 1,024-token window. The family keeps its checkpoint dtype at load, as mlx-vlm runs it.

What changed

Ripple model (src/models/ricursive.rs)

  • ModelArgs defaults to the published config and validate() runs at load: layer_types must have one entry per layer and only full_attention / sliding_attention; hidden_act must be silu; num_attention_heads must be a positive multiple of num_key_value_heads; head_dim must be positive and even (rotate-half); sliding_window, when set, goes through the shared validate_sliding_window; ffn_clamp_threshold must be finite and non-negative; embed_scale finite. Every error starts with Ricursive:. Without layer_types, layer i is full on i % 5 == 4, as upstream.
  • Embedding: h0 = (embed(ids).f32 * embed_scale).astype(dtype) after the (quantized) lookup; a null embed_scale leaves the lookup alone (folded tables). h0 is the value residual, taken before the first norm.
  • Block: a = attn(input_layernorm(x), h0), x += post_attention_layernorm(a), x += post_feedforward_layernorm(mlp(pre_feedforward_layernorm(x))), then norm and lm_head (or the tied embedding).
  • Values: v = v_proj(lerp(h0, x_normed, sigmoid(value_res_lambda))), computed like upstream _interpolate_values: the blend is the FP32 sigmoid rounded to the activation dtype, the lerp runs in FP32 with torch.lerp's two branches (seed + b * delta for b < 0.5, end + (b - 1) * delta otherwise) and is rounded once. use_valres: false uses x_normed.
  • RoPE on sliding layers only, full layers are NoPE. It keeps upstream's _apply_rotary order: inv_freq = 1 / f32(base ** (i / d)), cos and sin of the FP32 angles rounded to the activation dtype, the rotate-half rotation in FP32, one rounding. The angles are built once per forward from the cache offset (per row in batched decode) and shared by every sliding layer.
  • Output gate out * sigmoid(g_proj(x_normed)), with the gate cast to FP32 first when gate_full_precision; MLP down(silu_f32(min(gate, t)) * clip(up, -t, t)) with the SiLU computed in FP32 and rounded once; no clamp for a null or zero threshold (upstream's if threshold:).
  • Caches: sliding layers a RotatingKVCache(sliding_window), full layers a growing KVCache; a null sliding_window makes every layer grow (the sliding layers still rotate). Per-sequence state is scheduler-owned (ADR 0010), like EXAONE 4: forward_layer_state, native batched decode (attend_batched_rows), last_row_logits, padded-prefill trim and prompt-cache snapshots (standard / rotating segment names). Prefill masks come from prefill_causal_mask / prefill_sliding_window_mask, so a single-row prefill keeps MLX's causal mode or native window route. Every layer stores FP16 KV; the wrapper reports that through kv_cache_storage_modes (table_less_storage_modes).
  • Weights: the HF names, or the same names under language_model. (mlx-vlm conversions), read in place without rewriting the map. A tied config ignores lm_head.weight. value_res_lambda must be an unquantized float32 or bfloat16 tensor with one value; a missing one while use_valres is true, a .scales sidecar, another dtype or another size is a load error naming the key.
  • The ModelOpt NVFP4 export is refused by name in RicursiveModel::load (through is_modelopt_nvfp4_text_checkpoint) before any weight is read; it was not downloaded or validated.
  • Per-module quantization overrides are refused by name in ModelArgs::validate, so both the directory loader and the weight-map route check them before any weight is read. araysuter/Ripple-65B-Preview-MLX-mixed-2bit lists 642 per-module entries (240 at 2 bits / group 32, 82 at 8 bits / group 64, the rest repeating the 4-bit / group 64 default); this loader reads every module with the default pair, so it would mis-read those planes. An entry that repeats the default loads; an entry with another bits, group_size or mode, or a false switch, fails with Ricursive: per-module quantization overrides are not supported (<path>: <entry> against the default bits B, group_size G); use a uniformly quantized MLX conversion such as frogggias/Ripple-65B-Preview-MLX-4bit.
  • eos_token_id comes from the config ([100265, 100257] on the published checkpoints).

Shared code touched, and its other callers

  • Load-time dtype (sanitize.rs): bf16_to_f16_at_load returns false for model_type: ricursive (new is_ricursive_config), next to the Limite, Talkie and Inkling exceptions. Without it, every arm that casts bf16 to f16 broke the load: Apple Silicon for an unquantized checkpoint (the BF16 ricursiveAI/Ripple-65B-Preview), pre-Ampere CUDA for every checkpoint, and MLXCEL_CUDA_F16_NORMALIZE=1 for an unquantized one on Ampere and later. The published value_res_lambda tensors are BF16 [1] in both the BF16 release and the MLX conversions, the cast made them f16, and the loader then refused the first layer (value_res_lambda must be float32 or bfloat16). mlx-vlm runs the family in bf16, and every parity figure below is from bf16 runs. The predicate matches only ricursive, so the other callers of bf16_to_f16_at_load (load_text_weights, the Gemma 4 selective loader, loading::vlm::finish_vlm_weights_common, the embedding loader, Kimi K3, the GLM-4 MoE Lite MTP drafter and the dense-vision loaders) keep their behavior for every other family. The selective loader's per-tensor Apple Silicon conversion (tensor_view_to_array, which has no config) is not on Ricursive's load path; pipeline-parallel partial loading, which uses it, is not wired for this family.
  • deepseek_v4_moe.rs: the clamp of limited_swiglu moved into a private clamp_swiglu_inputs, and limited_swiglu_f32_silu sits next to it with the FP32 SiLU. limited_swiglu computes exactly what it did. Its callers are LimitedSwitchGlu::forward and LimitedMlp::forward in the same file, DeepSeek-V4.1's MoE (deepseek_v41_moe.rs) and two DeepSeek-V4 tests; deepseek_v4_tests::limited_swiglu_clamps_match_reference, limited_switch_glu_shares_gather_indices_and_is_bit_identical_to_per_call_form and the DeepSeek-V4.1 tests pass in the gate. Both functions carry a Used by: line; limited_swiglu's names both DeepSeek families.
  • Used by: rosters gained Ricursive where it calls the helper: prefill_causal_mask and prefill_sliding_window_mask (utils.rs), RotatingKVCache (cache.rs), attend_batched_rows (cache/attend.rs), is_modelopt_nvfp4_text_checkpoint (sanitize.rs) and four model_owned.rs helpers. No behavior changes in these.

Wiring: ModelType::Ricursive (CLI family "Specialized"), detection ("ricursive"), registry name and model_type_keys, metadata registration (ConfigBacked, LoadedModel::Ricursive), the memory-estimate and tensor-parallel fallback tables (tensor parallel stays unsupported: the TP runtime has no Ricursive arm, so its existing refusal, which names the model type, applies; not exercised), the native batched-decode roster, a detection test, docs/supported-models.md and CHANGELOG.md (## [Unreleased] / ### Added; the section did not exist after the v0.9.0 release commit, so this adds it). The KV estimator needs no change: it already sizes layer_types sliding layers at sliding_window.

Where this differs from the issue text

  • The norms are the shared RMSNorm. The issue says fast_rms_norm with a weight multiplies before rounding. MLX's fused kernels round first: xn = wn * static_cast<T>(x * normalizer) in mlx/backend/cuda/rms_norm.cu:123 and out = w * static_cast<T>(x * inv) in mlx/backend/metal/kernels/rms_norm.metal:70 at the pinned MLX, which is upstream's normalized.astype(x.dtype) * weight. layers.rs already documents this beside rms_norm_round_once, the single-rounding form. rms_norm_rounds_before_applying_the_weight pins the block norm to the explicit FP32-normalize, round, then scale sequence bit for bit on a bf16 row, and shows rms_norm_round_once gives different bits on the same row. An earlier draft of this branch composed the norm as fast_rms_norm_no_weight times the weight; on GB10 it gave the same bits as the fused kernel on that row.
  • RoPE and SwiGLU keep the upstream rounding order, so there is no second arm to compare.
  • No limited_swiglu reuse for the activation itself: Ripple calls the FP32-SiLU variant, which shares the clamp. limited_swiglu (bf16 SiLU) is unchanged for DeepSeek-V4.
  • KV cache modes are not wired. Every layer stores FP16, which kv_cache_storage_modes reports and mlxcel arch --json lists (kv_modes: ["fp16"]). The family is not in the turbo-KV list. Requesting another mode was not exercised.
  • Reference setup. The published MLX conversions carry "model_file": "ricursive.py" (a remote-code file for mlx_lm --trust-remote-code). mlx-vlm then loads that file instead of its own ricursive module and fails (module 'custom_model' has no attribute 'ModelConfig'). The reference runs used a directory that links the same weight and tokenizer files and drops only that key from config.json. mlxcel ignores the key and loads the published directory unchanged.

Verification

GB10 (CUDA 13, sm_121), 121 GB unified memory. This commit sits on 9402cf893; the build, tests, gate and the runs marked "this commit" used exactly its tree. Rows not marked that way come from the previous revision of this branch on 517ede2d7, whose model code is the same apart from the dtype policy and the override check, neither of which these quantized checkpoints reach on Ampere and later. Throughput was measured while other jobs shared the host.

Before the change (base binaries)

  • mlxcel arch lists no ricursive entry.
  • mlxcel generate -m Ripple-65B-Preview-MLX-4bit -p Hello -n 8 --temp 0 exits with Error: Unsupported model type: ricursive.

Load-time dtype, through the CLI (this commit, and the same tree with the pre-fix ricursive.rs and sanitize.rs)

  • A 5-layer random BF16 Ricursive checkpoint (hidden 64, the published config otherwise, the 4-bit checkpoint's tokenizer) with MLXCEL_CUDA_F16_NORMALIZE=1: before the fix mlxcel generate -p "What is 17 * 23?" -n 16 --temp 0 prints Converting 78 bf16 weight tensors to f16 for CUDA f16 normalization (MLXCEL_CUDA_F16_NORMALIZE). and exits with Error: Ricursive: model.layers.0.self_attn.value_res_lambda must be float32 or bfloat16 (dtype 9); with the fix it loads without converting and its 16 greedy token ids equal the run without the variable (both binaries agree on that run).
  • On the 4-bit checkpoint MLXCEL_CUDA_F16_NORMALIZE=1 does not reproduce the failure on this GPU, before or after the fix: Ampere and later never convert a quantized checkpoint, so both binaries load it and print the same 8 tokens for "What is 17 * 23?" as the default path and mlx-vlm. The pre-Ampere arm (which converts quantized checkpoints too) and the Apple Silicon arm were not run; the fix is an early return in bf16_to_f16_at_load ahead of all three arms, and the run above goes through that same function.

Tests

  • src/models/ricursive_tests.rs (21 tests), a detection test and a load-policy test in sanitize.rs. The tiny model (3 layers, sliding/full/sliding, window 4, use_valres, clamp 0.2, embed_scale 2, every weight nonzero and every norm weight away from 1) is checked against a host-side f32 replay of the reference forward written out in the test (embedding scale, h0 before the first norm, per-head norms, RoPE on sliding layers only, the window, the gate, the clamp, the four norms):
    • one 11-token prefill matches the replay (max error 1e-4), with a null window too; a check that the replay itself moves when every layer rotates or when the value residual is removed
    • one prefill equals a 3/5/3-token chunked prefill and a 3-token prefill plus single-token decode, row by row, across the window; the sliding layers hold a ring of 4 and the full layer grows
    • the value-residual lerp against a hand computation for blends 0.25, 0.75 and 0.5, the endpoints at lambda ±60, and bf16 rounding of the blend and the result
    • the norm rounds before applying the weight (above)
    • the rotary matches MLX's non-traditional fast_rope in f32 at offset 7, and per-row offsets equal the single-row result
    • clipped SwiGLU at and past the threshold, unclamped for a null or zero threshold, and the FP32 SiLU rounded once in bf16
    • embed_scale: null over a table folded by the scale equals the scaled model bit for bit, and differs over the unfolded table
    • config and weight errors (layer count, layer type, activation, head ratio, zero KV heads, window 0, negative clamp, odd head_dim, zero layers, missing / quantized / float16 / two-value value_res_lambda), the language_model. prefix, a tied head, and the ModelOpt NVFP4 refusal
    • the attention window each layer passes to the mask-less prefill and decode kernels: the sliding window on sliding layers, 0 on the full layer, 1 at sliding_window: 1, 0 everywhere for a null window
    • per-module quantization overrides: a default-only block and entries repeating the default validate; a 2-bit / group 32 entry, an 8-bit embedding, an mxfp4 mode and a false switch are each refused with an error naming the path
    • load-time dtype: ricursive_configs_keep_checkpoint_dtype (in sanitize.rs) asserts bf16_to_f16_at_load is false for Ricursive configs, quantized and not, with MLXCEL_CUDA_F16_NORMALIZE=1 set under the crate's env lock so the CUDA arm is exercised on Ampere and later; bf16_checkpoint_loads_in_bf16_under_the_f16_opt_in writes the tiny model as a BF16 safetensors checkpoint, loads it through RicursiveModel::load with the same opt-in, checks every value_res_lambda is still bf16, and compares the logits with the same weights built in memory as bf16 (equal)
    • last_row_case! and the shared native-batch contract (mixed_cache_batched_decode_tests::contracts: scheduler-owned layout, isolation of interleaved sequences, malformed batches refused before any cache is touched)
  • Fail before, pass after. With the new tests on top of the pre-fix ricursive.rs and sanitize.rs (everything else as in this commit), bf16_checkpoint_loads_in_bf16_under_the_f16_opt_in fails with Ricursive: model.layers.0.self_attn.value_res_lambda must be float32 or bfloat16 (dtype 9) (9 is float16) and per_module_quantization_overrides_are_refused_by_name fails because the 2-bit entry validates. With only the new sanitize.rs arm removed, ricursive_configs_keep_checkpoint_dtype fails as well. All pass on this commit.
  • Mutations, run against the ricursive tests: taking h0 after layer 0's input_layernorm fails 4 tests (the replay among them); rotating the full layers fails 3; a bf16 SiLU fails clipped_swiglu_rounds_the_fp32_silu_once; ignoring embed_scale fails 4 (these four on the previous revision of this branch, whose model code is unchanged here). Widening the attention window by one key fails attention_window_is_the_sliding_window_on_sliding_layers_only on this commit (22 of 23 matching tests still pass: the tiny model's prefill takes the masked route and its decode cache already holds only the window, so no forward test reads the value; the 1,536-token trace and the 1,708-token greedy run below go through the mask-less route). Collapsing the two torch.lerp branches into one still passes every test (the branches differ only in FP32 rounding before the bf16 rounding).
  • make verify-test-cuda on this commit: 18,914 passed, 2 failed, 578 ignored across 207 test binaries. The failures are mlx_test_guard_coverage::mlx_evaluating_lib_tests_take_mlx_test_guard (src/vision/encoders/nemotron_h_nano_omni_tests.rs:276 pos_embed_resample_runs_in_f32 takes no guard) and step3p7_parity::text_decode_delegates_sequence_local_native_batching (assertion failed: !wrapper.supports_padded_prefill()). On the unmodified main (9402cf893), cargo test --locked --profile test-fast --features cuda -p mlxcel --test mlx_test_guard_coverage and --test step3p7_parity fail with the same messages. Every Ricursive test passes in the gate.
  • cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings: pass.
  • cargo fmt --all -- --check: clean.
  • scripts/ci on this commit: 40 checks, 38 pass (check_used_by.py: 78 public functions in 2 shared files, 57 annotated, 719 caller-file references; check_cross_repo_refs.py HEAD; every other check_*.py and *_test.sh; make verify-rocm-overlay verify-cuda-runtime-dir verify-python-tooling verify-makefile-env; the license header check; the web UI contract self-test; the MLX pin check). check_helm_chart.py and helm_chart_package_test.sh fail because helm is not installed on the host, the same way on the base.

Real checkpoints

Checkpoint Revision Size
frogggias/Ripple-65B-Preview-MLX-4bit 4a33b33f043f41a51ae7236edd440d64cfa7cc94 36.45 GB, affine 4-bit, group 64
frogggias/Ripple-65B-Preview-MLX-8bit dd672246374fa2a3829fcc42c3ad02409098909f 68.84 GB, affine 8-bit, group 64
  • mlxcel arch lists "Ricursive Ripple (sliding/NoPE-global, value residuals)" under "Specialized"; mlxcel arch --json has a ricursive entry, category dense, kv_modes ["fp16"].
  • mlxcel generate -m Ripple-65B-Preview-MLX-4bit -p "Write a Python function that merges overlapping intervals." -n 256 --temp 0 --profile (17-token chat prompt; this commit and the previous revision) prints a correct merge_intervals (sort by start, extend the last interval while start <= merged[-1][1], else append) plus one sentence, 122 tokens, and stops on EOS before the 256 limit. Resident 33.94 GB.
  • "What is 17 * 23?": 17 * 23 = 391., 8 tokens, then EOS.
  • A 1,708-token prompt ("The notebook records an observation. " * 280 plus a question about the code word placed at its end), so the sliding layers cross the 1,024-token window: the model reasons briefly and answers ORCHID, 61 tokens, then EOS (four runs, this commit included).
  • Rates on a shared GPU, this commit: decode 3.84 (8 tokens), 4.96 (122) and 4.67 (61) tok/s; the 1,708-token prefill 247.2 tok/s; load 5.0 to 44.3 s depending on the page cache. The previous revision measured decode 3.49 to 4.83 tok/s and that prefill at 166.9 and 229.6 tok/s with the CUDA kernels cached (47.6 tok/s on the host's first run, which compiled them).
  • Greedy parity with mlx_vlm.generate (temperature 0, chat template, same 4-bit weights). For all three prompts the prompt ids are identical (16, 17 and 1,708 tokens). On the two short prompts mlxcel's tokens equal mlx-vlm's (8 and 122) in every run, this commit included, after which mlx-vlm emits <|im_end|> (100265), the id mlxcel stopped on. On the 1,708-token prompt mlx-vlm emits 61 tokens and then 100265; two of four mlxcel runs match all 61, and the other two (this commit, and one of two runs of the same binary on the previous revision) differ in one token, position 52, inside the reasoning (Ensure only code. where mlx-vlm has Must only code.), and match the other 60, the ORCHID answer and the EOS. One binary produced both outputs, so this is run-to-run variation on this host rather than a code difference; the logit gap at that position was not measured. mlx-vlm's own rates on those runs: decode 4.70 to 5.22 tok/s, 1,708-token prefill 52.9 tok/s (its first run on the host).
  • mlxcel-server -m Ripple-65B-Preview-MLX-4bit, streaming /v1/chat/completions at temperature 0 with the checkpoint's chat_template.jinja: "What is 17 * 23?" streams 17 * 23 = 391. (HTTP 200, text/event-stream, finish_reason: stop); the interval prompt streams the same function as generate in 107 chunks, finish_reason: stop.

Teacher-forced parity against mlx-vlm 0.8.1 (checkout e8035ae3, which contains #2697) on mlx 0.32.5 (CUDA 13 wheel), 8-bit checkpoint, corpus docs/architecture.md (4,179 tokens): examples/logit_trace against scripts/mlx_lm_logit_trace.py --mlx-vlm, compared with scripts/compare_logit_traces.py (decided = reference top-two gap of at least 2).

Trace Positions Top-1 disagreements Decided disagreements Logit delta on the reference's choice Perplexity ref / mlxcel
4 chunks of 64 (64 4 8 0) 256 2 (both rank 2, gap ≤ 0.219) 0 / 107 p50 0.0625, p99 1.0938, max 1.6250 40.7913 / 41.0734
one 1,536-token prefill (1536 1 8 0), crosses the window 1,536 17 (16 rank 2, 1 rank 3, gap ≤ 0.219) 0 / 662 p50 0.0586, p99 0.5000, max 2.3926 10.9976 / 11.0352
48 chunks of 32 behind up to 1,200 tokens of context (32 48 8 1200) 1,536 20 (all rank 2, gap ≤ 0.219) 0 / 667 p50 0.0488, p99 0.5586, max 1.6250 10.8980 / 10.9313
  • Every disagreement is at a position where the reference's top two are within 0.219. Both runtimes emit bf16 logits here (upstream projects the head in the activation dtype), and they run different MLX builds (the pinned MLX with mlxcel's CUDA overlays against the 0.32.5 wheel), so their quantized matmuls and reductions are not bit-identical.
  • In the third trace mlxcel prefills the context in one forward and then traces each 32-token block through the cache (the rotating cache wraps for every chunk whose context plus block exceeds 1,024 tokens); the reference runs one causal forward over context plus block.

Not verified / limits

  • BF16 ricursiveAI/Ripple-65B-Preview (129.6 GB) does not fit this host and was not run; the dtype fix is shown on a small random BF16 checkpoint. araysuter/Ripple-65B-Preview-MLX-mixed-2bit is refused by its config.json (read from the Hub) and was not downloaded. The ModelOpt NVFP4 export is refused, not supported.
  • The 8-bit logit traces and the server streaming runs are from the previous revision; this revision changes nothing those quantized checkpoints reach on this GPU.
  • Metal, ROCm and pre-Ampere CUDA were not run.
  • Tensor and pipeline parallel, the DFlash2 drafter, KV cache quantization and concurrent server batching on the real checkpoint were not exercised. Native batched decode is covered by the tiny-model contract test only; prompt-cache snapshots and padded-prefill trimming were not exercised for this family.
  • Decode runs a few more small kernels per layer than a fused path would (the FP32 RoPE rotation, the value-residual lerp, the FP32 gate and SiLU casts). Decode was 3.49 to 4.83 tok/s against mlx-vlm's 4.70 to 5.22 tok/s on the same prompts, on a shared GPU, so the cost of those kernels was not isolated; this PR does not add fused kernels for them.
  • The commit sits on the current main (9402cf893); git merge-tree --write-tree origin/main HEAD returns this commit's tree.

Adds Ricursive Ripple-65B-Preview (model_type ricursive,
RicursiveForCausalLM) to mlxcel generate, mlxcel-server and mlxcel arch,
following mlx-vlm's ricursive port (Neywa-Labs/mlx-vlm#2697) including its
rounding: RoPE sliding-window layers and NoPE full layers, four RMS norms
per block plus per-head q/k norms, value residuals that lerp every layer's
value input toward the scaled input embedding in FP32, an FP32 sigmoid
output gate, a clipped SwiGLU with an FP32 SiLU and embed_scale applied in
FP32 after the lookup. Per-sequence caches are scheduler-owned with native
batched decode. MLX's fused rms_norm already rounds before applying the
weight, which is the reference order, so the block uses the shared RMSNorm.

The family keeps its checkpoint dtype at load, as mlx-vlm runs it: the
bf16 -> f16 cast (Apple Silicon, pre-Ampere CUDA, MLXCEL_CUDA_F16_NORMALIZE)
would turn value_res_lambda into f16, which the loader refuses.

limited_swiglu's clamp moves into a shared helper next to the new
limited_swiglu_f32_silu; DeepSeek-V4 and V4.1 compute what they did. The
ModelOpt NVFP4 export and per-module mixed quantizations are refused by
name.

Closes lablup#3224

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): add Ripple-65B (ricursive) support

1 participant