feat(models): add Muse Spark (muse_spark) text decoder support
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ả
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
- ml-explore/mlx-lm#1976 (
06e03f7, 2026-10-15) added the model asmuse_spark_open, with fused kernels (expert_routing,norm_add_norm,post_expert_norm_combine,qk_norm,qk_norm_rope,rms_norm_sigmoid_gate), a processor, a tool parser and server changes. ml-explore/mlx-lm#1977 (5f3c79d) fixed the response template. ml-explore/mlx-lm#1981 (93e6d4a) renamed everything tomuse_sparkto match the HF names. Current code: https://github.com/ml-explore/mlx-lm/tree/main/mlx_lm/models/muse_spark (config.py,layers.py,model.py,checkpoint.py,kernels.py), https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/tool_parsers/muse_spark.py and https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/chat_templates/muse_spark.py. - Blaizzy/mlx-vlm#2542 (merge
f1a9b7ba, 2026-10-20) at https://github.com/Blaizzy/mlx-vlm/tree/main/mlx_vlm/models/muse_spark carries the same decoder inlanguage.pyplus the multimodal pieces handled by #3223. - Treat the mlx-lm Python fallbacks and kernel sources as the numeric contract. Porting the six Metal kernels is not required for correctness; implement the math with MLX ops first, then fuse only where a measurement justifies it (see Performance below).
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 upstreamnorm_add_normkernel fuses the add with the next block'sinput_layernorm; the ops version is the same math. - Residual gates: checkpoint tensors
post_attention_residual_gate.gateandpost_feedforward_residual_gate.gate([hidden]) becomew = 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 storeadd_attn_alpha,add_attn_beta,add_ffn_alpha,add_ffn_beta; detect a converted checkpoint by any key ending in_alphaand then skip every sanitize transform. Readresidual_gate_temperaturefrom 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 (epsrms_norm_eps); q is then multiplied byqk_scale_factor; RoPE is traditional (traditional=True, interleaved pairs) at baselayer_rope_theta[i]on layers where it is non-zero, applied after the norm and scale. Whether a layer uses RoPE comes fromlayer_rope_thetaalone and whether it is sliding comes fromlayer_typesalone: they coincide on the real config, but the tiny test checkpoint has a full layer with RoPE and a sliding layer without it; SDPA scalehead_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 growingKVCache. - MoE: router
gate.weight[256, 8192]andgate.e_score_correction_bias[256], both f32.logits = x.f32 @ gate.weight.T;score = sigmoid(logits * output_multiplier); select top-8 byscore + bias(ties to the lower expert id), weights from unbiasedscore,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 tomoe_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 withexperts.post_expert_norm.weight(epspost_norm_eps) before the weighted sum,y = sum_k(norm(y_k) * w_k), and finallypost_expert_proj(4096 to 8192).num_shared_experts != 0or any non-sparsemlp_layer_typesentry is rejected by name, as upstream does. - Head:
logits = lm_head(norm(h).astype(bf16)).f32 * output_multiplier, thentanh(logits / 20) * 20.model.language_model.normreads the f32 stream. - Zero-centered norms: checkpoint norms
input_layernorm,pre_feedforward_layernorm,post_feedforward_layernorm,mlp.pre_expert_norm,mlp.experts.post_expert_normstorew - 1; sanitize stores(1 + w.f32).bf16.MuseRmsNorm::centeredinsrc/models/muse_glimmer_layers.rs:44is 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 (upstreamquant_predicate), and every dense projection is bf16. - HF NVFP4 layout (
meta-models/...-NVFP4): separateself_attn.{q,k,v,gate}_proj.*are concatenated intoqkvg_projafter 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) becomingglobal_scale = scale_2 * 6 * 448;down_proj,down_proj_weight_scale,down_proj_weight_scale_2likewise. Drop*_input_scale(activations are not quantized) and everymodel.audio_tower.*key. With novision_config, also dropmodel.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_scalehere has mlx-lm's native meaning (dequantize withglobal_scale / (448 * 6)), which isnative_global_scaleinsrc/models/switch_layers.rs:483-491, not the opposite-senseinv_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:962routesmuse_glimmerthroughdetect_text_or_vlm_by_weights. Addmuse_sparkthe same way:ModelType::MuseSpark(text) when the checkpoint has no vision weights or the user requests text,ModelType::MuseSparkVLMreserved 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 waystartup.rsrefuses 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 behindModelOwnedSequenceStatewithSequenceId), the text-only marker guardreject_muse_glimmer_text_only_markers(called atsrc/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 theis_muse_glimmer_model_pathcheck (src/server/startup.rs:1379) and anyMuseGlimmer-only match arms into a Muse-family predicate that includesMuseSpark, 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 toreasoning_content, the tool header is hidden, and the answer channel reachescontent. - NVFP4 experts:
src/models/switch_layers.rsnative_global_scalepath and the NVFP4 key normalization insrc/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_selectfromsrc/models/laguna_layers.rs:536(scale the logits byoutput_multiplierbeforerouter_scores; normalize with a1e-15epsilon) and update its// Used by:comment.
Implementation plan
src/models/muse_spark_config.rs:MuseSparkTextArgsand the top-levelMuseSparkArgs(vision and audio configs parsed but unused here), with load-time validation of every rejection above.layer_rope_thetaandlayer_typesare truncated tonum_hidden_layers(as mlx-vlmconfig.pydoes) and a list shorter than that is a load error; the tiny checkpoint below ships 62layer_rope_thetaentries 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,LanguageModelimpl includinglast_row_logitsand 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 insrc/models/mod.rs,src/model_metadata.rs(text kind; adapters unsupported with a named message as Glimmer's entry atsrc/model_metadata.rs:192does),src/loaded_model.rs,src/models/registry.rs(mlxcel arch), and the per-family tables insrc/execution/memory_estimate.rsandsrc/distributed/tensor_parallel/inference.rs. docs/supported-models.md: a text-family entry with the operational blockdocs/adding-models.mdrequires 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 archlistsmuse_spark. - Tiny checkpoints:
trl-internal-testing/tiny-MuseSparkForConditionalGenerationloads throughmlxcel generatewith finite logits, and its logits for a fixed prompt matchmlx_lmon 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 BF16reference/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 0reaches391in the user channel, with reasoning separated, and greedy 64-token output matchesmlx_lm.generate --temp 0on the same checkpoint (MLXCEL_FUSED_MOE=0), including on a prompt longer than 2048 tokens. -
mlxcel-serverserves 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_coefficientsagainst hand-computed values for gate 0 and a negative and positive gate; (2)interleave_rope_rowsmaps rotate-half rows to interleaved pairs, verified by RoPE on the reordered weights equalling rotate-half RoPE on the original; (3) thegate_up_projsplit, uint8 to uint32 view andscale_2 * 2688global scale land innative_global_scale, notinv_global_scale; (4) router selection uses the biased score, weights the unbiased one, appliesoutput_multiplierbefore the sigmoid and the1e-15epsilon; (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-serverandmlxcel arch;docs/supported-models.mdupdated.
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_projby 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của lablup/mlxcel
-
area:core priority:high status:ready type:security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:medium status:ready type:security
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:models modeltype:text priority:medium status:in-progress type:bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:models priority:low status:ready type:test
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:models modeltype:omni priority:medium status:ready type:bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của lablup/mlxcel
Issue tương tự
-
TypeScript BM25 drops supplementary characters at the token length limitCó thể đã có người làm @ErenAta16 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
chroma-core/chroma#8038 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
p3 ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 71/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:ui effort:medium enhancement P7 source:agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
marketing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousĐang mởmaintainer-needed p2 remote triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày