Skip to content

Experimental: run MoE models that don't fit with experts on disk - #394

Merged
rromenskyi merged 2 commits into
mainfrom
experts-on-disk
Oct 19, 2026
Merged

rromenskyi merged 2 commits into
mainfrom
experts-on-disk

Conversation

@rromenskyi

Copy link
Copy Markdown
Contributor

Settings › Server › Experimental › "Run big MoE models with experts on disk", off by default.

What it does

  • With it on, a MoE model that doesn't fit the GPU limit (less than GPUFit's 2.5 GB left beside its weights) starts with the runtime's --experts-on-disk SHARE (Experimental: routed experts on disk (--experts-on-disk SHARE) mlx-lm#56, pinned).
  • The rest of its routed experts are read from the SSD as they're needed.
  • The share is what the limit leaves after the rest of the weights, the margin and 2.5 GB for the model's work, in 5% steps from 10% to 90%.
  • It isn't offered when the model fits, isn't MoE, or doesn't fit even with 10% of its experts.
  • The prompt cache and prefill are sized by what stays in memory.
  • Only used when the installed runtime has the flag.

Which experts count: only those the runtime offloads, read from the safetensors headers.

  • Quantized gate/up/down projections of a stacked SwitchGLU, with each module gathered across shards.
  • Counts on real folders: Gemma 4 26B-A4B 12.85 GB; Ornith 35B-A3B 11.86 GB.
  • Nemotron 30B-A3B counts 0: its fc1/fc2 experts aren't offloaded yet. Muse Glimmer counts 0: it's dense, with no experts.

Measured on Gemma 4 26B-A4B with a quarter of its experts kept, through the runtime and its server: 7.8 tok/s at a 6.1 GB peak. That model fits this Mac on its own, so the switch leaves it alone here; a model over the limit gets the share.

Settings section rendered in dark mode.

Tests: ExpertsOnDiskTests (header counting, the share rules, the launch argument). 1389 pass.

Reviews (codex, muse), fixed in the second commit:

  • Experts the runtime can't offload were counted.
  • The 10% clamp launched models that couldn't fit.
  • Modules split across shards were missed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XhEwWJCoJPXFyyCzp988Bx

Roman Romenskyi and others added 2 commits October 19, 2026 13:40
Settings › Server › Experimental › "Run big MoE models with experts on
disk", off by default. With it on, a MoE model that doesn't fit the GPU
limit (less than GPUFit's 2.5 GB left beside its weights) starts with
the runtime's --experts-on-disk: the share of its routed experts kept in
memory is what the limit leaves after the rest of the weights, the
margin and 2.5 GB for its work, in 5% steps, 10-90%. The rest is read
from the SSD as needed (ipsupport-llc/mlx-lm#56, pinned).

- The experts' size comes from the safetensors headers (stacked
  switch_mlp/switch_glu tensors with the experts first); a dense model or
  one without stacked experts is left as it is.
- The prompt cache and prefill are sized by what stays resident.
- Only when the runtime has the flag.

Gemma 4 26B-A4B with a quarter of its experts: 7.8 tok/s at a 6.1 GB
peak (it fits on its own, so the switch leaves it alone).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XhEwWJCoJPXFyyCzp988Bx
Review (codex, muse):
- Only quantized gate/up/down projections of a stacked SwitchGLU count
  (Nemotron's fc1/fc2, unquantized or biased experts load whole), and a
  module's tensors are gathered across shards before that check: Gemma 4
  26B-A4B counted 11.7 of its 12.85 GB, its modules split over files.
- No share is offered when even 10% of the experts doesn't fit beside the
  rest: it used to be clamped up to 10% and launched anyway.

Checked on real folders: Gemma 4 26B-A4B 12.85 GB, Ornith 35B-A3B
11.86 GB, Nemotron 30B-A3B and the dense Muse Glimmer 0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XhEwWJCoJPXFyyCzp988Bx
@rromenskyi
rromenskyi merged commit 989a215 into main Oct 19, 2026
2 checks passed
@rromenskyi
rromenskyi deleted the experts-on-disk branch October 19, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant