Skip to content

feat(xla): packed 4-bit MoE expert bank with selected-expert compute #3585

Done

Description

@inureyes

Part of #564

Problem

models/mlx/nvidia-nemotron-3-nano-30b-a3b-4bit (nemotron_h, 52 layers, 128 experts top-6 sigmoid, relu2, 17 GB at 4-bit) expands to 117.6 GiB of f32 weights at load, 111 GiB of it the expert bank. GB10 has 121 GiB unified memory (110 GiB available), so the 30B gates of #3350 are blocked.

Current Behavior (main 4d09a1b, src/lib/mlxcel-xla/src)

  • Config::supports_packed_quant (emitter/config.rs:2122) requires self.moe.is_none() and self.ssm.is_none(), so the packed path (WeightSpec::QuantRaw, weights.rs:65; push_proj, weights.rs:125) never reaches an expert bank.
  • The MoE block (weights.rs:547) pushes every switch_mlp tensor as WeightSpec::Whole, and take_moe_weights (emitter/model.rs:926) declares them f32 at any precision.
  • pins_f32_precision (emitter/recurrent_config.rs:233) pins recurrent-state configs such as nemotron_h to F32.
  • routed_experts (emitter/moe.rs:378) broadcasts hn to [E, N, H] (line 391), computes all E experts, then combines top-k.

Proposed Solution

  • Keep an MLX affine-quantized expert bank packed on device (U32 packed plus f16 scales/biases per expert, about 14 GiB here) and dequantize in the graph.
  • Compute only the top-k selected experts: gather their packed rows by index and combine with the routing weights. No iree_linalg_ext.scatter.
  • Cover relu2 fc1/fc2 and SwiGLU gate/up/down, the shared expert, and the decode, prefill and ragged batch graphs, with one gate mirrored between loader and emitter as supports_packed_quant does today.
  • Non-quantized checkpoints, and quantized MoE checkpoints with the feature off, stay byte-identical to current goldens.

Acceptance Criteria

Verification

Run on GB10 with gpu-lock run for every GPU command; re-run on ROCm gfx1151 for the shared emitter change.

#3350 keeps its five-family gates; its 30B gates wait on this issue.

Activity

  1. added
    status:ready
    type:enhancement
    priority:medium
    area:architecture
    area:inference
    on Nov 30, 2026
  2. added
    status:in-progress
    status:review
    and removed
    status:ready
    status:in-progress
    on Nov 30, 2026
  3. added
    status:done
    and removed
    status:review
    on Nov 30, 2026
  4. added this to the 0.9 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:architecturearea:inferencepriority:mediumstatus:donetype:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions