直接从 SSD 流式传输 MoE 专家,其 token 生成速度已接近 Strata 的 94%。
我一直在尝试减少对在线模型的依赖,转而在本地运行更大的模型。在家里,我有一台配备两块 RTX 4090 显卡的 PC(我们就叫它 Orthrus 吧——希腊神话中那只双头猎犬),而工作上我则使用一块拥有 32GB 统一内存的 MacBook M5。
Orthrus 运行的是 Windows 11,因为我的孩子们一直在玩游戏。我曾尝试安装 Ubuntu 进行双系统启动,但他们的游戏最终占用了两块硬盘中的大部分空间(共两太字节)。
我也是“房间移动开发”(RMD)的忠实拥趸:在厨房花一小时喝咖啡,在办公桌前待两小时,然后再去沙发区。固定的台式机塔式机箱并不适合我。
我的第一个实验是在 Orthrus 上使用 llama.app 运行 Qwen 3.8 27B,并通过 pi 从我的笔记本电脑上调用它。该模型负责编码任务,像 Opus 这样的在线模型负责编排,而第二块 RTX 显卡则在 Neovim 中运行一个 FIM(前缀填充)模型用于自动补全。
当我在社交网络上谈论此事时,收到了非常强烈的反馈:使用 Strata 搭配 Qwen3.8-Flash-Next 。
什么是 Strata?
Strata 是一个专为 MoE(混合专家)模型(如 Qwen)设计的推理引擎。只有“热”专家保留在 VRAM(显存)中,其余部分则存入 RAM(内存),甚至磁盘。由于专家占据了 MoE 模型权重的 90% 以上,因此像这样拥有 180B 参数的模型可以在显存较小的 GPU 上运行。比如我的 RTX 4090!
它在笔记本电脑上也能工作,我偶然发现了一篇博客文章,正好演示了这一点:在 32 GB 内存的 Mac M4 上运行 Qwen3.8-Flash-Next ,速度比 llama.cpp 快,达到 13.5 tok/s。
对于我使用编码代理的方式来说,这太慢了,但这确实是一个值得去解决的有趣痛点。一系列 MoE 模型无法放入 MacBook 的统一内存中,但若能以不错的速度运行,将极具价值。
其他引擎是如何卸载的?
在决定采用 Strata 之前,我查看了 llama.cpp、vLLM 和 Transformers 在 MoE 模型无法完全装入显存时所做的处理。有三个关键问题:专家存储在哪里?专家的矩阵乘法在哪里执行?每个 token 传输什么数据?
llama.cpp 使用 mmap 映射 GGUF 文件,可以将专家保留在 CPU 上(通过 --cpu-moe 、 --n-cpu-moe N 、 -ot "exps=CPU" 或 --fit on 参数让系统自动选择)。这些专家也在 CPU 上进行计算,因此只有激活值会跨越 PCIe 总线,权重永远不会传输。当专家能放入 RAM 时,效果很好。但当放不下时,页面缓存会发生抖动(thrashing)。最近推出的 GPU 专家缓存功能( --moe-cache-mib )虽然解决了部分问题,但会导致图结构碎片化(每个 token 从 2 个分裂变为 50 个),即使所有数据都能装入时也会损失约 10% 的性能。
vLLM 的 --cpu-offload-gb N 将 N GB 的权重放入固定内存(pinned RAM)中,内核通过 PCIe 就地读取它们。对于 MoE 层来说,这只是被路由到的专家,但没有任何缓存机制:一个热专家会在每个 token 上再次跨越 PCIe 总线传输,且没有磁盘层级。默认情况下,卸载的权重包括密集层,每个 token 都会读取;使用 --cpu-offload-params experts 参数可将其限制为仅专家部分。这符合 vLLM 的大批量处理需求,因为大批量无论如何都会触及几乎所有专家,但对于单个用户在单张 GPU 上的场景则不太适用。
Transformers 通过 Accelerate( device_map="auto" , offload_folder )进行卸载,一次一个模块:钩子会在 forward 之前将其权重复制到 GPU。对于 MoE 而言,该模块是整个层的整个专家库,因此每个 token 都会将每个卸载层的所有专家复制到 GPU,以便从中使用 8 或 10 个。没有缓存,也没有路由的概念。而且在 Mac 上,CPU 和 GPU 共享同一内存,因此“卸载到 CPU”实际上释放不了任何资源。
我在一张 A10G(24 GB)显卡上对所有引擎进行了测试,配备充足的 RAM,Harry Mellor 则使用更优的参数重新运行了 vLLM:
| 引擎 | 解码速度 (tok/s) |
|---|---|
| Strata, Q8_0 | 82 - 88 |
| llama.cpp, Q8_0, --fit on | 63 - 64 |
| llama.cpp, BF16, --fit on | 35 - 36 |
| vLLM, FP8, --cpu-offload-gb 16 --cpu-offload-params experts | 20.1 |
| vLLM, FP8, 相同参数, --enforce-eager | 14.7 |
| vLLM, FP8, --cpu-offload-gb 16 | 9.7 |
| vLLM, BF16, --cpu-offload-gb 50 --cpu-offload-params experts | 7.3 |
| vLLM, BF16, --cpu-offload-gb 50 | 3.3 |
| Transformers + Accelerate | 0.16 |
仅卸载专家模块即可使 vLLM 的速度翻倍,而 FP8 格式在此基础上进一步提升了性能(每个专家的字节数减半,模型在 GPU 上的占用率更高)。vLLM 的另一种卸载后端会提前复制层组,其运行速度低于每秒 1 个 token。
如果专家模块能装入内存,llama.cpp 几乎无可匹敌。如果装不下,你就必须通过受限缓存流式传输路由器选中的部分,且速度要足够快,以确保 SSD 成为瓶颈而非 Python。理想情况下,还应复用模型的高速专家内核。这是在 32 GB Mac 上运行 Qwen3.8-Flash-Next 的情况,而 Transformers 库无法开箱即用实现这一点。
在配备 32 GB 内存的 Mac 上使用 Transformers 让 Qwen3.8-Flash-Next 正常运行
Strata 在我的笔记本电脑上已经太慢了,而 Transformers 短期内也无法超越它。但由于 Accelerate 路径的实现差距太大,我想尝试修复 Transformers 本身的卸载功能,以我的笔记本电脑上的大模型为目标,尽管我知道它对于我的工作方式来说可能仍然太慢。
所有代码均由 AI 构建:包括 Transformers 的 PR、特定于模型的包以及 Metal 内核。我负责的部分是选择尝试的内容、阅读性能分析数据以及决定保留哪些部分。所有内容都在一个 Space 中:tarekziade/moe-expert-streaming 。
从小处着手
我从 OLMoE-1B-7B 开始,因为它可以装入内存,所以我可以将每个 token 与原生 Transformers 进行比较。
第一个版本:专家模块存储在磁盘上,设备上有 LRU 缓存,Python 循环一次运行一个专家。在专家已全部缓存的情况下,速度为每秒 10.1 个 token。原生版本约为 32。I/O 没问题,问题出在我的循环上:原生版本使用 grouped_mm ,它在一个内核中运行层的所有专家。
修复方案以及本项目的核心思想是将缓存转变为槽位池(slot pool):一个由所有层共享的预分配设备张量,加上一个从专家 ID 到槽位的每层表。将路由器的专家 ID 重新映射到槽位后,该池看起来就像一个常规的专家库,因此 grouped_mm 可以直接在其上运行。无需自定义专家矩阵乘法。这使得速度达到了每秒 34.6 个 token,而原生版本为 38.1。
experts_offload
随后,我将独立加载器变为 from_pretrained 的一个选项,提交到了 huggingface/transformers#50717 。要尝试它,请从该 PR 安装 Transformers:
pip install "git+https://github.com/huggingface/transformers.git@refs/pull/50245/head"
然后,从 OLMoE 转向真正的目标 Qwen3.8-Flash-Next:
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" ,
},
)
该仓库保存了项目转换脚本的输出:密集权重、量化为 3 位的专家模块以及 n-gram 表。
映射到“disk”的专家模块通过流式传输路径而非 Accelerate 的卸载机制进行处理:加载器跳过它们的张量,MoE 层切换到卸载后的实现。未命中项由 8 个 I/O 线程读取,每个专家进行一次连续读取。接下来两层的路由器会在当前隐藏状态上提前运行,以猜测要预取哪些专家。专家模块可以离线量化,从而使读取数据量更小。它适用于具有标准专家布局的 MoE 模型。
该 API 仍在与 Transformers 维护者讨论中。device_map 的形式便源于此讨论,而量化后的专家模块可能会通过 #50245 中的每层量化计划,而不是作为单独的选项。
在 32 GB Mac 上运行 121 GB 的专家模块
Qwen3.8-Flash-Next 拥有 48 层,每层 512 个专家(其中 10 个处于激活状态),FP8 格式下大小为 121 GB。仅流式传输它们还不够:还有一个需要独立磁盘路径的 51 GB n-gram 嵌入表。因此:
专家模块量化为 3 位:49 GB 存储在磁盘上,12 GiB 缓存在设备上
密集层使用 8 位(约 5.4 GB,与 BF16 相比困惑度增加 0.2%)
n-gram 表保留在磁盘上,按需读取行
转换过程大约需要5小时。加载后,它占用约18 GiB内存,而处理6K提示时峰值达到25.4 GiB。这差不多是极限了:我必须关闭浏览器,否则macOS就会开始进行内存交换。
模型特定的部分(n-gram表、Metal内核)位于PR之上的一个小包moe-expert-streaming中。第一个版本的运行速度约为10 tok/s。
然后我在同一台M5上安装了Strata,使用相同的提示:
Transformers
Strata
差距
解码,200个token
10.0 tok/s
14.8
1.5倍
预填充,4K提示
68 tok/s
220
3.2倍
在6K文档后解码
7.3 tok/s
13.7
1.9倍
Strata 0.1.60使用了IQ3_XXS专家。两者都使用贪婪解码,关闭了思考、MTP和投机草稿,并使用1,024-token的预填充块。完整的设置和原始结果在Space的详情页面中。
我还尝试了vllm-metal,即通过MLX在Apple GPU上运行的vLLM,它最近获得了专家卸载功能。它像这个项目一样,通过有界缓存从MLX检查点流式传输路由专家。但由于上述n-gram原因,它无法在32 GB内存上运行Qwen3.8-Flash-Next:只有专家被流式传输,而n-gram表保留在内存中。Hub上的MLX检查点需要32 GB,再加上约5 GB的密集层和任何专家缓存。
缩小差距
大部分时间并没有花在专家上。以下是有帮助的因素:
尽早提交GPU工作。MPS上的PyTorch会将小内核保留到下一次同步,因此当Python工作时GPU处于空闲状态。在每个块后强制提交带来了10%的提升。这应该在PyTorch中得到修复。
macOS上没有快速路径部分的Metal内核:Gated DeltaNet和超连接。
Strata自己的权重。我切换到了Strata的GGUF权重,将每个token的密集权重流量从5.4 GB减少到3.9 GB,单个专家大小从2.15 MB减少到1.75 MB,并为每个专家大小设置了单独的缓存池。
预填充,我们使用更大的块,并在计算当前层的同时读取下一层的专家,速度从68提升到约228 tok/s。
长文档:仅对索引器选择的块进行注意力计算,KV缓存就地增长而不是在每个token时复制。
未命中:Strata不隐藏它们,它像我一样等待,没有缓存策略比LRU好多少。有帮助的是每层只读取一个猜测的专家,否则SSD将处于空闲状态。
以下是现在运行时的单个token的一个MoE层:
这些是在同一台M5上使用相同提示经过这些优化后的最终结果:
Transformers
Strata
差距
解码,200个token
13.9 tok/s
14.8
1.06倍
预填充,4K提示
228 tok/s
220
1.0倍
在6K文档后解码
12.4 tok/s
13.7
1.1倍
在短解码方面落后Strata约6%,预填充略快,全部通过Transformers实现。
剩下的主要是主机往返开销,每个token约10毫秒。同步后唤醒仅占其中的约1毫秒。其余时间是GPU在Python排队下一层时处于空闲状态。Strata提前为整个token的工作排队,而GPU在每个层等待Metal共享事件,同时主机读取专家。PyTorch没有暴露这一点。我尝试用内核自旋在一个CPU写入的标志上来模拟它,但GPU需要一到永远才能看到写入。真正的修复需要在PyTorch的MPS流上有一个原生操作,但有挂起的风险,所以我还没有构建它。
结论
它以约14 tok/s的速度运行,接近Strata,但对于我使用编码代理的方式来说仍然太慢。Orthrus仍在做真正的工作。
Transformer 并未击败 Strata,而要缩小最后约 6% 的差距,需要在技术栈中进行更深层的变革,首先要解决的是对每层同步的控制权,而目前的 PyTorch 无法提供这一功能。有趣的部分在于它如何做到如此接近:仅流式传输路由专家、一个由 grouped_mm 直接运行的有界缓存,以及几个针对性的 Metal 内核。该项目中没有 C++ 扩展:只有 Python、使用 torch.mps.compile_shader 在运行时编译的 Metal 内核,以及来自 Hub 的预构建内核。所有为本实验编写的 Metal 内核现已发布在 Hub 上,项目从中加载它们。
然而,击败 Strata 从来不是唯一的目标。构建这个项目是学习从系统角度理解 MoE 和 LLM 工作原理的好方法:路由到底有多稀疏、专家缓存能带来多少收益、每个 token 的内存带宽去向何处,以及主机和 GPU 互相等待花费了多少时间。Transformers 让这一切变得容易,可以逐个模块地进行探查。
通用的专家流式传输实现位于 huggingface/transformers#50717 ,基准测试位于该 Space 。欢迎对该方法和 API 提供反馈。
感谢 Pedro、Lysandre 和 Arthur 提供的出色反馈,以及 Harry 帮助测试 vLLM。
最后,感谢 Niko Veit 开发了 Strata 。Strata 设定了消费级硬件上专家流式传输可能性的标杆,而拥有这些值得追赶的数据正是推动这项工作取得如此进展的动力。
Streaming MoE experts directly from SSD gets within 6% of Strata on token generation.
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.
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.
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!
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?
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. 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. 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.
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:
Engine
Decode (tok/s)
Strata, Q8_0
82 - 88
llama.cpp, Q8_0, --fit on
63 - 64
llama.cpp, BF16, --fit on
35 - 36
vLLM, FP8, --cpu-offload-gb 16 --cpu-offload-params experts
20.1
vLLM, FP8, same flags, --enforce-eager
14.7
vLLM, FP8, --cpu-offload-gb 16
9.7
vLLM, BF16, --cpu-offload-gb 50 --cpu-offload-params experts
7.3
vLLM, BF16, --cpu-offload-gb 50
3.3
Transformers + Accelerate
0.16
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.
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 .
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 standalone loader into an option of from_pretrained , in
huggingface/transformers#50717 .
To try it, install Transformers from that PR:
pip install "git+https://github.com/huggingface/transformers.git@refs/pull/50717/head"
Then, moving from OLMoE to the real target, Qwen3.8-Flash-Next:
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" ,
},
)
That repo
holds the output of the project's
conversion script :
the dense weights, the 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 MoE layers switch to an offloaded
implementation. Misses are read by 8 I/O threads, 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. It works for MoE models with the standard experts layout.
The API is still being discussed with the Transformers maintainers. The
device_map form came out of that, and quantized experts will probably go
through the per-layer quantization plan of
their own option.
Running 121 GB of experts on a 32 GB Mac
Qwen3.8-Flash-Next has 48 layers of 512 experts (10 active), 121 GB in FP8.
Streaming them isn't enough: there's also a 51 GB n-gram embedding
table that needs its own disk path. So:
experts quantized to 3 bits: 49 GB on disk, 12 GiB cached on the device
dense layers in 8 bits (~5.4 GB, +0.2% perplexity vs BF16)
the n-gram table stays on disk, rows read when needed
The conversion takes ~5 hours. After loading, it uses ~18 GiB, and a 6K prompt
peaks at 25.4 GiB. That's about the limit: I have to close the browser, or macOS
starts swapping.
The model-specific bits (the n-gram table, Metal kernels) live in a small
package, moe-expert-streaming ,
on top of the PR. The first version ran at about 10 tok/s.
Then I installed Strata on the same M5, with the same prompts:
Transformers
Strata
Gap
Decode, 200 tokens
10.0 tok/s
14.8
1.5x
Prefill, 4K prompt
68 tok/s
220
3.2x
Decode after a 6K document
7.3 tok/s
13.7
1.9x
Strata 0.1.60 used IQ3_XXS experts. Both ran greedy, with thinking, MTP and
speculative drafts off, and 1,024-token prefill chunks. The full setup and raw
results are on the Space's
details page .
I also tried vllm-metal , vLLM on
Apple GPUs through MLX, which recently got expert offloading. It streams the
routed experts from an MLX checkpoint through a bounded cache, like this
project. But it can't 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's 32 GB in the MLX checkpoints on the Hub, before the ~5 GB of dense layers and any expert cache.
Closing the gap
Most of the time wasn't spent on experts. Here's what helped:
Committing GPU work early. PyTorch on MPS holds small kernels until the
next sync, so the GPU idled while Python worked. Forcing a commit after each
block gave +10%. This should really be fixed in PyTorch.
Metal kernels for the parts without a fast path on macOS: Gated DeltaNet
and the hyper-connections.
Strata's own weights. I switched to Strata's GGUF weights , reducing dense
weight traffic from 5.4 GB to 3.9 GB per token and individual expert size from
2.15 MB to 1.75 MB, with a separate cache pool for each expert size.
Prefill , we went from 68 to ~228 tok/s using bigger chunks, and reading the next layer's
experts while the current layer is being computed.
Long documents : attention over the indexer's selected blocks only, and a
KV cache that grows in place instead of being copied at every token.
Misses : Strata doesn't hide them, it waits like I do, and no cache policy
beat LRU by much. What helped was reading just one guessed expert per layer,
while the SSD would otherwise be idle.
Here's one MoE layer for one token, as it runs now:
These are the final results after these optimizations on the same M5 with the same prompts:
Transformers
Strata
Gap
Decode, 200 tokens
13.9 tok/s
14.8
1.06x
Prefill, 4K prompt
228 tok/s
220
1.0x
Decode after a 6K document
12.4 tok/s
13.7
1.1x
That's about 6% behind Strata on short decode, with slightly faster prefill,
all through Transformers.
Most of what's left is host round trips, ~10 ms per token. Waking up after a
sync is only ~1 ms 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
doesn't expose that. I tried to fake it with a kernel spinning on a flag the CPU
writes, and the GPU took anywhere from a second to never to see the write. The
real fix would be a native op on PyTorch's MPS stream, with a risk of hangs, so
I haven't built it.
Conclusion
It runs at ~14 tok/s, close to Strata, and it's still too slow for how I use
coding agents. Orthrus keeps doing the real work.
Transformers didn't beat Strata, and closing the last ~6% would take deeper
changes in the stack, starting with control over that per-layer sync, which
PyTorch doesn't give you today. The interesting part is how it got that
close: streaming only the routed experts, a bounded cache that grouped_mm runs
on as is, and a few targeted Metal kernels. There's 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 never the only goal, though. Building this was a great way
to learn how MoEs and LLMs work from a systems perspective: how sparse the
routing really is, how much an expert cache buys you, where memory bandwidth
goes per token, and how much time the host and the GPU spend waiting on each
other. Transformers makes all of that easy to poke at, 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 to Pedro, Lysandre and Arthur for their excellent feedback, and to Harry
for helping test vLLM.
Finally, thanks to Niko Veit for Strata .
Strata set the bar for what's possible with expert streaming on consumer
hardware, and having those numbers to chase is what pushed this work as far as
it went.
| 刊期 | 得分 | 排名 | 结果 |
|---|---|---|---|
| 2026-11-22 | 8.49 | 21 | 入选 |
| 2026-11-21 | 8.77 | 36 | 未入选 |
| 2026-11-20 | 9.22 | 29 | 未入选 |
| 2026-11-19 | 9.95 | 29 | 未入选 |