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

Aperta
#3,224 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
12/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start by reading the Architecture and Current mlxcel state sections, then the closest existing code: src/models/muse_glimmer_layers.rs (MuseGlimmerDecoderLayer) and src/models/deepseek_v4_moe.rs (limited_swiglu). The new family goes in src/models/ricursive.rs with tests in src/models/ricursive_tests.rs. Done means the unit tests pass, the 4-bit checkpoint generates correctly, and logits match mlx-vlm at decided positions.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

arch:hybrid area:models modelsize:medium modeltype:text priority:medium status:ready type:enhancement

Summary

Add Ricursive Ripple-65B-Preview (model_type: ricursive, RicursiveForCausalLM), a dense 65B text decoder: 80 layers in a 4:1 pattern of RoPE sliding-window (1024) layers and NoPE global layers, four RMS norms per block (sandwich norms), per-head QK RMSNorm, an elementwise sigmoid attention output gate, clipped SwiGLU, scaled input embeddings, and value residuals that blend every layer's value input with the scaled input embedding. mlxcel has no ricursive support.

Upstream reference

Architecture (from upstream code and the published config)

Config of ricursiveAI/Ripple-65B-Preview (d58dbcf4): hidden_size 5120, num_hidden_layers 80, num_attention_heads 80, num_key_value_heads 8, head_dim 128, intermediate_size 40960, vocab_size 100352, rms_norm_eps 1e-6, rope_theta 10000, sliding_window 1024, layer_types with full_attention at layers 4, 9, 14, ..., 79 (every fifth, 16 layers) and sliding_attention elsewhere (the same as hybrid_layer_pattern, where 0 marks global), use_gated_attention true, gate_full_precision true, use_valres true, ffn_clamp_threshold 20.0, embed_scale 71.55417527999327 (= sqrt(5120)), max_position_embeddings 2097152, tie_word_embeddings false, bos 100257, eos [100265, 100257], pad 100277, hidden_act silu.

  • Embedding: h0 = (embed_tokens(ids).f32 * embed_scale).astype(dtype) when embed_scale is set (a checkpoint may instead fold the scale into the table and set it to null). h0 is also the value residual.
  • Block: a = attn(input_layernorm(x), value_residual=h0); x = x + post_attention_layernorm(a); x = x + post_feedforward_layernorm(mlp(pre_feedforward_layernorm(x))). Final norm then lm_head.
  • RMSNorm numerics: computed in f32 (x * rsqrt(mean(x^2) + eps)), rounded to the activation dtype, then multiplied by the weight in that dtype. This is not fast_rms_norm with a weight, which multiplies before rounding; use the round-then-scale order everywhere (all four block norms, q_norm, k_norm, final norm).
  • Attention: q_proj (5120 to 80128), k_proj and v_proj (5120 to 8128), o_proj, all bias-free. q_norm / k_norm per head. Values: v = v_proj(lerp(h0, x_normed, sigmoid(value_res_lambda))) where value_res_lambda is a learned [1] scalar per layer and x_normed is the block's attention input; the lerp is computed in f32 like torch.lerp (seed + b * (end - seed) for b < 0.5, end + (b - 1) * (end - seed) otherwise) and rounded once. With use_valres false, v = v_proj(x_normed).
  • RoPE: only on sliding layers; full layers are NoPE. Rotate-half (non-traditional) over the full head_dim, inv_freq = 1 / base^(i/d), positions offset by the cache offset; cos and sin are computed in f32, rounded to the activation dtype, then the rotation is done in f32 and rounded (upstream _apply_rotary). Plain fast_rope differs in that intermediate rounding; decide with the logit-trace gate below whether fast_rope is acceptable, and if it disagrees at decided positions, implement the upstream order.
  • SDPA: scale head_dim ** -0.5, GQA 80:8, no sinks. Sliding layers use a windowed causal mask of 1024; full layers a plain causal mask.
  • Output gate: out = attn_out * sigmoid(g_proj(x_normed)) where g_proj is 5120 to 80*128 (elementwise, not per head); with gate_full_precision the sigmoid input is cast to f32 first. Then o_proj.
  • MLP: down_proj(silu(min(gate, 20)) * clip(up, -20, 20)) with gate_proj / up_proj 5120 to 40960; SiLU is computed in f32 and rounded once before the multiply. No clamp when ffn_clamp_threshold is null.
  • Caches: sliding layers RotatingKVCache(max_size=1024, keep=0); full layers growing KVCache. A null sliding_window makes every layer a growing cache.
  • Config validation (load errors): layer_types length equals num_hidden_layers, only the two known layer types, hidden_act == silu, num_attention_heads % num_key_value_heads == 0, sliding_window >= 1 when set. When layer_types is absent, default to full on i % 5 == 4 (upstream default).
