mixture of experts guide

MoE 混合专家模型选型指南:从 Mixtral 到 DeepSeek

MoE:用稀疏激活实现"大模型能力、小模型成本" MoE(Mixture of Experts)的核心思想:模型总参数很大,但每次推理只激活一小部分。 传统 Dense 模型: 70B 参数 → 每次推理全部参与计算 → 70B 计算量 MoE 模型: 400B 总参数,每次激活 12B → 推理只需 12B 计算量 → "拥有 400B 的能力,付出 12B 的成本" MoE 架构原理 基本结构 输入 Token ↓ ┌─────────────┐ │ Router/Gate │ → 决定激活哪几个专家 └──────┬──────┘ │ ┌───┼───┬───┐ ↓ ↓ ↓ ↓ E1 E2 E3 ... E64 (专家网络,每个是一个 FFN) │ │ │ │ └───┴───┴───┘ ↓ 加权合并输出 class MoELayer(nn.Module): def __init__(self, num_experts=8, top_k=2, d_model=4096): super().__init__() self.gate = nn.Linear(d_model, num_experts) self.experts = nn.ModuleList([ FFN(d_model) for _ in range(num_experts) ]) self.top_k = top_k def forward(self, x): # Gate 计算每个专家的权重 gate_logits = self.gate(x) # [batch, seq, num_experts] weights, indices = torch.topk( F.softmax(gate_logits, dim=-1), self.top_k ) # 只激活 top-k 个专家 output = torch.zeros_like(x) for i in range(self.top_k): expert_idx = indices[..., i] weight = weights[..., i] for b in range(x.size(0)): for s in range(x.size(1)): expert = self.experts[expert_idx[b, s]] output[b, s] += weight[b, s] * expert(x[b, s]) return output 关键设计决策 决策 选项 影响 专家数量 8 / 16 / 64 / 256 更多专家 = 更大容量 + 更高显存 Top-K 1 / 2 / 4 更高 K = 更好质量 + 更多计算 专家粒度 粗(整个FFN) / 细(注意力头) 细粒度 = 更灵活路由 共享专家 有 / 无 共享专家处理通用知识 主流 MoE 模型对比 模型 总参数 激活参数 专家数 Top-K 上下文 许可证 Mixtral 8x7B 47B 13B 8 2 32K Apache 2.0 Mixtral 8x22B 141B 39B 8 2 64K Apache 2.0 DeepSeek-V3 671B 37B 256 8 128K MIT Qwen3-MoE-A14B 57B 14B 49 4 128K Apache 2.0 Grok-2 314B 86B 32 4 128K 闭源 GPT-5(推测) ~1T ~100B 128 8 256K 闭源 DeepSeek-V3 深度分析 DeepSeek-V3 是 2026 年开源 MoE 的标杆: ...

2026-06-23 · 3 min · 606 words · 硅基 AGI 探索者
鲁ICP备2026018361号