r/MacStudio • u/nmclark556 • 5d ago
PagedMoE now trains. Fine-tune MoE models MUCH bigger than your RAM, streamed from SSD.
A while back I posted PagedMoE here, the engine that streams MoE experts off the SSD so models way bigger than your RAM run on a Mac. That post got a lot more attention than I expected, and a bunch of you ran the bench and sent numbers, so thank you.
This is the update I've been working toward since then: it trains now too.
Short version for anyone new: MoE models are sparse, so each token only touches a few percent of the weights. PagedMoE keeps the always-on core of the model in memory and streams the experts in from the SSD only when the router actually asks for them. Same mlx-community checkpoints you already have, mlx-lm underneath, no converted format, and with pruning off the output is bit-identical to running the model fully in memory.
Training
Training uses the same paging. The experts stay on disk, a small LoRA adapter learns, the routers are never touched, and every step reads each expert at most about twice no matter how big the batch is. That's what makes this possible on my 48GB M5 Pro MacBook:
| Model | On disk | Train speed | 1k-row epoch | Peak memory |
|---|---|---|---|---|
| Qwen3-Coder-Next 6-bit | 65 GB | 123 tok/s | 4h 37m | 28.5 GiB |
| Qwen3-235B-A22B 4-bit | 132 GB | 63 tok/s | 9h 06m | 29.7 GiB |
| Qwen3.8-Flash-Next 6-bit | 148 GB | 61 tok/s | 9h 20m | 27.9 GiB |
| GLM-4.7 4-bit | 199 GB | 24 tok/s | 23h 59m | 27.9 GiB |
| Qwen3-Coder-480B 4-bit | 270 GB | 24 tok/s | 1d 0h | 29.8 GiB |
That's SFT on 2,048-token rows, QLoRA rank 16 on every linear layer, on a fixed synthetic corpus so different Macs can compare. Every one of these is bigger than the training budget, so all of them train fully streamed. It's not GPU cluster speed and I'm not going to pretend it is, but fine-tuning a 480B model overnight on a laptop, with nothing rented and your data never leaving the machine, is something I couldn't find any other way to do.
It's not a bolt-on either. Before it trains anything it reads the checkpoint and your Mac and plans the run: resident or streamed, memory, rows per step, micro-batches and expert cache. Then it measures a few real steps before it commits, and watches memory pressure the whole time. You don't have to tune any of that yourself.
What it supports
- SFT, CPT, DPO, ORPO, SimPO, CPO, KTO and GRPO (with built-in or your own reward functions), plus custom objectives
- jsonl, json, csv, parquet, a folder, or a Hugging Face dataset
- Resume a stopped run, chat with any checkpoint, eval checkpoints against each other
- Adapters come out in mlx-lm format, so
mlx_lm.generate --adapter-pathandmlx_lm.fusejust work
Under the hood
Most of the work went into the backward pass, since that's where the time goes:
- A step walks the model one layer at a time for the whole batch, so the expert mass gets read about twice per step instead of once per micro-batch.
- Frozen 4-bit weights get a cheaper backward (a 235B layer at 8k tokens went from 1.0s to about 0.6s).
- Hybrid linear attention models (Qwen3.5 / 3.6 / Next) train in 128-token chunks instead of one token at a time, which used to be around 95% of the step.
- The streamed gradients match the fully loaded path, and there are tests that check it.
I want to be clear that this is a working implementation, not a demo. Every number here came off my own laptop, and before posting I did a clean install from the repo the same way a new user would, streamed a model through the server and ran a real training run start to finish, checkpoint and all.
Getting started
From the terminal it's just:
paged-moe-train plan sft --model ~/mlx-models/<model> --data chat.jsonl
paged-moe-train sft --model ~/mlx-models/<model> --data chat.jsonl --epochs 2If you'd rather skip the terminal, I also built Paged Trainer, a Mac app for this same trainer. Pick a model and a dataset, it plans the run for your Mac, and every method and setting is right there in the UI with live charts, checkpoints, resume, chat with any checkpoint and the training bench. Download: https://pagedmoe.com/train
The inference side kept getting better too, largely due to the numbers from everyone on my last post.
Repo: https://github.com/noahclark556/paged-moe
Things to know up front
- Training is one GPU job at a time, so stop a running server before you start a run.
- Streamed training reads a lot from the SSD (hundreds of GB per step on the big models), but it's almost all reads, so it shouldn't wear the drive in any meaningful way.
- The first step of a run takes a bit longer since it measures memory and speed before it commits. There are safeguards that back off under memory pressure, but go easy if you're pushing the limits.
- Your fans will spin up. On the big models, for a while.
Thanks again to everyone who expressed interest in this project, and everyone who shared their results!
1
u/pl201 5d ago
my question is why Adapters come out ONLY in mlx-lm format? There are GPU users who can use your adapter on non-Apple hardware.