Repository navigation
feat(models): support Ricursive Ripple-65B (ricursive) - #3729
Open
Jaeyeong-CHOI wants to merge 1 commit into
Open
Jaeyeong-CHOI wants to merge 1 commit into
Jaeyeong-CHOI wants to merge 1 commit into
Conversation
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
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
Closes #3224.
Adds Ricursive Ripple-65B-Preview (
model_type: ricursive,RicursiveForCausalLM) for text generation and serving. The decoder follows mlx-vlm'sricursiveport (Neywa-Labs/mlx-vlm#2697) step for step, including where it rounds. On GB10 thefrogggias/Ripple-65B-Preview-MLX-4bitcheckpoint writes the acceptance function, its greedy output matchesmlx_vlm.generatetoken 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), andmlxcel-serverstreams 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)ModelArgsdefaults to the published config andvalidate()runs at load:layer_typesmust have one entry per layer and onlyfull_attention/sliding_attention;hidden_actmust besilu;num_attention_headsmust be a positive multiple ofnum_key_value_heads;head_dimmust be positive and even (rotate-half);sliding_window, when set, goes through the sharedvalidate_sliding_window;ffn_clamp_thresholdmust be finite and non-negative;embed_scalefinite. Every error starts withRicursive:. Withoutlayer_types, layeriis full oni % 5 == 4, as upstream.h0 = (embed(ids).f32 * embed_scale).astype(dtype)after the (quantized) lookup; a nullembed_scaleleaves the lookup alone (folded tables).h0is the value residual, taken before the first norm.a = attn(input_layernorm(x), h0),x += post_attention_layernorm(a),x += post_feedforward_layernorm(mlp(pre_feedforward_layernorm(x))), thennormandlm_head(or the tied embedding).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 withtorch.lerp's two branches (seed + b * deltaforb < 0.5,end + (b - 1) * deltaotherwise) and is rounded once.use_valres: falseusesx_normed._apply_rotaryorder: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.out * sigmoid(g_proj(x_normed)), with the gate cast to FP32 first whengate_full_precision; MLPdown(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'sif threshold:).RotatingKVCache(sliding_window), full layers a growingKVCache; a nullsliding_windowmakes 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/rotatingsegment names). Prefill masks come fromprefill_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 throughkv_cache_storage_modes(table_less_storage_modes).language_model.(mlx-vlm conversions), read in place without rewriting the map. A tied config ignoreslm_head.weight.value_res_lambdamust be an unquantized float32 or bfloat16 tensor with one value; a missing one whileuse_valresis true, a.scalessidecar, another dtype or another size is a load error naming the key.RicursiveModel::load(throughis_modelopt_nvfp4_text_checkpoint) before any weight is read; it was not downloaded or validated.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-2bitlists 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 anotherbits,group_sizeormode, or afalseswitch, fails withRicursive: 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_idcomes from the config ([100265, 100257]on the published checkpoints).Shared code touched, and its other callers
sanitize.rs):bf16_to_f16_at_loadreturns false formodel_type: ricursive(newis_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 BF16ricursiveAI/Ripple-65B-Preview), pre-Ampere CUDA for every checkpoint, andMLXCEL_CUDA_F16_NORMALIZE=1for an unquantized one on Ampere and later. The publishedvalue_res_lambdatensors 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 onlyricursive, so the other callers ofbf16_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 oflimited_swiglumoved into a privateclamp_swiglu_inputs, andlimited_swiglu_f32_silusits next to it with the FP32 SiLU.limited_swiglucomputes exactly what it did. Its callers areLimitedSwitchGlu::forwardandLimitedMlp::forwardin 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_formand the DeepSeek-V4.1 tests pass in the gate. Both functions carry aUsed by:line;limited_swiglu's names both DeepSeek families.Used by:rosters gained Ricursive where it calls the helper:prefill_causal_maskandprefill_sliding_window_mask(utils.rs),RotatingKVCache(cache.rs),attend_batched_rows(cache/attend.rs),is_modelopt_nvfp4_text_checkpoint(sanitize.rs) and fourmodel_owned.rshelpers. No behavior changes in these.Wiring:
ModelType::Ricursive(CLI family "Specialized"), detection ("ricursive"), registry name andmodel_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.mdandCHANGELOG.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 sizeslayer_typessliding layers atsliding_window.Where this differs from the issue text
RMSNorm. The issue saysfast_rms_normwith a weight multiplies before rounding. MLX's fused kernels round first:xn = wn * static_cast<T>(x * normalizer)inmlx/backend/cuda/rms_norm.cu:123andout = w * static_cast<T>(x * inv)inmlx/backend/metal/kernels/rms_norm.metal:70at the pinned MLX, which is upstream'snormalized.astype(x.dtype) * weight.layers.rsalready documents this besiderms_norm_round_once, the single-rounding form.rms_norm_rounds_before_applying_the_weightpins the block norm to the explicit FP32-normalize, round, then scale sequence bit for bit on a bf16 row, and showsrms_norm_round_oncegives different bits on the same row. An earlier draft of this branch composed the norm asfast_rms_norm_no_weighttimes the weight; on GB10 it gave the same bits as the fused kernel on that row.limited_swiglureuse 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_storage_modesreports andmlxcel arch --jsonlists (kv_modes: ["fp16"]). The family is not in the turbo-KV list. Requesting another mode was not exercised."model_file": "ricursive.py"(a remote-code file formlx_lm --trust-remote-code). mlx-vlm then loads that file instead of its ownricursivemodule 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 fromconfig.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 on517ede2d7, 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 archlists noricursiveentry.mlxcel generate -m Ripple-65B-Preview-MLX-4bit -p Hello -n 8 --temp 0exits withError: Unsupported model type: ricursive.Load-time dtype, through the CLI (this commit, and the same tree with the pre-fix
ricursive.rsandsanitize.rs)MLXCEL_CUDA_F16_NORMALIZE=1: before the fixmlxcel generate -p "What is 17 * 23?" -n 16 --temp 0printsConverting 78 bf16 weight tensors to f16 for CUDA f16 normalization (MLXCEL_CUDA_F16_NORMALIZE).and exits withError: 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).MLXCEL_CUDA_F16_NORMALIZE=1does 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 inbf16_to_f16_at_loadahead 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 insanitize.rs. The tiny model (3 layers, sliding/full/sliding, window 4,use_valres, clamp 0.2,embed_scale2, 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,h0before the first norm, per-head norms, RoPE on sliding layers only, the window, the gate, the clamp, the four norms):fast_ropein f32 at offset 7, and per-row offsets equal the single-row resultembed_scale: nullover a table folded by the scale equals the scaled model bit for bit, and differs over the unfolded tablevalue_res_lambda), thelanguage_model.prefix, a tied head, and the ModelOpt NVFP4 refusalsliding_window: 1, 0 everywhere for a null windowmxfp4mode and afalseswitch are each refused with an error naming the pathricursive_configs_keep_checkpoint_dtype(insanitize.rs) assertsbf16_to_f16_at_loadis false for Ricursive configs, quantized and not, withMLXCEL_CUDA_F16_NORMALIZE=1set 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_inwrites the tiny model as a BF16 safetensors checkpoint, loads it throughRicursiveModel::loadwith the same opt-in, checks everyvalue_res_lambdais 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)ricursive.rsandsanitize.rs(everything else as in this commit),bf16_checkpoint_loads_in_bf16_under_the_f16_opt_infails withRicursive: model.layers.0.self_attn.value_res_lambda must be float32 or bfloat16 (dtype 9)(9 is float16) andper_module_quantization_overrides_are_refused_by_namefails because the 2-bit entry validates. With only the newsanitize.rsarm removed,ricursive_configs_keep_checkpoint_dtypefails as well. All pass on this commit.ricursivetests: takingh0after layer 0'sinput_layernormfails 4 tests (the replay among them); rotating the full layers fails 3; a bf16 SiLU failsclipped_swiglu_rounds_the_fp32_silu_once; ignoringembed_scalefails 4 (these four on the previous revision of this branch, whose model code is unchanged here). Widening the attention window by one key failsattention_window_is_the_sliding_window_on_sliding_layers_onlyon 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 twotorch.lerpbranches into one still passes every test (the branches differ only in FP32 rounding before the bf16 rounding).make verify-test-cudaon this commit: 18,914 passed, 2 failed, 578 ignored across 207 test binaries. The failures aremlx_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_f32takes no guard) andstep3p7_parity::text_decode_delegates_sequence_local_native_batching(assertion failed: !wrapper.supports_padded_prefill()). On the unmodifiedmain(9402cf893),cargo test --locked --profile test-fast --features cuda -p mlxcel --test mlx_test_guard_coverageand--test step3p7_parityfail 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/cion 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 othercheck_*.pyand*_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.pyandhelm_chart_package_test.shfail becausehelmis not installed on the host, the same way on the base.Real checkpoints
frogggias/Ripple-65B-Preview-MLX-4bit4a33b33f043f41a51ae7236edd440d64cfa7cc94frogggias/Ripple-65B-Preview-MLX-8bitdd672246374fa2a3829fcc42c3ad02409098909fmlxcel archlists "Ricursive Ripple (sliding/NoPE-global, value residuals)" under "Specialized";mlxcel arch --jsonhas aricursiveentry, categorydense,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 correctmerge_intervals(sort by start, extend the last interval whilestart <= 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."The notebook records an observation. " * 280plus 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 answersORCHID, 61 tokens, then EOS (four runs, this commit included).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 hasMust only code.), and match the other 60, theORCHIDanswer 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/completionsat temperature 0 with the checkpoint'schat_template.jinja:"What is 17 * 23?"streams17 * 23 = 391.(HTTP 200,text/event-stream,finish_reason: stop); the interval prompt streams the same function asgeneratein 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, corpusdocs/architecture.md(4,179 tokens):examples/logit_traceagainstscripts/mlx_lm_logit_trace.py --mlx-vlm, compared withscripts/compare_logit_traces.py(decided = reference top-two gap of at least 2).64 4 8 0)1536 1 8 0), crosses the window32 48 8 1200)Not verified / limits
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-2bitis refused by itsconfig.json(read from the Hub) and was not downloaded. The ModelOpt NVFP4 export is refused, not supported.main(9402cf893);git merge-tree --write-tree origin/main HEADreturns this commit's tree.