Repository navigation
feat(models): add dots.llm1 (dots1) MoE - #263
Merged
Merged
Conversation
Port rednote's dots.llm1, a DeepSeek-V3-style Mixture-of-Experts model without MLA. The sigmoid-router, routed-expert, and shared-expert machinery mirrors the existing deepseek_v3 / glm4_moe path, and the experts reuse the shared switch_layers SwitchGLU. Attention is standard multi-head (32 query and 32 KV heads, head_dim 128, no GQA) with per-head Q/K RMSNorm applied before transpose and non-traditional RoPE at base 1e7. Q/K/V/O projections stay separate so the mixed 4/6-bit export loads each tensor at its real per-tensor bit width (v_proj and the down_proj tensors are 6-bit, the rest 4-bit), which the unified loaders detect from shape. Layer 0 is a dense SwiGLU MLP (first_k_dense_replace=1); layers 1..61 are MoE: the router selects the top-6 of 128 experts on the bias-corrected gate logits, combines the unbiased sigmoid scores (normalized, scaled by routed_scaling_factor 2.5), and always adds a single fused shared expert. The group-limited selection step is skipped when n_group is null or 1. The head is untied and all 62 hidden layers are real decoder layers (dots.llm1 has no multi-token-prediction layer to drop). Weight sanitize stacks per-expert tensors only when the checkpoint ships them per-expert (the mlx-community export is already pre-stacked, so this is a no-op there) and drops rotary inv_freq buffers. Registered as a config-backed text model across detection.rs, models/mod.rs, model_metadata.rs, loaded_model.rs, and the tensor-parallel architecture map, with a "MoE (other)" metadata entry. Checkpoint-free unit tests cover config parsing, the dense/MoE layer split, the shared-MLP intermediate derivation, the head_dim fallback, nullable grouped-routing fields, and EOS resolution. docs/supported-models.md lists the family.
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
* feat(models): add dots.llm1 (dots1) MoE Port rednote's dots.llm1, a DeepSeek-V3-style Mixture-of-Experts model without MLA. The sigmoid-router, routed-expert, and shared-expert machinery mirrors the existing deepseek_v3 / glm4_moe path, and the experts reuse the shared switch_layers SwitchGLU. Attention is standard multi-head (32 query and 32 KV heads, head_dim 128, no GQA) with per-head Q/K RMSNorm applied before transpose and non-traditional RoPE at base 1e7. Q/K/V/O projections stay separate so the mixed 4/6-bit export loads each tensor at its real per-tensor bit width (v_proj and the down_proj tensors are 6-bit, the rest 4-bit), which the unified loaders detect from shape. Layer 0 is a dense SwiGLU MLP (first_k_dense_replace=1); layers 1..61 are MoE: the router selects the top-6 of 128 experts on the bias-corrected gate logits, combines the unbiased sigmoid scores (normalized, scaled by routed_scaling_factor 2.5), and always adds a single fused shared expert. The group-limited selection step is skipped when n_group is null or 1. The head is untied and all 62 hidden layers are real decoder layers (dots.llm1 has no multi-token-prediction layer to drop). Weight sanitize stacks per-expert tensors only when the checkpoint ships them per-expert (the mlx-community export is already pre-stacked, so this is a no-op there) and drops rotary inv_freq buffers. Registered as a config-backed text model across detection.rs, models/mod.rs, model_metadata.rs, loaded_model.rs, and the tensor-parallel architecture map, with a "MoE (other)" metadata entry. Checkpoint-free unit tests cover config parsing, the dense/MoE layer split, the shared-MLP intermediate derivation, the head_dim fallback, nullable grouped-routing fields, and EOS resolution. docs/supported-models.md lists the family. * fix(moe): infer per-tensor quant bits in SwitchLinear for mixed-precision experts
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
Port rednote's dots.llm1 (
dots1), a DeepSeek-V3-style Mixture-of-Experts model without MLA. The sigmoid-router, routed-expert, and shared-expert machinery mirrors the existingdeepseek_v3/glm4_moepath; the experts reuse the sharedsrc/models/switch_layers.rsSwitchGLU, and the Q/K-norm attention followssrc/models/qwen3.rs.Architecture
head_dim128, per-head Q/K RMSNorm applied after reshape-to-heads and before transpose + RoPE, non-traditional RoPE at base 1e7, scalehead_dim^-0.5.q_proj/k_proj/v_proj/o_proj(not fused) so the mixed 4/6-bit export loads each tensor at its real per-tensor bit width:v_proj, the dense/shareddown_proj, the expertdown_proj, andlm_headare 6-bit while the rest are 4-bit. The unified loaders detect bit width from the packed shape, so the config-levelbits=4/group_size=64is all that is threaded.first_k_dense_replace=1: layer 0 is a dense SwiGLU MLP; layers 1..61 are MoE. The router selects the top-6 of 128 experts on the bias-corrected gate logits (gate.weightpluse_score_correction_bias, the bias used only in selection), combines the unbiased sigmoid scores gathered at the selected experts (normalized, scaled byrouted_scaling_factor2.5), and always adds a single fused shared expert (moe_intermediate_size * n_shared_expertswide). The group-limited selection step is skipped whenn_groupis null or 1 (both null in the checkpoint).lm_head; all 62 hidden layers are real decoder layers (dots.llm1 has no multi-token-prediction layer to drop).What changed
src/models/dots1.rs: new model implementation.src/models/dots1_tests.rs: checkpoint-free config-parsing and derivation tests.src/models/detection.rs:"dots1"toModelType::Dots1.src/models/mod.rs: module, re-export,ModelType::Dots1,ALL_MODEL_TYPES, "MoE (other)" metadata, test include.src/model_metadata.rs: config-backed loader registration.src/loaded_model.rs:LoadedModel::Dots1variant and delegation arm.src/distributed/tensor_parallel/inference.rs: architecture-name mapping.docs/supported-models.md: dots.llm1 family entry.Weight sanitize
Stacks per-expert MoE tensors only when the checkpoint ships them per-expert (probes
experts.0.gate_proj; themlx-communityexport is already pre-stacked, so this is a no-op there), copying whole tensors rather than slicing quantized weights, and dropsrotary_emb.inv_freqbuffers.Test plan
cargo check --release --features metal,accelerate --libcargo clippy --release --features metal,accelerate --lib -- -D warningscargo fmt --checkmlx-community/dots.llm1.inst-mixed-4-6bit(Metal device; validated by maintainer)Closes #249