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

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Back to Articles 180B Parameters, 32GB of RAM: Pushing MoE Inference to the Limit with Transformers Published November 18, 2026 Update on GitHub Upvote 6 Tarek Ziadé tarekziade Follow Streaming MoE experts directly from SSD gets within 6% of Strata on token generation.

返回文章:180B 参数,32GB 内存:利用 Transformers 将 MoE 推理推向极限。发布于 2026 年 11 月 18 日,GitHub 更新,点赞 6 次,作者 Tarek Ziadé。直接从 SSD 流式传输 MoE 专家模型在生成 token 时的性能已达到 Strata 的 94%。

I’ve been trying to rely less on online models and run bigger ones locally. At home I have a PC with two RTX 4090s (let’s call it Orthrus - the two-headed hound of Greek mythology), and for work I have a MacBook M5 with 32G of unified memory. Orthrus runs on Windows 11, because my kids play games all the time. I had a dual boot with Ubuntu, but their games ended up taking most of the two terabytes of disk.

我一直试图减少对在线模型的依赖,转而在本地运行更大的模型。我在家里有一台配备两块 RTX 4090 的电脑(我们称之为 Orthrus——希腊神话中的双头犬),工作时则使用一台拥有 32GB 统一内存的 MacBook M5。Orthrus 运行的是 Windows 11,因为我的孩子们总是在玩游戏。我曾经安装过 Ubuntu 双系统,但他们的游戏最终占用了两 TB 硬盘的大部分空间。

I am also a huge fan of RMD (rooms moving development): one hour in the kitchen sipping my coffee, two hours at my office desk, then the sofa. A fixed desktop tower is not for me. My first experiment was to run Qwen 3.8 27B with llama.app on Orthrus and use it from my laptop through pi. That model does the coding tasks, an online model like Opus does the orchestration, and the second RTX runs a FIM model for auto-completion in Neovim.

我也是“移动办公开发”(RMD)的忠实拥趸:在厨房喝着咖啡工作一小时,在办公桌前工作两小时,然后转战沙发。固定的台式机并不适合我。我的第一次实验是在 Orthrus 上使用 llama.app 运行 Qwen 3.8 27B,并通过 pi 从笔记本电脑上调用它。该模型负责编码任务,像 Opus 这样的在线模型负责编排,第二块 RTX 显卡则运行一个 FIM 模型,用于 Neovim 中的自动补全。

When I talked about this on social networks, I got very strong feedback: use Strata with Qwen3.8-Flash-Next. What is Strata? Strata is an inference engine for MoE models like Qwen. Only the hot experts stay in VRAM, the rest goes to RAM, or even to disk. Experts are 90%+ of a MoE model’s weights, so a 180B model like this one can run on a GPU with much less memory. Like my RTX 4090!

当我在社交网络上谈论这件事时,得到了非常强烈的反馈:使用 Strata 配合 Qwen3.8-Flash-Next。什么是 Strata?Strata 是一个针对 Qwen 等 MoE 模型的推理引擎。只有活跃的专家模型保留在显存(VRAM)中,其余部分则存入内存(RAM)甚至磁盘。专家模型占 MoE 模型权重的 90% 以上,因此像这样 180B 的模型可以在显存较小的 GPU 上运行,比如我的 RTX 4090!

It works on a laptop too, and I stumbled on this blog post doing exactly that: Qwen3.8-Flash-Next on a 32 GB Mac M4, faster than llama.cpp, at 13.5 tok/s. That’s too slow for how I use coding agents, but it’s an interesting itch to scratch. A whole range of MoE models don’t fit in a MacBook’s unified memory and could run at a decent speed. How do other engines offload?

它在笔记本电脑上也同样适用,我偶然发现了一篇博客文章,正是这样做的:在 32GB 内存的 Mac M4 上运行 Qwen3.8-Flash-Next,速度比 llama.cpp 更快,达到 13.5 tok/s。对于我使用编码代理的方式来说,这个速度太慢了,但这是一个值得尝试的有趣挑战。许多 MoE 模型无法完全装入 MacBook 的统一内存,但却能以不错的速度运行。其他引擎是如何进行卸载(offload)的呢?

Before committing to Strata, I looked at what llama.cpp, vLLM and Transformers do when a MoE model doesn’t fit. Three questions matter: where do the experts live, where does the expert matmul run, and what moves on each token? llama.cpp maps the GGUF file with mmap and can keep the experts on the CPU (—cpu-moe, —n-cpu-moe N, -ot “exps=CPU”, or —fit on to pick for you). Those experts are also computed on the CPU, so only the activations cross PCIe, never the weights.

在决定使用 Strata 之前,我研究了当 MoE 模型无法完全装入时,llama.cpp、vLLM 和 Transformers 是如何处理的。三个问题至关重要:专家模型存放在哪里?专家矩阵乘法(matmul)在哪里运行?每个 token 处理时会有什么数据移动?llama.cpp 使用 mmap 映射 GGUF 文件,并可以将专家模型保留在 CPU 上。这些专家模型也在 CPU 上计算,因此只有激活值会跨越 PCIe 总线,权重则不会。

Great when the experts fit in RAM. When they don’t, the page cache thrashes. A GPU expert cache (—moe-cache-mib) just landed, but it fragments the graph (2 splits per token become 50) and loses ~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 PCIe. For a MoE layer, that’s only the routed experts, but nothing is cached: a hot expert crosses PCIe again on every token, and there’s no disk tier.

当专家模型能装入内存时,这很棒。如果装不下,页面缓存就会频繁抖动。GPU 专家缓存功能(—moe-cache-mib)刚刚发布,但它会使计算图碎片化(每个 token 的 2 次拆分变成 50 次),即使在完全装入的情况下也会损失约 10% 的性能。vLLM 的 —cpu-offload-gb N 将 N GB 的权重放入固定内存(pinned RAM),内核通过 PCIe 原地读取它们。对于 MoE 层,这仅涉及被路由的专家模型,但没有任何缓存:活跃的专家模型在每个 token 处理时都会再次跨越 PCIe,且没有磁盘层级。

By default the offloaded weights include dense layers, read on every token; —cpu-offload-params experts keeps it 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 (device_map=“auto”, offload_folder), one module at a time: hooks copy its weights to the GPU before forward. 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.

默认情况下,卸载的权重包括密集层,每个 token 都会读取;使用 —cpu-offload-params experts 可以将其限制为仅专家模型。这适合 vLLM 的大批量处理(无论如何都会触及几乎所有专家),但不太适合单 GPU 上的单用户场景。Transformers 通过 Accelerate(device_map=“auto”, offload_folder)进行卸载,一次处理一个模块:钩子在向前传播前将权重复制到 GPU。对于 MoE,该模块是某一层的所有专家库,因此每个 token 都会复制卸载层的所有专家,尽管只使用其中的 8 或 10 个。

No cache, no notion of routing. And on a Mac, CPU and GPU share the same memory, so “offload to CPU” frees nothing. I 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.

没有缓存,也没有路由的概念。在 Mac 上,CPU 和 GPU 共享同一内存,因此“卸载到 CPU”并不能释放任何空间。我在一台配备 A10G (24GB) 和充足内存的机器上运行了 Qwen3.6-35B-A3B,并对比了各引擎的性能。

Offloading only the experts doubles vLLM’s speed, and FP8 helps on top (half the bytes per expert, more of the model on the GPU). vLLM’s other offload backend, which copies groups of layers ahead of time, ran under 1 tok/s. If the experts fit in RAM, llama.cpp is hard to beat. If they don’t, you have to 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’s Qwen3.8-Flash-Next on a 32 GB Mac, and Transformers couldn’t do it out of the box.

仅卸载专家模型使 vLLM 的速度翻倍,而 FP8 格式进一步提升了性能(每个专家占用的字节数减半,GPU 能容纳更多模型)。vLLM 的另一个预先复制层组的卸载后端,运行速度低于 1 tok/s。如果专家模型能装入内存,llama.cpp 很难被超越。如果装不下,则必须通过有界缓存仅流式传输路由器选中的部分,速度要快到让 SSD 成为瓶颈而非 Python,并理想地重用模型快速的专家内核。这就是 32GB Mac 上的 Qwen3.8-Flash-Next,而 Transformers 原生无法做到这一点。

Making Qwen3.8-Flash-Next work on my 32 GB Mac with Transformers Strata was already too slow for me on the laptop, and Transformers was not going to beat it anytime soon. But the Accelerate path was so far off that I wanted to try fixing offloading in Transformers itself, with the big model on my laptop as the target, knowing it would probably stay too slow for how I work. All of the code was built with AI: the Transformers PR, the model-specific package and the Metal kernels. My part was choosing what to try, reading the profiles, and deciding what to keep. Everything is in a Space: tarekziade/moe-expert-streaming.

为了让 Qwen3.8-Flash-Next 在我的 32GB Mac 上通过 Transformers 运行,我意识到 Strata 在笔记本上对我来说太慢了,而 Transformers 短期内也无法超越它。但 Accelerate 的路径偏差太大,我想尝试直接修复 Transformers 中的卸载机制,以笔记本上的大模型为目标,尽管我知道它可能仍然无法满足我的工作需求。所有的代码都是由 AI 构建的:Transformers 的 PR、特定模型的包以及 Metal 内核。我的工作是选择尝试的方向、阅读分析报告并决定保留什么。所有内容都在这个 Space 中:tarekziade/moe-expert-streaming。

Start small I started with OLMoE-1B-7B, which fits in memory, so I could compare every token with vanilla Transformers. First version: experts on disk, an LRU cache on the device, and a Python loop running one expert at a time. With every expert already cached, it did 10.1 tok/s. Vanilla did ~32. The I/O was fine, my loop was not: vanilla uses grouped_mm, which runs all the experts of a layer in one kernel. The fix, and the key idea of this 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 as is. No custom expert matmul needed. That got it to 34.6 tok/s, against 38.1 for vanilla. experts_offload I then turned the standalo

从小处着手:我从 OLMoE-1B-7B 开始,因为它能装入内存,这样我就可以将每个 token 与原生 Transformers 进行对比。第一个版本:专家模型在磁盘上,设备上有 LRU 缓存,并使用 Python 循环一次运行一个专家。在所有专家都已缓存的情况下,速度为 10.1 tok/s,而原生版本约为 32 tok/s。I/O 没问题,但我的循环有问题:原生版本使用 grouped_mm,它在一个内核中运行一层的全部专家。修复方法以及该项目的核心思想是将缓存转换为槽位池(slot pool):一个由所有层共享的预分配设备张量,加上一个从专家 ID 到槽位的层级映射表。将路由器的专家 ID 重新映射到槽位,池看起来就像一个常规的专家库,因此 grouped_mm 可以直接运行,无需自定义专家矩阵乘法。这使其速度达到了 34.6 tok/s,而原生版本为 38.1 tok/s。随后我将独立版本转换为 experts_offload。