Weight layout and sanitize

HF keys: model.embed_tokens.weight, model.layers.N.{input_layernorm,post_attention_layernorm,pre_feedforward_layernorm,post_feedforward_layernorm}.weight, model.layers.N.self_attn.{q,k,v,o,g}_proj.weight, self_attn.{q,k}_norm.weight, self_attn.value_res_lambda ([1]), model.layers.N.mlp.{gate,up,down}_proj.weight, model.norm.weight, lm_head.weight. No transforms are needed beyond stripping a language_model. prefix (mlx-vlm conversions) and dropping lm_head.weight when tie_word_embeddings. value_res_lambda must stay f32 or bf16 and unquantized; error by name if it is missing while use_valres is true.

Checkpoints and hosts

Checkpoint Revision Format Size
ricursiveAI/Ripple-65B-Preview d58dbcf4 BF16 129.6 GB
frogggias/Ripple-65B-Preview-MLX-4bit 4a33b33f affine 4-bit gs64 36.4 GB
frogggias/Ripple-65B-Preview-MLX-8bit dd672246 affine 8-bit gs64 68.8 GB
araysuter/Ripple-65B-Preview-MLX-mixed-2bit d92b6536 mixed affine 29.6 GB
ricursiveAI/Ripple-65B-Preview-NVFP4 b4b4e36d ModelOpt NVFP4 57.2 GB

The frogggias 4-bit and 8-bit conversions declare model_type: ricursive with the same config, keep the HF key names above (plus .scales / .biases; embed_tokens and lm_head are quantized too, value_res_lambda and the norms stay bf16), and fit a 128 GB host (8-bit with other jobs serialized); they are the validation targets. Their ricursive.py is a remote-code model file for mlx_lm --trust-remote-code; mlxcel ignores it, and embed_scale is applied after the quantized embedding lookup. BF16 (129.6 GB) exceeds a 128 GB host and is out of scope for validation. The ModelOpt NVFP4 export is a stretch goal: load it only if the existing ModelOpt NVFP4 path in src/models/sanitize.rs handles its dense (non-expert) layout without new code; otherwise reject it with a named error and leave it for a follow-up.

Current mlxcel state and reuse

  • No ricursive arm in src/models/detection.rs, src/models/mod.rs, src/model_metadata.rs or src/models/registry.rs.
  • Closest families: Gemma 3 and Muse Glimmer for the four-norm sandwich block and the sliding/full mix (src/models/muse_glimmer_layers.rs:305-335 MuseGlimmerDecoderLayer, NoPE full layers via rope_theta: None, gated attention via gate_proj), GPT-OSS / Laguna for RotatingKVCache plus growing caches with model-owned per-sequence state and windowed prefill masks (src/models/gpt_oss.rs:905-975).
  • Clipped SwiGLU: reuse limited_swiglu (src/models/deepseek_v4_moe.rs:65; a non-positive limit disables clamping, which matches a null threshold) and add a // Used by: DeepSeekV4, Ricursive comment, which the function currently lacks. If the f32 SiLU rounding order matters (check with the trace), add the f32 variant next to it instead of a Ripple-local copy.
  • Value residual: no mlxcel model has one yet; implement it in src/models/ricursive.rs as a small value_residual_lerp(h0, x, lambda) helper with a unit test.
  • The new family touches no shared hotspot other than the // Used by: line on limited_swiglu.

