Skip to content

feat(models): add dots.llm1 (dots1) MoE - #263

Merged
inureyes merged 2 commits into
mainfrom
feat/issue-249-dots1
Jun 13, 2026
Merged

inureyes merged 2 commits into
mainfrom
feat/issue-249-dots1

Conversation

@inureyes

Copy link
Copy Markdown
Member

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 existing deepseek_v3 / glm4_moe path; the experts reuse the shared src/models/switch_layers.rs SwitchGLU, and the Q/K-norm attention follows src/models/qwen3.rs.

Architecture

  • Standard multi-head attention: 32 query and 32 KV heads (no GQA), head_dim 128, per-head Q/K RMSNorm applied after reshape-to-heads and before transpose + RoPE, non-traditional RoPE at base 1e7, scale head_dim^-0.5.
  • Separate 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/shared down_proj, the expert down_proj, and lm_head are 6-bit while the rest are 4-bit. The unified loaders detect bit width from the packed shape, so the config-level bits=4 / group_size=64 is 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.weight plus e_score_correction_bias, the bias used only in selection), combines the unbiased sigmoid scores gathered at the selected experts (normalized, scaled by routed_scaling_factor 2.5), and always adds a single fused shared expert (moe_intermediate_size * n_shared_experts wide). The group-limited selection step is skipped when n_group is null or 1 (both null in the checkpoint).
  • Untied 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" to ModelType::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::Dots1 variant 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; the mlx-community export is already pre-stacked, so this is a no-op there), copying whole tensors rather than slicing quantized weights, and drops rotary_emb.inv_freq buffers.

Test plan

  • cargo check --release --features metal,accelerate --lib
  • cargo clippy --release --features metal,accelerate --lib -- -D warnings
  • cargo fmt --check
  • Real-model generation on mlx-community/dots.llm1.inst-mixed-4-6bit (Metal device; validated by maintainer)

Closes #249

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.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata status:review Under review labels Jun 13, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Jun 13, 2026
@inureyes
inureyes merged commit f3c6da9 into main Jun 13, 2026
4 checks passed
@inureyes
inureyes deleted the feat/issue-249-dots1 branch June 13, 2026 10:50
@inureyes inureyes added this to the 0.3 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): add dots.llm1 (dots1) MoE

1 participant