Transformers PR streams MoE experts from SSD to run 180B Qwen3.8-Flash-Next on a 32GB Mac

The author wanted to rely less on online models and run bigger ones locally. At home there is a PC with two RTX 4090s, which he calls Orthrus; for work he has a MacBook M5 with 32 GB of unified memory. His first setup ran Qwen 3.8 27B on Orthrus and used it from the laptop: that model does the coding tasks, an online model such as Opus does orchestration, and the second RTX runs a fill-in-the-middle model for autocomplete in Neovim. After he described this on social networks, people told him to try Strata with Qwen3.8-Flash-Next.
Strata is an inference engine for MoE models like Qwen. Only the hot experts stay in VRAM; the rest goes to RAM or disk. The author says experts are 90%+ of a MoE model's weights, so a 180B model can run on a GPU with much less memory. He found a blog post doing this on a 32 GB Mac M4, faster than llama.cpp, at 13.5 tok/s. That is too slow for how he uses coding agents, but it was an interesting itch to scratch, since many MoE models do not fit in a MacBook's unified memory.
Before committing to Strata he compared how other engines offload when a MoE model does not fit. llama.cpp maps the GGUF file with mmap and can keep experts on the CPU and compute them there, so only activations cross PCIe. That is great when the experts fit in RAM; when they do not, the page cache thrashes. A new GPU expert cache (--moe-cache-mib) fragments the graph (2 splits per token become 50) and loses about 10% even when everything fits. vLLM's --cpu-offload-gb keeps weights in pinned RAM that kernels read over PCIe; nothing is cached, so a hot expert crosses PCIe again on every token, and there is no disk tier. Transformers offloads through Accelerate one module at a time, and for a MoE that module is a layer's whole expert bank, so every token copies every expert of every offloaded layer to use 8 or 10 of them. There is no cache and no notion of routing. On a Mac, CPU and GPU share memory, so offloading to CPU frees nothing.
He ran all of them on Qwen3.6-35B-A3B on one A10G (24 GB) with plenty of RAM, and Harry Mellor reran vLLM with better flags. Offloading only the experts doubles vLLM's speed, and FP8 helps on top. vLLM's other offload backend, which copies groups of layers ahead of time, ran under 1 tok/s. His conclusion: if the experts fit in RAM, llama.cpp is hard to beat; if not, you have to stream only what the router picks, through a bounded cache, fast enough that the SSD is the bottleneck, ideally reusing the model's fast expert kernels. Transformers could not do that out of the box.
So he set out to fix offloading in Transformers itself, knowing the result would probably stay too slow for his own work. All the code (the Transformers PR, the model-specific package and the Metal kernels) was built with AI; his part was choosing what to try, reading profiles and deciding what to keep. He started with OLMoE-1B-7B, which fits in memory, so each token could be compared with vanilla Transformers. The first version, with experts on disk, an LRU cache on the device and a Python loop running one expert at a time, did 10.1 tok/s with every expert cached, against about 32 for vanilla. The I/O was fine; the loop was the problem, because vanilla uses grouped_mm, which runs all of a layer's experts in one kernel. The key idea of the project was to turn the cache into a slot pool: one preallocated device tensor shared by all layers, plus a per-layer table from expert id to slot. Remap the router's expert ids to slots and the pool looks like a regular expert bank, so grouped_mm runs on it unchanged. That reached 34.6 tok/s against 38.1 for vanilla. He then turned the standalone loader into an option of from_pretrained in huggingface/transformers#50717.
For the real target, Qwen3.8-Flash-Next has 48 layers of 512 experts (10 active), 121 GB in FP8, plus a 51 GB n-gram embedding table that needs its own disk path. The setup quantizes experts to 3 bits (49 GB on disk, 12 GiB cached on the device), puts dense layers in 8 bits (about 5.4 GB, +0.2% perplexity versus BF16) and keeps the n-gram table on disk, reading rows when needed. Conversion takes about 5 hours. After loading, the model uses about 18 GiB, and a 6K prompt peaks at 25.4 GiB, which is about the limit: he has to close the browser or macOS starts swapping. Cache misses are read by 8 I/O threads, one contiguous read per expert, and the next two layers' routers run early on the current hidden states to guess which experts to prefetch. The first version ran at about 10 tok/s. He also tried vllm-metal, which streams routed experts from an MLX checkpoint, but it cannot run this model on 32 GB because the n-gram tables stay in memory.
What closed the gap to Strata: forcing a GPU commit after each block on PyTorch MPS (+10%, since small kernels were held until the next sync); Metal kernels for Gated DeltaNet and the hyper-connections; switching to Strata's GGUF weights, which cut dense weight traffic from 5.4 GB to 3.9 GB per token and expert size from 2.15 MB to 1.75 MB; prefill going from 68 to about 228 tok/s with bigger chunks and reading the next layer's experts during compute; attention over only the indexer's selected blocks plus an in-place KV cache for long documents; and reading one guessed expert per layer while the SSD would otherwise be idle. No cache policy beat LRU by much.
On the same M5 with the same prompts (Strata 0.1.60 with IQ3_XXS experts; both greedy, thinking, MTP and speculative drafts off, 1,024-token prefill chunks), the Transformers path runs at about 14 tok/s, about 6% behind Strata on short decode, with slightly faster prefill. What remains is mostly host round trips, about 10 ms per token; waking after a sync is only about 1 ms of that. The rest is the GPU running dry while Python queues the next layer, whereas Strata queues a whole token's work up front. A kernel spinning on a CPU-written flag failed because the GPU took anywhere from a second to never to see the write. The real fix, a native op on PyTorch's MPS stream, risks hangs, so he has not built it.
He concludes that it is still too slow for his coding-agent use, so Orthrus keeps doing the real work, and that Transformers did not beat Strata. The project has no C++ extension: Python, Metal kernels compiled at runtime with torch.mps.compile_shader, and prebuilt kernels from the Hub, where the kernels are now published. He says the broader goal was learning how MoEs work from a systems perspective, and thanks Niko Veit for Strata, Harry Mellor for testing vLLM, and Pedro, Lysandre and Arthur for feedback.
Key facts
- Expert streaming for Transformers (PR huggingface/transformers#50717) runs the 180B Qwen3.8-Flash-Next on a 32 GB MacBook M5 at about 14 tok/s, about 6% behind Strata on short decode, with slightly faster prefill.
- The key idea is a slot pool: one preallocated device tensor shared by all layers, so grouped_mm runs on the cache unchanged. On OLMoE-1B-7B this took speed from 10.1 to 34.6 tok/s, against 38.1 for vanilla Transformers.
- The 121 GB FP8 model is squeezed by 3-bit experts (49 GB on disk, 12 GiB cached), 8-bit dense layers (about 5.4 GB) and an on-disk 51 GB n-gram table; memory use is about 18 GiB after loading and 25.4 GiB peak with a 6K prompt.
- Gains came from committing GPU work early (+10%), custom Metal kernels, Strata's GGUF weights, and prefill going from 68 to about 228 tok/s; about 10 ms per token of host round trips remain.
- The author says ~14 tok/s is still too slow for his coding-agent use, and the API is still being discussed with the Transformers maintainers.
Why it matters
Many MoE models do not fit in a laptop's unified memory, and the stock Transformers offload path (Accelerate) copies every expert of every offloaded layer on every token, with no cache and no use of routing. This work shows that streaming only the routed experts through a bounded cache can bring plain Transformers within about 6% of Strata on short decode on the same M5. The author's route there, a shared slot pool that lets the standard grouped_mm kernel run unchanged, is the reusable idea.
Who it affects
People running large MoE models on a Mac or a single consumer GPU, and Transformers users who want offloading that understands expert routing. The author says it works for MoE models with the standard experts layout. It is also relevant to anyone weighing llama.cpp, vLLM and Strata for offloading, since the post compares how each handles a model that does not fit.
How to use it
Install Transformers from the PR with pip install "git+https://github.com/huggingface/transformers.git@refs/pull/50717/head". Download tarekziade/Qwen3.8-Flash-Next-expert-streaming, which holds the converted dense weights, the 3-bit experts and the n-gram table. Then call AutoModelForCausalLM.from_pretrained on the dense folder with dtype=torch.bfloat16, device_map={"": "mps", "experts.*": "disk"}, a MetalConfig(bits=8) quantization config, and experts_offload with cache_bytes of 12 << 30 and the path to the quantized experts. Converting a model yourself takes about 5 hours. Plan memory carefully: about 18 GiB after loading and 25.4 GiB at the peak with a 6K prompt on the 32 GB Mac, and the author closes his browser to avoid swapping. The benchmarks and full setup are in the Space tarekziade/moe-expert-streaming.
How solid is it
This is a first-person experiment report, not a peer-reviewed result. The numbers come from the author's own runs on one M5 with the same prompts for both engines, and the post says the full setup and raw results are on the Space's details page. The 6% gap is stated for short decode only. All the code was built with AI, with the author choosing what to try, reading profiles and deciding what to keep. The author also says Transformers did not beat Strata.
Risks and caveats
At about 14 tok/s the author considers it too slow for coding agents, and his two-RTX-4090 desktop keeps doing the real work. The API is still being discussed with the Transformers maintainers, and quantized experts will probably move to the per-layer quantization plan of #50245, so the interface may change. Memory is tight: 25.4 GiB peak on a 32 GB machine. Closing the last ~6% would need deeper changes, starting with control over the per-layer sync, which PyTorch does not expose; a native op on PyTorch's MPS stream is the real fix but risks hangs, so it has not been built. The author also notes that if experts fit in RAM, llama.cpp is hard to beat.
“Transformers didn't beat Strata, and closing the last ~6% would take deeper changes in the stack, starting with control over that per-layer sync, which PyTorch doesn't give you today.”
— The post's author, Hugging Face blog