Implementation plan

  • src/models/ricursive.rs: ModelArgs with the validation above, RicursiveRmsNorm (round-then-scale), RicursiveAttention, RicursiveMlp, RicursiveDecoderLayer, RicursiveModel (carries h0 through the layer loop), RicursiveWrapper implementing LanguageModel with last_row_logits, the mixed rotating/full batched decode path, and SequenceId-keyed caches.
  • src/models/ricursive_tests.rs: tests below plus last_row_case!.
  • Registration: src/models/mod.rs (ModelType::Ricursive), src/models/detection.rs ("ricursive"), src/model_metadata.rs (ConfigBacked text entry like Laguna's at src/model_metadata.rs:244), src/loaded_model.rs, src/models/registry.rs, and the per-family tables in src/execution/memory_estimate.rs and src/distributed/tensor_parallel/inference.rs (TP unsupported, named error).
  • docs/supported-models.md: an entry under "Text and hybrid model families" covering the block, value residuals, the window, the checkpoints validated, and unsupported paths (TP, DFlash2).
  • Chat template: the checkpoint's Jinja template is rendered as-is; <|im_end|> (100265) and <|endoftext|> (100257) both stop generation (from eos_token_id).

Acceptance criteria

  • mlxcel arch lists ricursive.
  • mlxcel generate -m models/Ripple-65B-Preview-MLX-4bit -p "Write a Python function that merges overlapping intervals." -n 256 --temp 0 produces a correct function and stops on an EOS id.
  • Greedy 64-token output matches mlx_vlm.generate --temp 0 on the same 4-bit checkpoint for a short prompt and for a prompt longer than 1500 tokens (crosses the 1024 window). Report a teacher-forced logit trace (examples/logit_trace.rs, scripts/compare_logit_traces.py, docs/benchmarks.md) against mlx-vlm on the 8-bit checkpoint with zero disagreement at decided positions; if the RoPE or SwiGLU rounding order is changed from the upstream order, include the arm with the upstream order and show it is not worse.
  • mlxcel-server -m models/Ripple-65B-Preview-MLX-4bit serves streaming chat with the checkpoint template.
  • Unit tests: (1) value residual lerp matches a hand computation for lambda giving blend below and above 0.5, and a test fails if h0 is taken after the first norm instead of before; (2) RMSNorm round-then-scale differs from scale-then-round on a constructed bf16 input and the implementation matches the former; (3) RoPE is applied on sliding layers only; (4) clipped SwiGLU at the threshold and with a null threshold; (5) embed_scale null versus set; (6) full prefill equals chunked prefill plus decode across the window on a tiny random model; (7) config validation errors; (8) last_row_case!.
  • Integrated into mlxcel generate, mlxcel-server and mlxcel arch; docs/supported-models.md updated.

Verification

cargo build --release --features metal,accelerate
cargo test --profile test-fast --features metal,accelerate ricursive_tests:: deepseek_v4_tests::
make verify-test
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
python3 scripts/ci/check_cross_repo_refs.py
./target/release/mlxcel download frogggias/Ripple-65B-Preview-MLX-4bit
./target/release/mlxcel generate -m models/Ripple-65B-Preview-MLX-4bit -p "Write a Python function that merges overlapping intervals." -n 256 --temp 0

Related

  • Out of scope, follow-up once this lands: the official DFlash2 drafter ricursiveAI/Ripple-65B-Preview-DFlash2 (upstream speculative_verifier.py and the transactional rotating cache in cache.py), and tensor parallel.
Lingua principale
Rust
Stelle
505
Fork
81
Merge medio
14h 2m
PR unite (30g)
448

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lablup/mlxcel

Tutte le issue di lablup/mlxcel

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.