180B Parameters on 32GB of RAM: Extending MoE Inference with Transformers
180B Parameters on 32GB of RAM: Extending MoE Inference with Transformers Published November 18, 2026 Streaming Mixture of Experts (MoE) experts directly from an SSD brought Tra...
By Software Development Team
180B Parameters on 32GB of RAM: Extending MoE Inference with Transformers
Published November 18, 2026
Streaming Mixture-of-Experts (MoE) experts directly from an SSD brought Transformers to within 6% of Strata for token generation on an Apple M5 system.
A local inference setup
The experiments used two systems: a desktop with two RTX 4090 GPUs, referred to as Orthrus, and a MacBook M5 with 32GB of unified memory. Orthrus runs Windows 11 for gaming, while the MacBook provides a portable development environment.
An initial setup ran Qwen 3.8 27B with llama.app on Orthrus. The model was accessed from the MacBook through pi, while the second RTX 4090 handled a fill-in-the-middle model for Neovim autocomplete.
Recommendations to test Strata with Qwen3.8-Flash-Next led to an investigation of how different inference engines offload MoE models.
What Strata does
Strata is an inference engine for MoE models such as Qwen. It keeps frequently used experts in VRAM and places the remaining experts in RAM or on disk. Because experts account for more than 90% of an MoE model's weights, this approach allows a 180B-parameter model to run on a GPU with substantially less memory, including an RTX 4090.
Strata can also run on laptops. One test ran Qwen3.8-Flash-Next on a 32GB Mac M4 at 13.5 tokens per second, faster than llama.cpp. That speed was not sufficient for coding-agent workloads, but it demonstrated that large MoE models could run on systems whose unified memory could not hold the complete model.
How inference engines offload experts
Three questions determine the effectiveness of MoE offloading:
- Where are the experts stored?
- Where is the expert matrix multiplication performed?
- What data moves for each token?
llama.cpp
llama.cpp maps the GGUF file with mmap and can keep experts on the CPU with options such as --cpu-moe, --n-cpu-moe N, -ot "exps=CPU", or --fit on.
The experts are also computed on the CPU, so only activations cross PCIe. Weights do not need to move. This works well when the experts fit in RAM. When they do not, the page cache can thrash.
A GPU expert cache using --moe-cache-mib was also available, but it fragmented the graph. The number of splits increased from two per token to 50, producing an approximately 10% performance loss even when the complete model fit in memory.
vLLM
With --cpu-offload-gb N, vLLM places N gigabytes of weights in pinned RAM. Kernels read those weights over PCIe. For an MoE layer, only the routed experts need to be accessed, but there is no cache, so a frequently used expert crosses PCIe again for every token.
By default, dense layers are also included in the offloaded weights. The --cpu-offload-params experts option limits offloading to experts. This design suits large batches that access most experts, but is less efficient for one user running on one GPU.
Transformers
Transformers uses Accelerate for offloading through options such as device_map="auto" and offload_folder. The system moves one module at a time to the GPU before forward runs.
For an MoE model, that module can be an entire layer's expert bank. As a result, every token may copy all experts in an offloaded layer even though routing selects only eight or ten of them. There is no expert cache or routing-aware transfer. On a Mac, CPU and GPU share memory, so moving weights to the CPU does not free unified memory.
Benchmark comparison
The engines were tested with Qwen3.6-35B-A3B on one 24GB A10G GPU with ample system RAM. vLLM was rerun with improved flags.
| Engine and configuration | Decode |
|---|---|
| Strata, Q8_0 | 82-88 tok/s |
llama.cpp, Q8_0, --fit on | 63-64 tok/s |
llama.cpp, BF16, --fit on | 35-36 tok/s |
vLLM, FP8, --cpu-offload-gb 16 --cpu-offload-params experts | 20.1 tok/s |
vLLM, FP8, same flags, --enforce-eager | 14.7 tok/s |
vLLM, FP8, --cpu-offload-gb 16 | 9.7 tok/s |
vLLM, BF16, --cpu-offload-gb 50 --cpu-offload-params experts | 7.3 tok/s |
vLLM, BF16, --cpu-offload-gb 50 | 3.3 tok/s |
| Transformers with Accelerate | 0.16 tok/s |
Restricting vLLM offloading to experts more than doubled its speed in the tested configuration. FP8 improved performance further by reducing the bytes transferred per expert and allowing more of the model to remain on the GPU. Another vLLM offload backend, which copies groups of layers in advance, ran below 1 token per second.
When experts fit in RAM, llama.cpp performed strongly. When they do not, an effective approach needs to stream only the experts selected by the router, use a bounded cache, and move data quickly enough that the SSD, rather than Python, becomes the limiting factor. It should also reuse the model's optimized expert kernels.
Implementing expert streaming in Transformers
Strata was already too slow for the intended laptop workflow, while the standard Transformers offloading path performed much worse. The experiment therefore focused on changing Transformers' offloading behavior for a large MoE model, even though the result might remain too slow for coding agents.
The Transformers pull request, model-specific package, and Metal kernels were developed with AI assistance. The implementation work involved selecting experiments, examining profiles, and deciding which changes to retain.
Starting with OLMoE
The first test used OLMoE-1B-7B, which fit in memory and allowed token-by-token comparison with standard Transformers.
The first implementation stored experts on disk, used an LRU cache on the device, and ran one expert at a time in a Python loop. With every expert already cached, it reached 10.1 tokens per second, compared with approximately 32 tokens per second for vanilla Transformers.
The I/O path was not the primary problem. The Python loop prevented use of grouped_mm, the kernel that processes all experts in a layer together.
The solution was a slot pool: one preallocated device tensor shared across layers, accompanied by a per-layer table mapping expert IDs to slots. Router-selected expert IDs are remapped to slots, allowing the pool to appear as a normal expert bank. The existing grouped_mm kernel can then operate on it without a custom expert matrix-multiplication implementation.
This increased performance to 34.6 tokens per second, compared with 38.1 tokens per second for vanilla Transformers.
The experts_offload option
The standalone loader was then integrated as an option for from_pretrained in huggingface/transformers#50717. The experimental version can be installed with:
pip install "git+https://github.com/huggingface/transformers.git@refs/pull/50717/head"
The Qwen3.8-Flash-Next setup used the following configuration:
path = snapshot_download("tarekziade/Qwen3.8-Flash-Next-expert-streaming")
model = AutoModelForCausalLM.from_pretrained(
f"{path}/dense",
dtype=torch.bfloat16,
device_map={"": "mps", "experts.*": "disk"},
quantization_config=MetalConfig(bits=8),
experts_offload={
"cache_bytes": 12 << 30,
"quantized_experts": f"{path}/experts-q3",
},
)
The associated repository contains dense weights, experts quantized to three bits, and an n-gram table produced by a conversion script.
Experts mapped to "disk" use the streaming path instead of Accelerate's standard offload mechanism. The loader skips their tensors, and MoE layers use an offloaded implementation. Cache misses are processed by eight I/O threads, with one contiguous read per expert. Routers in the next two layers run early on the current hidden states to predict experts for prefetching. Offline quantization reduces the amount of data that must be read.
The implementation supports MoE models using the standard experts layout. Its API was still under discussion with Transformers maintainers. The device_map form resulted from that discussion, while quantized experts were expected to move toward the per-layer quantization plan in #50245.
Running 121GB of experts on a 32GB Mac
Qwen3.8-Flash-Next contains 48 layers, each with 512 experts, of which 10 are active. The experts occupy 121GB in FP8. Streaming the experts alone was insufficient because the model also includes a 51GB n-gram embedding table requiring a separate disk-based path.
The configuration used:
- Experts quantized to three bits: 49GB on disk, with 12GiB cached on the device
- Dense layers stored in eight-bit form: approximately 5.4GB, with a 0.2% perplexity increase compared with BF16
- The n-gram table stored on disk, with rows read as needed
Conversion took approximately five hours. After loading, the model used about 18GiB. A 6K-token prompt raised usage to 25.4GiB, close to the system's practical limit. Closing the browser was necessary to prevent macOS from swapping.
The model-specific implementation, including the n-gram table handling and Metal kernels, was placed in the moe-expert-streaming package. The first version ran at approximately 10 tokens per second.
The same M5 system was then tested with Strata using identical prompts:
| Workload | Transformers | Strata | Difference |
|---|---|---|---|
| Decode, 200 tokens | 10.0 tok/s | 14.8 tok/s | 1.5x |
| Prefill, 4K prompt | 68 tok/s | 220 tok/s | 3.2x |
| Decode after a 6K document | 7.3 tok/s | 13.7 tok/s | 1.9x |
Strata 0.1.60 used IQ3_XXS experts. Both systems used greedy decoding with thinking, MTP, and speculative drafts disabled, along with 1,024-token prefill chunks.
The experiment also tested vllm-metal, which runs vLLM on Apple GPUs through MLX and had recently gained expert offloading. It streams routed experts from an MLX checkpoint through a bounded cache, but it could not run Qwen3.8-Flash-Next on a 32GB system because the n-gram tables remained in memory. The MLX checkpoints on the Hub already occupied 32GB before accounting for approximately 5GB of dense layers and the expert cache.
Closing the performance gap
Most of the optimization work focused on components other than the experts:
- Committing GPU work early: PyTorch on MPS delays small kernels until the next synchronization, allowing the GPU to sit idle while Python continues. Forcing a commit after each block improved performance by 10%.
- Metal kernels: Custom kernels covered components without a fast macOS path, including Gated DeltaNet and hyper-connections.
- Strata's weights: Using Strata's GGUF weights reduced dense-weight traffic from 5.4GB to 3.9GB per token and reduced individual expert size from 2.15MB to 1.75MB. Separate cache pools were used for each expert size.
- Prefill: Larger chunks and reading the next layer's experts while computing the current layer increased prefill speed from 68 to approximately 228 tokens per second.
- Long documents: Attention was restricted to the indexer's selected blocks, and the KV cache grew in place rather than being copied for every token.
- Cache misses: No cache policy substantially outperformed LRU. Reading one predicted expert per layer helped keep the SSD busy without reading unnecessary experts.
For one token in one MoE layer, the router selects 10 of 512 experts. Eight may already be in the expert cache, while two are read from the SSD into free cache slots. The GPU then processes the experts from those slots, while the SSD reads one predicted expert for the next layer. That prefetched expert enters the cache only if routing uses it.
After these optimizations, the results on the same M5 system were:
| Workload | Transformers | Strata | Difference |
|---|---|---|---|
| Decode, 200 tokens | 13.9 tok/s | 14.8 tok/s | 1.06x |
| Prefill, 4K prompt | 228 tok/s | 220 tok/s | 1.0x |
| Decode after a 6K document | 12.4 tok/s | 13.7 tok/s | 1.1x |
Transformers reached approximately 6% below Strata for short decode and was slightly faster for prefill.
Remaining limitations
Most of the remaining difference came from host round trips, which took approximately 10 milliseconds per token. Waking after synchronization accounted for only about 1 millisecond. The remainder resulted from the GPU running idle while Python queued the next layer.
Strata queues the complete token's work in advance and uses a Metal shared event at each layer while the host reads experts. PyTorch does not expose the same control. An attempt to emulate it with a kernel that waited for a flag written by the CPU produced inconsistent results, from one second of delay to no observed update. A native operation on PyTorch's MPS stream would be the direct solution, but it would also introduce a risk of hangs.
Conclusion
The implementation reached approximately 14 tokens per second on the M5, close to Strata but still too slow for the intended coding-agent workflow. The desktop system with two RTX 4090 GPUs remained the primary system for that work.
Transformers did not surpass Strata. Closing the remaining approximately 6% would require deeper changes, beginning with control over per-layer synchronization that PyTorch does not currently provide.
The approach that produced the result combined three main ideas: stream only the experts selected by the router, use a bounded cache that existing grouped_mm kernels can process directly, and add targeted Metal kernels. The project used Python and Metal kernels compiled at runtime with torch.mps.compile_shader, without a C++ extension. The generic expert-streaming implementation was proposed in huggingface/transformers#50717.