180B Parameters, 32GB of RAM: Pushing MoE Inference to the Limit with Transformers

In one sentence

The author implemented SSD streaming for MoE experts in Transformers, enabling a 180B-parameter model to run on a 32GB Mac with speeds close to Strata.

Key points

  • The author benchmarked MoE offloading strategies across Strata, llama.cpp, vLLM, and Transformers when models exceed memory.
  • Transformers' default Accelerate offloading copies an entire layer's expert bank per token, resulting in poor performance.
  • The author introduced a preallocated slot-pool cache that remaps expert IDs to reuse native grouped_mm kernels without custom matmuls.
  • The streaming path supports multi-threaded SSD prefetching and offline quantization, achieving near-vanilla speeds on OLMoE.
  • Submitted as a Transformers PR, the solution enables running the 180B Qwen3.8-Flash-Next model on a 32GB Mac.

In depth

An AI-written overview of the original article, not the article itself.

A Hugging Face blog post details an experiment that runs the roughly 180B-parameter Qwen3.8-Flash-Next MoE model on a 32GB MacBook M5. By streaming routed experts directly from an SSD in Transformers, the setup reaches within 6% of Strata's token generation speed.

Limits of Existing Engines

The author wanted to run large coding models locally on a laptop, but existing tools struggle when MoE experts exceed RAM. According to the post, llama.cpp suffers from page cache thrashing when experts spill to disk, vLLM lacks a disk tier and caching, and Transformers with Accelerate copies an entire layer's expert bank per token.

Core Design and Optimizations

To fix this, the author opened Transformers PR #50717 to stream only routed experts from disk using eight I/O threads. A key idea is the slot pool: a preallocated device tensor shared across layers with a mapping table, allowing the native grouped_mm kernel to run unchanged.

For Qwen3.8-Flash-Next, experts are quantized to 3-bit on disk with a 12 GiB device cache, while the 51 GB n-gram table stays on disk. Further gains came from committing MPS GPU work early, runtime-compiled Metal kernels, switching to Strata's GGUF weights, and prefetching experts, keeping peak memory at 25.4 GiB.

Benchmarks and Bottlenecks

On the M5 MacBook, short decode speed rose from 10.0 tok/s to 13.9 tok/s, trailing Strata's 14.8 tok/s by 6%, while 4K prefill reached 228 tok/s, slightly ahead of Strata. However, PyTorch's MPS backend lacks per-layer sync events, leaving roughly 10 ms of host round-trip overhead per token, making around 14 tok/s still too slow for the author's coding agent workflow.

Read originalOpens huggingface.co

This summary was generated by AI from the original article and may contain errors; the original is authoritative. Copyright belongs to the original author.

Recent stories from this source