feat(models): add Muse Spark (muse_spark) text decoder support

Đang mở
#3,222 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
8/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
ai, machine-learning

Hướng nghiên cứu

Start from the existing Muse Glimmer port: read src/models/muse_glimmer_layers.rs (MuseRmsNorm), src/models/muse_glimmer_cache.rs, and the detection routing in src/models/detection.rs. The work is a new muse_spark family module for the text decoder, with weight sanitize covering NVFP4 and affine layouts. Done means the tiny test checkpoints load and match the upstream mlx-lm reference, but the issue is blocked on a 512 GiB host, so it is not a first task.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Summary

Add the text decoder of Meta Muse Spark Open (model_type: muse_spark, MuseSparkForConditionalGeneration, text_config.model_type: muse_spark_text): an 816B-total, 42B-active omni model whose language model is a 62-layer MoE with a gated fp32 residual stream, sliding and NoPE full attention, a compressed-width expert block, and NVFP4 or affine-quantized experts. This issue covers the text path only: text prompts, the ATEM tool-call format, reasoning headers, and the NVFP4 and MLX checkpoint layouts. Image, video and audio input are split into #3223, which is blocked on this one, because the multimodal half adds a vision tower, an audio encoder, two processors and timestamp handling, which together with this decoder would be more than one reviewable PR.

