180 Billion Parameters and 32 GB of RAM Push Mixture of Experts Inference to the Limit with Transformers
A Transformers experiment streams mixture-of-experts weights from SSD on 32 GB RAM, reaching 14 tokens per second within 6 percent of Strata.
Key Takeaways
- A Hugging Face Transformers pull request streams Qwen3.8-Flash-Next mixture-of-experts weights from SSD on a 32 GB MacBook M5, reaching about 14 tokens per second, close to Strata with slightly faster prefill.
- Existing inference engines have limitations for MoE models larger than available memory: llama.cpp works well when experts fit in RAM but thrashes when they do not, vLLM can offload experts to pinned RAM but lacks caching and disk tiers, and Transformers’ default Accelerate offload copies whole module weights without exploiting expert routing.
- The key idea is to stream only the router-selected experts through a bounded cache, making SSD bandwidth the bottleneck rather than Python overhead, while reusing fast expert kernels.
- The experiment shows that large MoE models, such as 180-billion-parameter systems, can run usefully on consumer hardware, though the laptop-based path may still be too slow for demanding coding-agent workflows.
Meta description: A Hugging Face Transformers experiment streams mixture-of-experts weights from SSD on a 32 GB MacBook M5, reaching 14 tokens per second, within 6% of Strata.

Tags: mixture-of-experts, SSD, Strata, Transformers, Qwen3.8-Flash-Next
Featured image: abstract illustration of mixture-of-experts weights streaming from an SSD to GPU memory, with a MacBook and a small cache pool.
For developers who want large language models on consumer hardware, a new project shows mixture-of-experts streaming can run inside Transformers. A Hugging Face Transformers pull request streams Qwen3.8-Flash-Next experts from SSD on a 32 GB MacBook M5 and reaches about 14 tokens per second, about 6% behind Strata on short decode, with slightly faster prefill.
The local setup behind the experiment
The work started from a wish to depend less on online models and run bigger models locally. The home machine is a Windows 11 PC with two RTX 4090 graphics cards, named Orthrus after the two-headed hound in Greek mythology. A dual boot with Ubuntu existed, but games taken by children filled most of the two terabytes of disk. The work machine is a MacBook M5 with 32 GB unified memory. The author likes rooms moving development: one hour in the kitchen with coffee, two hours at an office desk, then the sofa. A fixed desktop tower is not practical.
The first experiment ran Qwen 3.8 27B with llama.app on Orthrus and used it from the laptop through pi. That model handled coding tasks, while an online model like Opus handled orchestration, and the second RTX ran a fill-in-the-middle model for auto-completion in Neovim. When this setup was shared on social networks, the strong feedback was to use Strata with Qwen3.8-Flash-Next.
Why Strata and existing engines set the bar
Strata is an inference engine for mixture-of-experts models like Qwen. Only the hot experts stay in GPU memory, while the rest goes to RAM or even to disk. Experts are 90% or more of a mixture-of-experts model's weights, so a 180B model can run on a GPU with much less memory, including an RTX 4090.
Strata also works on a laptop. A blog post ran Qwen3.8-Flash-Next on a 32 GB Mac M4, faster than llama.cpp, at 13.5 tokens per second. That is too slow for the author's coding-agent workflow, but it suggested a broader point: many mixture-of-experts models do not fit in a MacBook's unified memory, yet they could run at a decent speed if weights are streamed well.
Before committing to Strata, the project examined what llama.cpp, vLLM and Transformers do when a mixture-of-experts model does not fit. Three questions matter: where the experts live, where the expert matrix multiplication runs, and what moves on each token.
| Engine | Where experts can live | Where expert computation runs | What moves per token |
|---|---|---|---|
| llama.cpp | RAM, by mapping the GGUF file with mmap | CPU, when experts are CPU-resident | Activations cross PCI Express; weights do not cross for CPU experts |
| vLLM | Pinned RAM via `--cpu-offload-gb N` | GPU kernels read weights in place over PCI Express | Routed expert weights cross PCI Express, with no cache and no disk tier |
| Transformers | CPU or disk through Accelerate, using `device_map="auto"` and `offload_folder` | GPU during forward pass, after weights are copied | Whole offloaded module weights are copied before use |
llama.cpp can keep experts on the CPU with `--cpu-moe`, `--n-cpu-moe N`, `-ot "exps=CPU"`, or `--fit` to choose automatically. Those experts are also computed on the CPU, so only the activations cross PCI Express, never the weights. That is great when the experts fit in RAM. When they do not, the system page cache thrashes. The GPU expert cache option `--moe-cache-mib` has just landed, but it fragments the graph, changing 2 splits per token into 50, and loses about 10% even when everything fits.
vLLM's `--cpu-offload-gb N` puts N GB of weights in pinned RAM, and kernels read them in place over PCI Express. For a mixture-of-experts layer, that can be only the routed experts, but nothing is cached: a hot expert crosses PCI Express again on every token, and there is no disk tier. By default, the offloaded weights include dense layers, read on every token; `--cpu-offload-params experts` keeps the offload to the experts. That fits vLLM's big batches, which touch almost every expert anyway, less so one user on one GPU.
Transformers offloads through Accelerate, one module at a time. Hooks copy a module's weights to the GPU before forward. For a mixture-of-experts model, 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 the same memory, so "offload to CPU" frees nothing.
All three engines were run on Qwen3.6-35B-A3B on one A10G with 24 GB, with plenty of RAM. Harry Mellor reran vLLM with better flags. Offloading only the experts doubled vLLM's speed, and FP8 helped on top because each expert uses half the bytes and more of the model stays on the GPU. vLLM's other offload backend, which copies groups of layers ahead of time, ran under 1 token per second.
The lesson was simple: if the experts fit in RAM, llama.cpp is hard to beat. If they do not, the system must stream only what the router picks, through a bounded cache, fast enough that the SSD is the bottleneck and not Python, ideally reusing the model's fast expert kernels. That is the path needed for Qwen3.8-Flash-Next on a 32 GB Mac, and Transformers could not do it out of the box.
Building a streaming path in Transformers
Strata was already too slow for the author's laptop workflow, and Transformers was not going to beat it soon. But the Accelerate offload path looked far enough from the goal that the author tried fixing offloading inside Transformers itself, targeting the big model on the laptop while knowing it would probably remain too slow for coding agents.
All of the code was built with AI: the Transformers pull request, the model-specific package and the Metal kernels. The human part was choosing what to try, reading the profiles, and deciding what to keep. Everything is in the project Space `tarekziade/moe-expert-streaming`.
The project started with OLMoE-1B-7B, which fits in memory, so every token could be compared with vanilla Transformers. The first version put experts on disk, used a least recently used cache on the device, and ran a Python loop one expert at a time. With every expert already cached, it reached 10.1 tokens per second. Vanilla Transformers reached about 32. The disk input was fine, but the loop was not: vanilla Transformers uses `grouped_mm`, which runs all the experts of a layer in one kernel.
The fix, and 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. The router's expert ids are remapped to slots, so the pool looks like a regular expert bank, and `grouped_mm` runs on it as is. No custom expert matrix multiplication was needed. That lifted speed to 34.6 tokens per second, against 38.1 for vanilla Transformers.
The standalone loader then became an option of `from_pretrained`, in `huggingface/transformers#50717`. To try it, install Transformers from that pull request. Moving from OLMoE to the real target, Qwen3.8-Flash-Next, required a model-specific conversion output: dense weights, experts quantized to 3 bits, and the n-gram table.
Experts mapped to "disk" go through the streaming path instead of Accelerate's offload. The loader skips their tensors, and mixture-of-experts layers switch to an offloaded implementation. Cache misses are read by 8 input/output threads, with one contiguous read per expert. The next two layers' routers run early on the current hidden states to guess which experts to prefetch. Experts can be quantized offline so reads are smaller. The approach works for mixture-of-experts models with the standard experts layout.
The API is still being discussed with the Transformers maintainers. The `device_map` form came out of that discussion, and quantized experts will probably go through the per-layer quantization plan in `#50245` rather than their own option.
Running Qwen3.8-Flash-Next on a 32 GB Mac
Qwen3.8-Flash-Next has 48 layers of 512 experts, with 10 active per token, and 121 GB in FP8. Streaming the experts alone is not enough: there is also a 51 GB n-gram embedding table that needs its own disk path. The final setup uses experts quantized to 3 bits, leaving 49 GB on disk and 12 gibibytes cached on the device. Dense layers use 8 bits, about 5.4 GB, with 0.2% higher perplexity compared with BF16. The n-gram table stays on disk, and rows are read when needed.
The conversion takes about 5 hours. After loading, the project uses about 18 gibibytes, and a 6,000-token prompt peaks at 25.4 gibibytes. That is about the limit: the browser must be closed, or macOS starts swapping. The model-specific parts, the n-gram table and the Metal kernels, live in the small package `moe-expert-streaming`, on top of the pull request. The first version ran at about 10 tokens per second.
The author then installed Strata on the same M5, using the same prompts. Strata 0.1.60 used IQ3_XXS experts. Both runs used greedy decoding, with thinking, multi-token prediction, and speculative draft modes off, and 1,024-token prefill chunks. The full setup and raw results are on the Space's details page.
The author also tried `vllm-metal`, vLLM on Apple GPUs through MLX, which recently gained expert offloading. It streams the routed experts from an MLX checkpoint through a bounded cache, like the Transformers project. But it cannot run Qwen3.8-Flash-Next on 32 GB for the n-gram reason above: only the experts are streamed, and the n-gram tables stay in memory. That is 32 GB in the MLX checkpoints on the Hub, before about 5 GB of dense layers and any expert cache.
What the result means for local inference
Most of the time was not spent on experts. The biggest gains came from system-level changes. PyTorch's Metal Performance Shaders backend holds small kernels until the next synchronization, so the GPU idled while Python worked. Forcing a commit after each block gave a 10% improvement. The author notes that this should really be fixed in PyTorch.
The project also added Metal kernels for parts that lacked a fast path on macOS: Gated DeltaNet and the hyper-connections. Switching to Strata's GGUF weights reduced dense weight traffic from 5.4 GB to 3.9 GB per token and reduced individual expert size from 2.15 MB to 1.75 MB, with a separate cache pool for each expert size.
Prefill improved from 68 to about 228 tokens per second by using bigger chunks and reading the next layer's experts while the current layer is being computed. For long documents, attention uses only the indexer's selected blocks, and the key-value cache grows in place instead of being copied at every token. For cache misses, Strata does not hide them; it waits, and no cache policy beat least recently used by much. What helped was reading just one guessed expert per layer while the SSD would otherwise be idle.
After these optimizations, the final results on the same M5 with the same prompts were about 6% behind Strata on short decode, with slightly faster prefill, all through Transformers. Most of what is left is host round trips, about 10 milliseconds per token. Waking up after a synchronization is only about 1 millisecond of that. The rest is the GPU running dry while Python queues the next layer. Strata queues the whole token's work up front, and the GPU waits on a Metal shared event at each layer while the host reads experts. PyTorch does not expose that. The author tried to fake it with a kernel spinning on a flag that the CPU writes, and the GPU took anywhere from a second to never to see the write. The real fix would be a native operation on PyTorch's Metal Performance Shaders stream, with a risk of hangs, so it was not built.
The project runs at about 14 tokens per second, close to Strata, and it is still too slow for how the author uses coding agents. Orthrus keeps doing the real work. Transformers did not beat Strata, and closing the last about 6% would take deeper changes in the stack, starting with control over that per-layer synchronization, which PyTorch does not give today.
The interesting part is how close the approach got: streaming only the routed experts, a bounded cache that `grouped_mm` runs on as is, and a few targeted Metal kernels. There is no C++ extension in the project: just Python, Metal kernels compiled at runtime with `torch.mps.compile_shader`, and prebuilt kernels from the Hub. All the Metal kernels written for this experiment are now published on the Hub, and the project loads them from there.
Beating Strata was not the only goal. Building the project was a way to learn how mixture-of-experts and large language models work from a systems perspective: how sparse the routing really is, how much an expert cache buys, where memory bandwidth goes per token, and how much time the host and the GPU spend waiting on each other. Transformers makes that easy to inspect, one module at a time.
The generic expert streaming implementation is in `huggingface/transformers#50717`, and the benchmarks are in the Space. Feedback on the approach and the API is welcome. Thanks are given to Pedro, Lysandre and Arthur for feedback, and to Harry for helping test vLLM. Thanks also to Niko Veit for Strata. Strata set the bar for what is possible with expert streaming on consumer hardware, and having those numbers to chase pushed the work as far as it went.
Comments (0)