Running 180B MoE on a 32GB MacBook with Transformers

Hugging Face engineers implemented Slot Pool-based expert streaming in Transformers to run Qwen3.8-Flash-Next (180B, 121GB expert) on a 32GB unified memory MacBook. The existing Accelerate offloading was inefficient due to layer-wise copying, but by reading only the experts selected by the router from the SSD and loading them into pre-allocated device tensors, they achieved 90% performance compared to vanilla (34.6 tok/s vs 38.1 tok/s) using the grouped_mm kernel. Expert 3-bit quantization (49GB), dense layer 8-bit (5.4GB), and n-gram table disk residency reduced peak memory to 25.4GiB.

The Wall of Local Inference and the Opportunities Provided by MoE

Attempts to run large language models locally constantly collide with hardware constraints. The author works between two environments: a dual RTX 4090 (24GB × 2) desktop 'Orthrus' and a 32GB unified memory MacBook M5. The fixed tower had to abandon Ubuntu dual boot due to being pushed aside by idle gaming disks, and the 'RMD (rooms moving development)' workflow requires a laptop for coding on the go.

"Experts account for over 90% of the MoE model weights, allowing even the 180B model to run with significantly less GPU memory."

This statement is key. Qwen3.8-Flash-Next has a structure where only 10 out of 512 experts per layer are activated across 48 layers, with expert weights alone reaching 121GB in FP8. Adding a 51GB n-gram embedding table makes it unmanageable with a single device's memory. Nevertheless, the Strata engine achieved 13.5 tok/s on the 32GB MacBook. This was accomplished through expert streaming at the engine level, solving what was impossible with the basic functionality of Transformers.

Why Existing Engines' Offloading Methods Failed

Before relying on Strata, the author experimented with how llama.cpp, vLLM, and Transformers (Accelerate) handle MoE. The test model was Qwen3.6-35B-A3B, and the hardware was A10G 24GB with sufficient system RAM.

EngineOffloading MechanismExpert Computation LocationCache/PrefetchMajor Limitations
llama.cppGGUF mmap, experts resident on CPU with `--cpu-moe` optionCPUGPU expert cache (recently added) with `--moe-cache-mib`Page cache thrashing when experts exceed RAM, ~10% performance drop due to graph fragmentation when cache is activated
vLLMLoad weights into fixed memory with `--cpu-offload-gb N`, read directly via PCIeGPU (kernel reads CPU memory)None (hot experts cross PCIe per token)Lack of disk tier, optimized for large batch serving, inefficient for single user/single GPU
Transformers (Accelerate)`device_map="auto"`, module-wise copying with `offload_folder`GPU (pre-copied via hook)None, lack of routing conceptCopies the entire expert bank of MoE layers per token, no offloading effect due to CPU/GPU unified memory on Mac

Harry Mellor adjusted the vLLM flag to offload only experts (`--cpu-offload-params experts`), doubling the speed and further improving it with FP8 quantization. However, the conclusion for Transformers was that it was "too slow compared to vanilla to be feasible for coding agents."

Slot Pool: The Key to Solving Bottlenecks

The issue was not I/O. The first prototype managed experts on disk with an LRU cache and executed them one by one in a Python loop. With cache hits, it achieved 10.1 tok/s, while vanilla achieved 32 tok/s. Profiling revealed that the lack of `grouped_mm` kernel was the cause. Vanilla executes all experts within a layer as a single kernel, but the Python loop called kernels for each expert, leading to significant overhead.

The solution is Slot Pool.

1. Single pre-allocated device tensor shared by all layers 2. Maintain a layer-specific expert ID → slot mapping table 3. Remap the expert IDs output by the router to slot indices 4. The pool appears like a regular expert bank, allowing the use of the existing `grouped_mm` as is

Without a custom expert matmul kernel, it restored vanilla 38.1 tok/s → 34.6 tok/s (90.8%). This code was submitted as PR `huggingface/transformers#50717` and integrated with the `from_pretrained` option.

Empirical Evidence of Qwen3.8-Flash-Next: Running 180B on a 32GB MacBook

Moving on to the actual target model, three additional techniques were combined.

Running the conversion script takes about 5 hours. After loading, the base memory usage is ~18 GiB, with a peak of 25.4 GiB for 6K prompts, fitting within the 32GB limit. If the browser is not closed, macOS starts swapping.

Vanilla_OLMoE38.1
Slot_Pool_OLMoE34.6
Strata_Qwen_M413.5

"When experts are mapped to disk, the streaming path is taken, and the loader skips that tensor while the MoE layer switches to offloading implementation. Eight I/O threads handle misses with a single continuous read per expert, and the next two layer routers are executed early from the current hidden state to predict prefetch targets."

Prefetching, quantization, and slot pooling work together to eliminate Python overhead, making SSD bandwidth the bottleneck. The API is still under discussion with maintainers, and quantized experts are expected to be integrated with the `#50245` layer-wise quantization plan.

Remaining Challenges and Developer Guide

The current implementation only applies to MoE models with a standard expert layout. The Mac Metal kernel, model-specific conversion packages, and Transformers PR were all written with AI support, and the author focused on the role of "choosing what to try and reading profiles to decide what to maintain." The entire reproduction environment is publicly available in the space tarekziade/moe-expert-streaming.

For developers looking to try it immediately:

An era of running 180B MoE on a 32GB MacBook has begun. However, the constraint of having to close the browser still remains.

Verified figures

Our take

Transformers native expert streaming has significantly broadened the practical limits of local LLM execution. The ability to run 180B MoE with only 32GB unified memory provides immediate value for both edge device deployment and individual developer workflows. However, the need for tuning prefetch heuristics and quantization schemes per model, along with the ongoing pressure from macOS swapping, are challenges that must be addressed before commercialization.

Open questions

Source

Back to catalog