Prhub

#28982 fix(mtp): avoid mtp perf regression in deepseek when enable eplb

原始 PR 作者 ICENacl 合并时间 2026-07-10 02:29 文件变更 1 提交数 3 评论 6 代码增减 +14 / -6

执行摘要

修复 EPLB 与 MTP 同时启用时的性能回归

当 DeepSeek 同时启用 EPLB 和 MTP 时,草稿模型复用目标模型的 dispatch info 导致接受率下降。PR body 提到:"When EPLB and MTP are enabled in DeepSeek, the draft model reusing the target model's dispatch info causes a degradation in accept rate. We introduce the is_nextn flag to fix this issue." 作者提供的 benchmark 数据显示,修复前 accept length 为 2.38,total throughput 为 9576.96;修复后分别为 2.69 和 10290.71,性能提升约7.5%。

值得合并,修复明确、验证充分、变更范围极小。建议关注 is_nextn 标志在其他模型中的一致性,确保类似问题不发生。

讨论亮点

主要 reviewer ch-wan 批准了 PR,无其他讨论。作者邀请了多位 reviewer 并提供了 benchmark 数据,验证了修复的有效性。无争议点。

实现拆解

  1. 在 forward_normal_dual_stream 中增加 is_nextn 检查(文件 python/sglang/srt/models/deepseek_v2.py,第941行):将 dispatch_info 的创建条件从 if server_args.enable_eplb 改为 if server_args.enable_eplb and not self.is_nextn,确保草稿模型不会创建 EPLB dispatch info。
  2. 在 forward_normal 中增加同样的检查(第1038行):与上一步相同,确保常规前向路径中草稿模型跳过 EPLB。
  3. 在 forward_deepep 中调整 dispatch info 创建逻辑(第1240-1245行):原代码直接创建 ExpertLocationDispatchInfo.init_new(layer_id=self.layer_id),现改为条件创建 if not self.is_nextn else None,避免草稿模型使用 EPLB。
  4. 在 op_select_experts 中调整同样的逻辑(第1478-1483行):与第三步相同,确保专家选择路径中草稿模型跳过 EPLB。
    所有变更仅涉及 python/sglang/srt/models/deepseek_v2.py 一个文件,共 +14/-6 行。
文件 模块 状态 重要度
python/sglang/srt/models/deepseek_v2.py 模型层 modified 6.52

关键符号

forward_normal_dual_stream forward_normal forward_deepep op_select_experts

关键源码片段

python/sglang/srt/models/deepseek_v2.py data-contract

唯一修改的文件,包含所有 EPLB dispatch info 创建路径的修复。

# python/sglang/srt/models/deepseek_v2.py
# 在 forward_normal_dual_stream 中:
server_args = get_global_server_args()
dispatch_info = (
    ExpertLocationDispatchInfo.init_new(layer_id=self.layer_id)
    if server_args.enable_eplb and not self.is_nextn # 草稿模型跳过 EPLB
    else None
)
​
# 在 forward_normal 中(第 1035-1040 行):
server_args = get_global_server_args()
dispatch_info = (
    ExpertLocationDispatchInfo.init_new(layer_id=self.layer_id)
    if server_args.enable_eplb and not self.is_nextn # 草稿模型跳过 EPLB
    else None
)
​
# 在 forward_deepep 中(第 1238-1245 行):
# 调用 topk 时,条件创建 dispatch info
expert_location_dispatch_info=(
    ExpertLocationDispatchInfo.init_new(
        layer_id=self.layer_id,
    )
    if not self.is_nextn # 草稿模型不传 dispatch info
    else None
),
​
# 在 op_select_experts 中(第 1476-1483 行):
# 类似 forward_deepep,条件创建 dispatch info
expert_location_dispatch_info=(
    ExpertLocationDispatchInfo.init_new(
        layer_id=self.layer_id,
    )
    if not self.is_nextn # 草稿模型不传 dispatch info
    else None
),

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

风险低。变更仅局限于条件判断的微调,不改变核心逻辑。若 self.is_nextn 标志未正确设置,可能导致草稿模型错误使用或不使用 EPLB,但该标志已在其他模型(如 Qwen3 MoE)中成熟使用,风险可控。

直接影响 DeepSeek 模型中启用 EPLB 和 MTP 的用户,修复后吞吐量提升约7.5%(从 9576.96 到 10290.71 tokens/s)。不影响不启用 EPLB 或 MTP 的场景。

无测试配套 核心路径变更

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论