Skip to content

fix(qwen3.5-moe): load per-expert split MoE weights (experts.{e}.gate_proj/up_proj/down_proj) #519

Closed

Description

@inureyes

Summary

mlxcel's Qwen3.5-MoE weight sanitization handles the fused experts.gate_up_proj layout and the per-expert experts.{e}.{w1,w2,w3}.weight layout, but NOT the per-expert layout that names tensors experts.{e}.gate_proj.weight / up_proj.weight / down_proj.weight. Such checkpoints fail to load with Missing weight: model.layers.N.mlp.switch_mlp.w1.

Current state

  • sanitize_weights step 6 (src/models/qwen3_5.rs:2350-2398) only stacks per-expert tensors named experts.{e}.{w1,w2,w3}.weight.
  • The fused experts.gate_up_proj path (step 7, qwen3_5.rs:2400-2431) is handled (slice at mid = shape[-2]//2).
  • qwen3_5 uses the qwen3_next-local SwitchLinear::from_weights (src/models/qwen3_next.rs:976-1002), which requires a pre-stacked {prefix}.weight and has NO per-expert fallback (unlike the shared src/models/switch_layers.rs::stack_individual_experts, lines 277-315, which does stack gate_proj/up_proj/down_proj for Qwen2-MoE/Mixtral).

What needs to change

In sanitize_weights step 6, also match experts.{e}.{gate_proj,up_proj,down_proj}.weight, stacking across e in 0..num_experts into switch_mlp.{w1,w3,w2} (gate->w1, up->w3, down->w2), mirroring the fused path's naming. Handle any per-expert quantized scales/biases.

Acceptance criteria

  • A Qwen3.5-MoE checkpoint shipping per-expert gate_proj-named experts loads without Missing weight.
  • Output matches the fused-layout checkpoint for the same model (parity).
  • Unit test with a synthetic per-expert gate_proj-named weight map.

Files

  • src/models/qwen3_5.rs

Activity

  1. added
    type:bug
    status:ready
    priority:medium
    area:models
    status:in-progress
    status:review
    status:done
    and removed
    status:ready
    status:in-progress
    status:review
    on Jul 1, 2026
  2. self-assigned this
    on Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:modelspriority:mediumstatus:donetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions