Mingyu's Library主页

深度学习文档 · 2026-08-28

Deep Dive · 2026-08-28

稀疏 MoE 开源模型的自托管选型

Self-Hosting Sparse MoE Open-Weight Models

当开源旗舰在编码基准上只落后闭源不到一个百分点、且几乎清一色是稀疏 MoE 架构时,「要不要自托管」第一次变成一道真实的工程与成本题。而 MoE 最深的陷阱是:激活参数只有 49B,显存却要按 1.6T 总参准备。

Now that flagship open-weight models trail closed frontier models by less than a benchmark point on coding — and are almost universally sparse Mixture-of-Experts — "should we self-host?" has become a real engineering and cost question. The deepest MoE trap: only 49B parameters activate, but you still have to hold 1.6T in memory.

主题来源:2026-08-28 AI 每日简报「今日精选主题」 · 全文双语,右上角可切换

Topic selected from the 2026-08-28 AI daily brief · Fully bilingual, toggle at top right

1. MoE 是什么:一句话与一张图

1. What MoE is: one sentence and one diagram

一句话:稀疏 Mixture-of-Experts(混合专家)把 Transformer 里的前馈层(FFN)拆成很多个并列的「专家」,每个 token 经过一个路由器(router / gate),只被送到其中少数几个专家去算,其余专家这一步完全不参与计算。

One sentence: A sparse Mixture-of-Experts (MoE) model replaces the feed-forward layer (FFN) of a Transformer with many parallel "experts." A router (gate) sends each token to only a few of them; the rest do no work on that token at all.

因此一个 MoE 模型有两个必须分开记的数字:总参数(total parameters,决定你要装多少权重进内存)和激活参数(active parameters,决定单 token 前向的算力开销 FLOPs)。DeepSeek-V3 是最经典的说明:6710 亿总参,单次推理只激活约 370 亿,却达到当时前沿闭源模型级别的能力,而计算成本只是其一部分。

So an MoE model has two numbers you must never conflate: total parameters (how much weight you have to hold in memory) and active parameters (the FLOPs cost of a single-token forward pass). DeepSeek-V3 is the canonical illustration: 671B total parameters, roughly 37B active per inference step, reaching frontier-class capability at a fraction of the compute cost.

输入 token 经注意力层后 路由器 Router / Gate 选 top-k 专家 专家 1 ✓激活 专家 2 休眠 专家 3 休眠 专家 4 ✓激活 … 专家 N 休眠 加权求和 → 下一层 显存要装:全部 N 个专家 算力只花:被激活的那 k 个
图 1:稀疏 MoE 的一次前向 —— 路由器只选 top-k 个专家参与计算,但所有专家的权重都必须常驻内存。
Input token after attention Router gating network picks top-k Expert 1 ✓ on Expert 2 idle Expert 3 idle Expert 4 ✓ on … Expert N idle Weighted sum → next layer Memory holds: all N experts Compute pays: only the k that fired
Fig. 1 — One forward pass through a sparse MoE layer: the router activates only top-k experts, yet every expert's weights must stay resident in memory.

2. 最贵的直觉陷阱:激活参数 ≠ 显存

2. The expensive intuition trap: active params ≠ VRAM

这是自托管 MoE 最常见、也最烧钱的误判。看到「49B 激活」,很多人下意识按 49B 稠密模型去估算硬件——大约 100GB 显存(BF16),两张 80GB 卡绰绰有余。但推理时任何一个专家都可能被路由到,所以所有专家权重都必须驻留。1.6T 总参在 BF16 下就是 3TB 量级的权重,即使 FP8 也在 1.6TB 量级,再叠加 KV cache 与激活值,这是一个几十张卡的集群,不是一台工作站。

This is the most common and most expensive misjudgment in self-hosting MoE. Seeing "49B active," people instinctively size hardware like a 49B dense model — roughly 100 GB in BF16, comfortably two 80 GB cards. But at inference any expert may be routed to, so every expert's weights must stay resident. 1.6T total parameters is on the order of 3 TB of weights in BF16, still ~1.6 TB in FP8, before KV cache and activations. That is a multi-node cluster, not a workstation.

量化的经验值:业界普遍观察到,MoE 模型的显存占用大约是同等能力稠密模型的 4~14 倍。换句话说,MoE 用「内存换算力」——你省下的是 FLOPs 和延迟,付出的是容量。Rule of thumb:A MoE-based model typically consumes roughly 4× to 14× more memory than its dense counterpart of comparable quality. MoE trades memory for compute: you save FLOPs and latency, you pay in capacity.

这带来一个反直觉的结论:MoE 让「同样的钱买到更强的模型」在云端 API 上成立,但在自托管上不一定成立。API 厂商用高并发把庞大的权重摊薄到成千上万个请求上;你自己跑一个 QPS 个位数的内部服务,那 3TB 权重就是纯粹的固定成本。

The counter-intuitive consequence: MoE's "more capability per dollar" holds for cloud APIs but not automatically for self-hosting. API providers amortize those enormous weights across thousands of concurrent requests. If you run an internal service at single-digit QPS, those 3 TB of weights are pure fixed cost.

怎么算一笔粗账

A back-of-envelope sizing formula

权重显存 ≈ 总参数 × 每参数字节数
   BF16 = 2 B/param  ·  FP8 = 1 B/param  ·  INT4 ≈ 0.5 B/param

例:1.6T 总参
   BF16 → ≈ 3.2 TB      FP8 → ≈ 1.6 TB      INT4 → ≈ 0.8 TB
再加 KV cache(随 context 长度与并发数线性增长)+ 激活值 + 碎片
   实际预留 ≈ 权重 × 1.2 ~ 1.5

对比同一模型的「算力侧」:单 token FLOPs 只按 49B 激活参数算
weight VRAM ≈ total_params × bytes_per_param
   BF16 = 2 B/param  ·  FP8 = 1 B/param  ·  INT4 ≈ 0.5 B/param

e.g. 1.6T total params
   BF16 → ≈ 3.2 TB      FP8 → ≈ 1.6 TB      INT4 → ≈ 0.8 TB
plus KV cache (linear in context length × concurrency) + activations + fragmentation
   provision ≈ weights × 1.2 – 1.5

Meanwhile the compute side scales with 49B active params only, not 1.6T.

⚠️ 上面是量级估算,不是精确容量规划。真实数字受专家分片策略、KV cache 量化、张量并行切分方式影响很大,务必以你实际使用的推理引擎实测为准。

⚠️ These are order-of-magnitude estimates, not a capacity plan. Real numbers depend heavily on expert sharding strategy, KV-cache quantization, and tensor-parallel layout — always measure on your actual serving engine.

3. 2026 年 8 月的开源格局

3. The open-weight landscape as of August 2026

2026 年的一个结构性事实:几乎每一个旗舰开源模型都是稀疏 MoE。第三方汇总的参数规格如下(总参 / 激活参):

A structural fact about 2026: nearly every flagship open-weight model is a sparse MoE. Specs as compiled by third-party trackers (total / active):

模型总参 / 激活参许可备注
DeepSeek V4-Pro1.6T / 49BMITSWE-bench Verified ≈ 80.6%;1M 上下文;V4-Pro-0813 于 8/13 GA
Mistral Large 3675B / 41BMistral Small 4 面向 2 卡部署
Llama 4 Maverick400B / 17B激活参数比例极低
Qwen 3.5397B / 17BQwen3.8 Max 于 8/2 发布
DeepSeek V4-FlashMIT宣称把近前沿能力带到 2 卡配置
ModelTotal / activeLicenseNotes
DeepSeek V4-Pro1.6T / 49BMIT≈80.6% SWE-bench Verified; 1M context; V4-Pro-0813 GA on Aug 13
Mistral Large 3675B / 41BMistral Small 4 targets 2-GPU setups
Llama 4 Maverick400B / 17BVery low active-parameter ratio
Qwen 3.5397B / 17BQwen3.8 Max shipped Aug 2
DeepSeek V4-FlashMITClaims near-frontier quality on 2-GPU deployments
数据可信度提示:上表的分数与参数来自第三方聚合站点(llm-stats、模型对比博客等),不是官方模型卡。榜单口径(是否用 agent harness、是否多次采样取最优)差异极大,做选型决策前请回到官方发布页与你自己的私有评测集。Confidence note:These figures come from third-party aggregators (llm-stats, comparison blogs), not official model cards. Benchmark methodology varies enormously — agent harness or not, best-of-n or not. Before deciding anything, go back to official release pages and your own private eval set.

被反复引用的一句判断是:开源与闭源的能力差距「现在是以单个 benchmark 分点、而不是以代际来衡量的」。这句话在编码这一个维度上有数据支撑(SWE-bench Verified 上 80.6% vs 80.8%),但把它推广到长上下文推理、工具调用可靠性、多语种、安全对齐等维度是没有依据的。选型时要问的是「在我的任务上差多少」。

The widely quoted line is that the open-versus-closed gap "is now measured in single benchmark points, not generations." That is defensible on coding specifically (80.6% vs 80.8% on SWE-bench Verified), but generalizing it to long-context reasoning, tool-calling reliability, multilingual quality, or safety alignment is unsupported. The question that matters is: how large is the gap on your task.

4. 怎么部署:专家并行与服务栈

4. How to serve it: expert parallelism and the stack

通用的 LLM 服务方式无法高效处理专家路由,因此 vLLM 与 TensorRT-LLM 都在 2025 年起陆续加入了 MoE 专用优化:融合的 MoE kernel、FlashInfer 集成与 kernel autotuning、以及专家并行(expert parallelism, EP)——把不同专家分散到不同 GPU 上,而不是像张量并行那样把每一层横切。

General-purpose LLM serving cannot handle expert routing efficiently, so both vLLM and TensorRT-LLM have been adding MoE-specific work since 2025: fused MoE kernels, FlashInfer integration with kernel autotuning, and expert parallelism (EP) — distributing distinct experts across GPUs rather than slicing every layer as tensor parallelism does.

三种并行方式的分工

How the three parallelism axes divide the work

低显存路线:把 MoE 当「工作集」问题

The low-memory route: treat MoE as a working-set problem

如果你就是没有集群,学术界给出了几条真实可用的方向,共同思路是:既然每步只用少数专家,就不必让全部专家常驻 GPU。

If you simply do not have a cluster, the research literature offers usable directions, all sharing one idea: since only a few experts fire per step, not every expert needs to sit in GPU memory.

代价要说清楚:所有「专家换入换出」方案本质是用 PCIe/CPU 内存带宽换 GPU 显存。它们能让模型跑起来,但单请求延迟通常显著变差,且对突发路由模式敏感。适合离线批处理与个人实验,不适合面向用户的低延迟在线服务。Be honest about the cost:Every expert-offloading scheme trades PCIe/host-memory bandwidth for GPU VRAM. They make the model run, but per-request latency usually degrades sharply and they are sensitive to bursty routing patterns. Good for offline batch and personal experimentation; not for user-facing low-latency serving.

5. 什么场景该自托管:一棵决策树

5. When self-hosting wins: a decision tree

有硬性数据驻留 / 合规要求? 数据不能出境 / 不能给第三方 是 → 自托管是唯一选项 按 FP8 全参预算硬件 否 → 日均 token 量够大吗? GPU 利用率能否长期 > 40% 否 → 用 API 低 QPS 下 3TB 权重 是纯固定成本 是 → 任务维度 你的私有评测集上 差距有多大? 差距小 → 自托管性价比成立 优先 V4-Flash / Small 4 这类 「近前沿 + 少卡」档位 差距大 → 混合路由 简单/高频请求走自托管小模型 难例升级到闭源 API 提醒:先量化再买卡。FP8 让 1.6T 从 ≈3.2TB 降到 ≈1.6TB,常常直接决定「几节点」这个 最贵的变量。
图 2:自托管 MoE 的决策树 —— 合规是硬门槛,利用率是经济门槛,评测差距是质量门槛。
Hard data-residency requirement? data cannot leave your boundary Yes → self-host is the only path budget for full FP8 weights No → enough daily token volume? can GPU utilization stay > 40% No → use an API at low QPS, 3 TB of weights is pure fixed cost Yes → task quality how big is the gap on your private eval set? Small gap → self-hosting pays off prefer the "near-frontier, few-GPU" tier: V4-Flash, Mistral Small 4 Large gap → hybrid routing cheap/high-volume calls self-hosted, hard cases escalate to a closed API Reminder: quantize before you buy. FP8 takes 1.6T from ≈3.2 TB to ≈1.6 TB, which often decides the single most expensive variable: node count.
Fig. 2 — Decision tree for self-hosting MoE: compliance is the hard gate, utilization is the economic gate, eval gap is the quality gate.

三类站得住脚的自托管场景

Three self-hosting cases that hold up

  1. 合规驱动:数据不能出边界。此时不是成本问题,而是可行性问题——按 FP8 全参预算硬件,并接受它。
  2. 高并发同质流量:比如批量文档处理、日志摘要、代码索引。利用率高,权重成本被摊薄,MoE 的低激活参数带来的吞吐优势在这里真正兑现。
  3. 可控性与稳定性:模型版本自己钉死,不会被上游静默升级改变行为;这对已经建了大量提示词与评测的团队价值很高。
  1. Compliance-driven: data cannot cross a boundary. Then it is not a cost question but a feasibility one — budget for full FP8 weights and accept it.
  2. High-volume homogeneous traffic: bulk document processing, log summarization, code indexing. Utilization is high, weight cost amortizes, and MoE's low active-parameter throughput advantage actually materializes.
  3. Control and stability: you pin the model version, so upstream silent upgrades cannot change behavior — valuable for teams with a large investment in prompts and evals.

6. 常见坑与反模式

6. Common pitfalls and anti-patterns

坑 1:按激活参数买卡。最贵的一个错误,见第 2 节。规划容量永远看总参数。Pitfall 1: sizing hardware by active parameters.The single most expensive mistake — see §2. Always plan capacity against total parameters.
坑 2:用榜单分数代替自己的评测。SWE-bench Verified 上差 0.2 分,不代表在你的领域数据、你的工具调用格式、你的中文长文档上也只差 0.2 分。自建 100~300 条的私有评测集是自托管决策的前置条件,不是可选项。Pitfall 2: substituting leaderboards for your own evals.A 0.2-point gap on SWE-bench Verified says nothing about your domain data, your tool-call format, or your long documents. A private eval set of 100–300 cases is a prerequisite for this decision, not an optional extra.
坑 3:忽视专家负载不均。EP 部署下,路由分布偏斜会让少数 GPU 成为瓶颈。上线后必须监控 per-expert 的 token 分配直方图,而不是只看总体 GPU 利用率——后者可能看着「不高」,其实是有几张卡在等另外几张。Pitfall 3: ignoring expert load imbalance.Under expert parallelism, skewed routing turns a few GPUs into bottlenecks. Monitor the per-expert token-assignment histogram, not just aggregate GPU utilization — aggregate can look "low" when in fact most cards are waiting on a few.
坑 4:把 offloading 方案用在在线服务上。FloE / eMoE / WiSP 这类工作让「能跑」成为可能,但单请求延迟代价很大。别拿它当低延迟在线服务的方案。Pitfall 4: putting offloading schemes behind a latency SLA.FloE / eMoE / WiSP make it possible to run at all, but at a steep per-request latency cost. Do not treat them as a low-latency serving solution.
好做法:先租后买。在决定采购之前,用云上按小时的 GPU 把你的真实流量重放一周,拿到实测吞吐、P95 延迟与专家负载分布。这一周的租金,比一次买错集群便宜两个数量级。Good practice: rent before you buy.Before any purchase, replay a week of real traffic on hourly cloud GPUs and collect measured throughput, P95 latency, and expert load distribution. A week of rental is two orders of magnitude cheaper than one wrong cluster.

7. 术语表与来源

7. Glossary and sources

术语表

Glossary

来源

Sources