Prhub

#23885 [Disagg] Finalize routed_experts_output in process_batch_result_disagg_prefill

原始 PR 作者 ByronHsu 合并时间 2026-04-28 07:40 文件变更 1 提交数 1 评论 1 代码增减 +3 / -0

执行摘要

修复 PD Disagg 预填充未 finalize 路由专家输出

修复 PD Disagg + --enable-return-routed-experts + overlap scheduling 下路由专家返回全零的 bug。PR body 指出,在启用路由回放的 RL 工作流中,预填充 prompt token 返回全零 topk 行,被训练器解释为 8 次重复选择专家 0,触发断言 Duplicate experts in routing!

建议合并。该 PR 修复了一个明确的遗漏 bug,修改量小,逻辑清晰,且已本地验证通过。

讨论亮点

无讨论。

实现拆解

python/sglang/srt/disaggregation/prefill.pyprocess_batch_result_disagg_prefill 方法中,在 copy_done.synchronize() 之后,添加了如下代码:

  1. 检查 result.routed_experts_output 是否为 None
  2. 若非 None,调用 result.routed_experts_output.finalize() 将 CPU 侧的 tensor 写入 host_cache.buffer
  3. result.routed_experts_output 设为 None,与聚合模式的处理一致。
    该修改仅 3 行,逻辑简单但关键。
文件 模块 状态 重要度
python/sglang/srt/disaggregation/prefill.py 调度器 modified 5.56

关键源码片段

python/sglang/srt/disaggregation/prefill.py core-logic

修复 PD Disagg 预填充处理器中遗漏的 `finalize()` 调用,核心 bugfix 所在。

# python/sglang/srt/disaggregation/prefill.py
# 在 copy_done 同步后,finalize 路由专家输出并清空引用
if copy_done is not None:
    copy_done.synchronize()
# 新增:确保 host_cache.buffer 被正确写入
if result.routed_experts_output is not None:
    result.routed_experts_output.finalize()
    result.routed_experts_output = None

评论区精华

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

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

风险与影响

风险极低。修改仅在 result.routed_experts_output is not None 时执行,当 --disable-overlap-schedule 时该字段为 None,因此无影响。但需确保所有调用 process_batch_result_disagg_prefill 的路径都已覆盖。

影响范围:修复 PD Disagg + 返回路由专家 + overlap scheduling 下的严重回归,使相关 RL 工作流恢复正常。对不使用该功能的用户无影响。

核心路径变更

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论