[REQUEST] Legacy MoE gate: opt-in route_norm, with historical combine weights left as the default
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
Read deepspeed/moe/sharded_moe.py and deepspeed/moe/layer.py to trace how MoE and TopKGate call the three gating functions; check deepspeed/ops/transformer/inference/moe_inference.py for positional callers. Run the existing MoE tests and compare omitted-flag behavior with the historical rules; done means the opt-in overrides renormalization while the default preserves existing numerics and auxiliary loss.
由索引模型根据 Issue 内容生成。
描述
Is your feature request related to a problem? Please describe.
The legacy MoE gate does not use one combine-weight rule. On current master (991ccf0f) the three functions in deepspeed/moe/sharded_moe.py disagree, and MoE / TopKGate have no switch for it.
top1gatingreturns the chosen expert's softmax probability. The sparse return is(gates * mask1).sum(dim=1)with no division (around line 321). The dense path's comment says "Normalize gate probabilities" and then only multiplies by the mask (around lines 329-331).top2gatingdivides the two kept probabilities by their sum before both the sparse and dense returns (around lines 402-411).topkgatingdivides the kept probabilities by their sum before both returns (around line 501).MoE(k=1)does not call this function.TopKGate.forwardsendsk == 1totop1gating,k == 2totop2gating, and onlyk > 2totopkgating(around lines 593-609).
TokenChoiceTopKRouter in deepspeed/moe/ep_router.py already takes route_norm. The config key expert_parallel.route_norm configures that AutoEP router. The legacy MoE constructor does not read it.
The auxiliary loss is a separate disagreement, and it is computed before those divisions. Top-1 is sum(me * ce) * E on the single assignment. Top-2 is mean(me * ce) * E * E on the first-expert mask only, which is the same value as top-1 when the first expert matches. Top-k is mean(me * ce) * E * E / k on the full top-k mask.
I measured this on CPU with torch 2.5.1, before changing the code, at 991ccf0f. drop_tokens=False, use_rts=False, and for top-2 top2_2nd_expert_sampling=False. Logits:
[[2.0, 0.0, -1.0, 0.5],
[0.2, 3.0, 0.1, -0.4],
[1.0, 1.1, 0.2, 0.0],
[-0.5, 0.3, 2.5, 0.1]]
| path | combine weights | per-token mass | l_aux |
|---|---|---|---|
top1gating, sparse and dense |
0.710100, 0.870166, 0.378175, 0.799164 | those values, not 1 | 1.261781 |
topkgating(k=1) |
1, 1, 1, 1 | 1 | 1.261781 |
top2gating |
the two kept probabilities, rescaled | 1 | 1.261781 |
topkgating(k=2) |
same weights as top-2 on this input | 1 | 1.144495 |
The k=1 load-balancing losses match. The k=2 losses do not (absolute difference 0.117286). On this input top-2 and top-k select the same experts, so the weight disagreement is top-1 versus top-k, and the loss disagreement is top-2 versus top-k. The gradient of the sum of combine weights with respect to the first token's logits is [0.205858, -0.068242, -0.025105, -0.112512] for top-1, and zeros for the renormalized gates, because those weights no longer depend on the softmax magnitude.
Unifying the weights, or unifying the auxiliary loss, changes numerics for existing users and checkpoints. Router parameter tensors keep their shapes. The MoE output and the expert gradients change, so a checkpoint trained with one rule does not reproduce its loss under the other.
I did not find an open issue for this. Search hits for route_norm in this repo are the AutoEP preset work (for example #8651), not the legacy gate.
Describe the solution you'd like
An opt-in route_norm on deepspeed.moe.layer.MoE, TopKGate, and the three gating functions. The default is None, which keeps today's rule inside each function:
top1gating: no renormtop2gatingandtopkgating: renorm the kept weights so they sum to 1
True renorms for every k. False leaves the raw softmax probabilities for every k. The argument is trailing and defaulted, so existing positional callers stay valid, including the inference TopKGate(...) in deepspeed/ops/transformer/inference/moe_inference.py.
The auxiliary loss stays where it is, before the division, and this flag does not change it. A dropped token stays 0, because 0 / eps is 0.
A draft pull request implements only that. Tests require bitwise equality with the historical rule when the flag is omitted. I would rather not mark it ready for review until you say this shape is what you want.
Describe alternatives you've considered
- Always renorm, including k=1. That matches
topkgating(k=1)and the AutoEP presets that setroute_norm=True, and it changes the MoE output of every existing top-1 checkpoint. - Never renorm. That changes every existing top-2 and top-k checkpoint.
- A bool whose default is either the top-1 rule or the top-2 rule. One bool cannot mean both historical behaviors, which is why the default is
None. - Also unifying
l_auxin this change. That is a second numeric change. If you want it, it should be its own opt-in and stay off by default.
Additional context
Questions for @tohtana:
- Is an opt-in
route_normon the legacy gate welcome? - Is
Nonemeaning "keep the historical per-gate rule" the default you want, with explicitTrue/Falseoverriding every k? - Is the name
route_normacceptable next to the existing AutoEP config keyexpert_parallel.route_norm, or do you want a different name onMoE? - Should auxiliary-loss unification be a separate opt-in, and stay unchanged here?
- Two related legacy-gate mismatches are not in this change.
used_tokenis an argument oftop1gatingonly;TopKGate.forwardaccepts it for every k and then does not pass it fork != 1. On the no-drop path, top-1 pads capacity to the tensor-parallel size and then clamps it back to the token count, which can undo that padding, while top-2 and top-k keep the padded capacity. Should those be separate bugfixes?
I will change or drop the draft PR if this is not the shape you want.
- 主要语言
- Python
- 星标
- 43.3k
- 派生
- 5.1k
- 平均合并
- 5 天 10 小时
- 30 天内合并 PR
- 85
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
deepspeedai/DeepSpeed 的其他 Issue
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()可能已有人在做 @its-amann 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
deepspeedai/DeepSpeed#9190 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exception可能已有人在做 @bantianyue 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#9183 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
deepspeedai/DeepSpeed#9019 · 2 条评论 ·
维护者通常 2 天内回复
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped forever可能已有人在做 @damienen 于 26 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
deepspeedai/DeepSpeed#8982 ·
维护者通常 2 天内回复
-
[BUG] OneCycle applies the minimum momentum to the first Adam update可能已有人在做 @ai-yang 于 30 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#8951 ·
维护者通常 2 天内回复
查看 deepspeedai/DeepSpeed 的全部 Issue
相似的 Issue
-
area/auth comp/agent P3 type/bug
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#161417 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
Dao-AILab/flash-attention#3251 ·
维护者通常 2 天内回复
-
[New Check]: sqlserver_public_network_access_disabled可能已有人在做 @pouria-l 今天认领。 未关闭feature-request status/needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
prowler-cloud/prowler#13607 · 1 条评论 ·
维护者通常 1 天内回复
-
external langchain
难度 1/5 1 小时以内 新手友好度 90/100
langchain-ai/docs#8184 ·
维护者通常 1 天内回复