Muse Spark is the larger sibling of the ported Muse Glimmer (src/models/muse_glimmer*.rs, #1100). They share the chat envelope, the ATEM tool format, zero-centered norm storage and the vision config surface, but the decoder is a different architecture (MoE with residual gates rather than Glimmer's dense sandwich-norm decoder), so this is a new family module that reuses Glimmer's server and template pieces rather than extending muse_glimmer.rs.

Upstream reference

Architecture (text decoder)

Text config (mlx-community/Muse-Spark-Open-816B-A42B-4bit): hidden_size 8192, num_hidden_layers 62, num_attention_heads 128, num_key_value_heads 16, head_dim 64, vocab_size 202048, rms_norm_eps 1e-5, post_norm_eps 1e-8, qk_scale_factor 5.4730064863875, rope_parameters {rope_theta 500000, rope_type default}, layer_rope_theta (0 marks NoPE; 0 on layers 1, 5, 9, ..., 61), layer_types (16 full_attention, the same 16 NoPE layers; 46 sliding_attention), sliding_window 2048, final_logit_softcapping 20.0, output_multiplier 0.17677669529663687, num_local_experts 256, num_experts_per_tok 8, moe_hidden_size 4096, moe_intermediate_size 4096, routed_scaling_factor 1.0, num_shared_experts 0, mlp_layer_types all sparse, residual_gate_temperature 0.3, max_position_embeddings 1048576, tie_word_embeddings false. Top level: image_token_id 200092, video_token_id 200091, audio_token_id 200038, eos_token_id [200001, 200008] (<|eot|> and <|end|>; <|eom|> is NOT a stop token).

  • Embedding: h = rms_norm(embed_tokens(ids), weight=None, eps=rms_norm_eps) (weightless), then cast to f32. The residual stream is f32 for the whole decoder.
  • Block (per layer): attn_in = input_layernorm(x).astype(bf16); r = self_attn(attn_in); h = alpha_attn * x + beta_attn * rms_norm(r, eps=post_norm_eps) (weightless post-norm, result kept f32); ffn_in = pre_feedforward_layernorm(h); r = mlp(ffn_in); out = alpha_ffn * h + beta_ffn * rms_norm(post_feedforward_layernorm.weight * r, eps=post_norm_eps). The post-FFN norm is an input-scale norm: the weight multiplies the input before a weightless rms norm (InputScaleRMSNorm). The upstream norm_add_norm kernel fuses the add with the next block's input_layernorm; the ops version is the same math.
  • Residual gates: checkpoint tensors post_attention_residual_gate.gate and post_feedforward_residual_gate.gate ([hidden]) become w = gate / 0.3, beta = sigmoid(w), alpha = sqrt(clip(sigmoid(-w) * (1 + beta), 1e-3, inf)), all f32, computed once at load (residual_gate_coefficients). MLX conversions already store add_attn_alpha, add_attn_beta, add_ffn_alpha, add_ffn_beta; detect a converted checkpoint by any key ending in _alpha and then skip every sanitize transform. Read residual_gate_temperature from the config rather than hard-coding 0.3.
  • Attention: one fused qkvg_proj [hidden, 2 * (128 + 16) * 64] laid out as q, k, v, output gate. q and k are weightless rms-normed per head (eps rms_norm_eps); q is then multiplied by qk_scale_factor; RoPE is traditional (traditional=True, interleaved pairs) at base layer_rope_theta[i] on layers where it is non-zero, applied after the norm and scale. Whether a layer uses RoPE comes from layer_rope_theta alone and whether it is sliding comes from layer_types alone: they coincide on the real config, but the tiny test checkpoint has a full layer with RoPE and a sliding layer without it; SDPA scale head_dim ** -0.5; GQA 128:16. Output: o_proj(rms_norm(attn_out_per_head, eps=rms_norm_eps) * sigmoid(gate)) (weightless per-head norm, sigmoid gate in f32). No attention sinks, no QK weights.
  • Caches: sliding layers RotatingKVCache(max_size=2048); full (NoPE) layers growing KVCache.
  • MoE: router gate.weight [256, 8192] and gate.e_score_correction_bias [256], both f32. logits = x.f32 @ gate.weight.T; score = sigmoid(logits * output_multiplier); select top-8 by score + bias (ties to the lower expert id), weights from unbiased score, w / (sum(w) + 1e-15) * routed_scaling_factor. The experts run at a compressed width: h = pre_expert_norm(pre_expert_proj(x)) (Linear 8192 to moe_hidden_size, then weighted RMSNorm), y_k = experts(h)[k] (SwitchGLU, precise SwiGLU in f32 then rounded), then each expert output is input-scale normed with experts.post_expert_norm.weight (eps post_norm_eps) before the weighted sum, y = sum_k(norm(y_k) * w_k), and finally post_expert_proj (4096 to 8192). num_shared_experts != 0 or any non-sparse mlp_layer_types entry is rejected by name, as upstream does.
  • Head: logits = lm_head(norm(h).astype(bf16)).f32 * output_multiplier, then tanh(logits / 20) * 20. model.language_model.norm reads the f32 stream.
  • Zero-centered norms: checkpoint norms input_layernorm, pre_feedforward_layernorm, post_feedforward_layernorm, mlp.pre_expert_norm, mlp.experts.post_expert_norm store w - 1; sanitize stores (1 + w.f32).bf16. MuseRmsNorm::centered in src/models/muse_glimmer_layers.rs:44 is the existing implementation of this convention; reuse it or the same conversion at load, not both.
Weight layout and sanitize
  • MLX conversion keys (mlx-community/...-4bit, 2088 tensors): model.language_model.embed_tokens.weight, model.language_model.layers.N.{input_layernorm,pre_feedforward_layernorm,post_feedforward_layernorm}.weight, layers.N.add_{attn,ffn}_{alpha,beta}, layers.N.self_attn.{qkvg_proj,o_proj}.weight, layers.N.mlp.{pre_expert_proj,post_expert_proj}.weight, layers.N.mlp.pre_expert_norm.weight, layers.N.mlp.gate.{weight,e_score_correction_bias}, layers.N.mlp.experts.{gate,up,down}_proj.{weight,scales,biases}, layers.N.mlp.experts.post_expert_norm.weight, model.language_model.norm.weight, lm_head.weight. Only the routed experts are quantized (affine 4-bit gs64); layers 0 and 61 keep bf16 experts (upstream quant_predicate), and every dense projection is bf16.
  • HF NVFP4 layout (meta-models/...-NVFP4): separate self_attn.{q,k,v,gate}_proj.* are concatenated into qkvg_proj after reordering the q and k rows from HF's rotate-half pairing (i, i + d/2) to interleaved pairs (2i, 2i + 1) (interleave_rope_rows, applied to weight, scales and biases alike). Experts: mlp.experts.gate_up_proj (uint8 packed, split in two along axis 1 into gate and up, viewed as uint32), gate_up_proj_weight_scale (E4M3 block scales per 16 inputs, split likewise), gate_up_proj_weight_scale_2 (column 0 gate, column 1 up) becoming global_scale = scale_2 * 6 * 448; down_proj, down_proj_weight_scale, down_proj_weight_scale_2 likewise. Drop *_input_scale (activations are not quantized) and every model.audio_tower.* key. With no vision_config, also drop model.vision_tower.*, model.vision_adapter.*, model.vision_projection.*; with a vision config they are kept for #3223 but unused by the text path.
  • The global_scale here has mlx-lm's native meaning (dequantize with global_scale / (448 * 6)), which is native_global_scale in src/models/switch_layers.rs:483-491, not the opposite-sense inv_global_scale (:466-479). Feeding it through the wrong field is a silent scale error; the sanitize test must pin which one is used.

Checkpoints and hosts

Checkpoint Revision Format Size
meta-models/Muse-Spark-Open-816B-A42B-NVFP4 75271573 NVFP4 experts, gated (manual approval) 533.0 GB
mlx-community/Muse-Spark-Open-816B-A42B-4bit a87282dd affine 4-bit gs64 experts 532.8 GB
mlx-community/Muse-Spark-Open-816B-A42B-3bit ca05d678 affine 3-bit gs64 experts 436.1 GB
mlx-community/Muse-Spark-Open-816B-A42B-oQ3e b4ce3d89 mixed affine 371.5 GB
trl-internal-testing/tiny-MuseSparkForConditionalGeneration c9e83e87 tiny random BF16, HF layout, with chat template 0.1 GB
IlyasMoutawwakil/tiny-random-Muse-Spark-NVFP4 5d628df4 tiny random NVFP4, with a BF16 reference/ copy of the same weights under 0.1 GB

Community 2-bit mixes of about 237 to 260 GB exist (joshuaswarren/...-MLX-2bit-mixed, staccs/...-lecore-mlx) but are not reference conversions. No usable checkpoint fits a 128 GB or 256 GB host, so this issue is status:blocked on a 512 GiB host: the 3-bit and oQ3e conversions fit one with room for the KV cache; the 4-bit and NVFP4 checkpoints (about 496 GiB of weights) are at the limit and should not be the first target. The implementation and all unit tests can proceed now against the two tiny checkpoints, which exercise the HF sanitize path (row interleave, gate_up split, NVFP4 scales). Clearing status:blocked needs only the host.

Current mlxcel state and reuse

  • src/models/detection.rs:962 routes muse_glimmer through detect_text_or_vlm_by_weights. Add muse_spark the same way: ModelType::MuseSpark (text) when the checkpoint has no vision weights or the user requests text, ModelType::MuseSparkVLM reserved for #3223. Until that lands, a checkpoint with vision weights loads as text and media requests fail with a named "Muse Spark image/video/audio input is not supported yet" error, the same way startup.rs refuses unsupported paths for text-only Glimmer (src/server/startup.rs:1485-1500).
  • Reuse from Muse Glimmer: MuseRmsNorm (src/models/muse_glimmer_layers.rs:21-60), the Muse cache layout (src/models/muse_glimmer_cache.rs, sliding rotating plus growing full caches behind ModelOwnedSequenceState with SequenceId), the text-only marker guard reject_muse_glimmer_text_only_markers (called at src/server/model_worker.rs:1749), and the server's ATEM support: ToolCallFormat::Atem (src/server/tool_calls/types.rs:40), detected from the chat template (src/server/chat_template.rs:2214), the recipient-envelope stream filter (src/server/tool_calls/stream_filter.rs:411-522, src/server/muse_atem_stream_support.rs). Generalize the is_muse_glimmer_model_path check (src/server/startup.rs:1379) and any MuseGlimmer-only match arms into a Muse-family predicate that includes MuseSpark, rather than copying them.
  • Response envelope: assistant turns are to=self<|message|>reasoning<|eom|>, <|start|>assistant to=NAME<|message|><atem:function_calls>..., <|start|>assistant to=user<|message|>answer<|eot|>. This is the envelope Glimmer already strips (#3025); confirm with a test on the Spark template that reasoning goes to reasoning_content, the tool header is hidden, and the answer channel reaches content.
  • NVFP4 experts: src/models/switch_layers.rs native_global_scale path and the NVFP4 key normalization in src/models/sanitize.rs:350 (normalize_nvfp4_keys); check whether the Spark key names fit it before writing a Spark-specific transform.
  • Sigmoid top-k with selection-only bias: reuse router_select from src/models/laguna_layers.rs:536 (scale the logits by output_multiplier before router_scores; normalize with a 1e-15 epsilon) and update its // Used by: comment.

Implementation plan

  • src/models/muse_spark_config.rs: MuseSparkTextArgs and the top-level MuseSparkArgs (vision and audio configs parsed but unused here), with load-time validation of every rejection above. layer_rope_theta and layer_types are truncated to num_hidden_layers (as mlx-vlm config.py does) and a list shorter than that is a load error; the tiny checkpoint below ships 62 layer_rope_theta entries for 2 layers, so a strict length check would reject it.
  • src/models/muse_spark_layers.rs: attention (fused qkvg, weightless qk norm, query scale, traditional RoPE, norm-and-sigmoid output gate), the residual-gate block, the compressed-width MoE with per-expert post-norm combine.
  • src/models/muse_spark.rs: model shell, f32 residual stream, softcapped head, LanguageModel impl including last_row_logits and batched decode for mixed rotating/full caches.
  • src/models/muse_spark_sanitize.rs: the HF-to-MLX transforms above, idempotent on MLX conversions.
  • Tests in src/models/muse_spark_tests.rs (below). Registration in src/models/mod.rs, src/model_metadata.rs (text kind; adapters unsupported with a named message as Glimmer's entry at src/model_metadata.rs:192 does), src/loaded_model.rs, src/models/registry.rs (mlxcel arch), and the per-family tables in src/execution/memory_estimate.rs and src/distributed/tensor_parallel/inference.rs.
  • docs/supported-models.md: a text-family entry with the operational block docs/adding-models.md requires for large models (checkpoint identity and revision, about 406 GiB of 3-bit weights, 512 GiB host class, 1048576 declared context with 2048-token sliding layers plus growing NoPE layers, ATEM tools, EOS ids, and unsupported TP, PP, speculative and media paths).

Performance

The upstream kernels exist because the stream is f32 and the block runs three norms around each add. Port with MLX ops first and record decode tok/s on the 512 GiB host. Then fuse norm_add_norm and the per-expert post_expert_norm_combine only if a profile on the real checkpoint shows them above 10 percent of decode time; any fused kernel needs a test against the ops path and must carry dtype entries in its template_args (the JIT kernel cache keys rule in the project contributor guidelines, enforced by make verify-kernel-dtype-keys) if it gets a CUDA port.

Acceptance criteria

  • mlxcel arch lists muse_spark.
  • Tiny checkpoints: trl-internal-testing/tiny-MuseSparkForConditionalGeneration loads through mlxcel generate with finite logits, and its logits for a fixed prompt match mlx_lm on the same checkpoint within 1e-3 max abs (both runs in f32 where possible); the NVFP4 tiny checkpoint loads through the NVFP4 sanitize path and its logits track its own BF16 reference/ weights within NVFP4 quantization error (top-1 agreement on a 32-token greedy run).
  • On the 512 GiB host, mlxcel generate -m models/Muse-Spark-Open-816B-A42B-3bit -p "What is 17 * 23?" -n 256 --temp 0 reaches 391 in the user channel, with reasoning separated, and greedy 64-token output matches mlx_lm.generate --temp 0 on the same checkpoint (MLXCEL_FUSED_MOE=0), including on a prompt longer than 2048 tokens.
  • mlxcel-server serves the 3-bit checkpoint: streaming chat, reasoning_content, one ATEM tool call round trip, and stop on <|eot|> while <|eom|> transitions continue.
  • Unit tests: (1) residual_gate_coefficients against hand-computed values for gate 0 and a negative and positive gate; (2) interleave_rope_rows maps rotate-half rows to interleaved pairs, verified by RoPE on the reordered weights equalling rotate-half RoPE on the original; (3) the gate_up_proj split, uint8 to uint32 view and scale_2 * 2688 global scale land in native_global_scale, not inv_global_scale; (4) router selection uses the biased score, weights the unbiased one, applies output_multiplier before the sigmoid and the 1e-15 epsilon; (5) per-expert post-norm happens before the weighted sum (a test with two experts of different magnitude fails if the norm is applied after); (6) zero-centered norm conversion is applied once and skipped on converted checkpoints; (7) full prefill equals chunked prefill plus decode across the 2048 window on a tiny random model; (8) last_row_case!.
  • A checkpoint with vision weights loads as text, and a request with an image fails with the named not-supported error rather than silently dropping the image.
  • 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 muse_spark_tests:: muse_glimmer_tests:: atem
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 trl-internal-testing/tiny-MuseSparkForConditionalGeneration
./target/release/mlxcel generate -m models/tiny-MuseSparkForConditionalGeneration -p "Hello" -n 16 --temp 0
# 512 GiB host only:
MLXCEL_FUSED_MOE=0 ./target/release/mlxcel generate -m models/Muse-Spark-Open-816B-A42B-3bit -p "What is 17 * 23?" -n 256 --temp 0

Related

  • #1100 (Muse Glimmer port), #3025 (Muse recipient headers in StreamFilter).
  • #3223 (image, video and audio input) is blocked by this issue.
  • Out of scope: tensor and pipeline parallel (upstream shards qkvg_proj by segment and experts in place), and the DFlash2 drafters (nvidia/Muse-Spark-Open-816B-A42B-DFlash2, RadixArk/Muse-Spark-Open-DFlash2).
Ngôn ngữ chính
Rust
Star
505
Fork
81
Merge trung bình
14 giờ 2 phút
Pull request đã merge (30 ngày)
448

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lablup/mlxcel

Tất cả issue của lablup/mlxcel

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.