Prhub

#20908 fix(PD): respect pause_generation in disagg event loops

sgl-project/sglang · 作者 lawrence-harmonic · 合并时间 2026-04-13 09:07

分析状态 已生成
文件变更 3提交数 2 · 评论 7
代码增减 +107 / -2
bugfix run-ci scheduling test

执行摘要

修复 disaggregation 事件循环中 pause_generation 失效的 bug,确保调度器暂停时生成停止。

修复 issue #20906,该 issue 指出在 disaggregation 事件循环(decode.py 和 prefill.py)中没有 self._engine_paused 检查,导致生成不会在调用 /pause_generation 时暂停。PR body 中明确说明动机为 'Fix #20906'。

该 PR 值得精读,特别是对于涉及调度和 disaggregation 模块的工程师。关注点包括:如何在事件循环中优雅地处理暂停状态,以及确保队列处理在暂停时继续的设计决策。

讨论亮点

review 中的主要讨论是测试文件的放置策略。reviewer hnyls2002 要求 'Do not add new E2E test files. Just put the pause generation test inside test_disaggregation_basic.' 作者遵守了这个要求,将测试集成到现有测试文件中,而不是创建新文件。这反映了团队对测试组织的一致性和维护性的重视。没有其他深入技术讨论。

实现拆解

实现方案包括三个关键改动点:1) 在解码事件循环(decode.py 的 event_loop_normal_disagg_decode 和 event_loop_overlap_disagg_decode)中添加 if self._engine_paused: continue,以跳过批次运行当引擎暂停时;2) 在预填充事件循环(prefill.py 的 event_loop_normal_disagg_prefill 和 event_loop_overlap_disagg_prefill)中添加类似检查,并调用 self.process_disagg_prefill_inflight_queue() 以确保 bootstrap 和 transfer 队列的处理在暂停时仍能完成;3) 在 test_disaggregation_basic.py 中添加回归测试 test_pause_resume_in_place,验证暂停功能在 disaggregation 场景下的有效性。

文件 模块 状态 重要度
python/sglang/srt/disaggregation/decode.py disaggregation modified 8.0
python/sglang/srt/disaggregation/prefill.py disaggregation modified 8.0
test/registered/disaggregation/test_disaggregation_basic.py test modified 6.0

分析完成后,这里会展示 LLM 生成的相对完整源码片段和详细注释。

关键符号

event_loop_normal_disagg_decode event_loop_overlap_disagg_decode event_loop_normal_disagg_prefill event_loop_overlap_disagg_prefill test_pause_resume_in_place

评论区精华

测试文件放置策略 测试

reviewer hnyls2002 要求不要添加新的 E2E 测试文件,而是将暂停生成测试集成到现有的 test_disaggregation_basic.py 中。

结论:作者遵守了要求,修改了测试文件,而不是创建新文件,确保测试组织的一致性。 · 已解决

风险与影响

技术风险较低:1) 改动是添加简单的条件检查,逻辑直接,回归风险小;2) 在 prefill.py 中添加的 self.process_disagg_prefill_inflight_queue() 调用可能在暂停时引入轻微性能开销,但这是确保队列处理完成的必要设计;3) 修改调度循环可能意外影响其他功能,但回归测试覆盖了基本场景,且改动范围小。兼容性风险低,因为只是修复现有 bug。

对用户:pause_generation 功能在 disaggregation 部署中现在正常工作,提高了系统的可控制性和调试能力。对系统:修复了调度器在暂停状态下的行为,确保生成停止,避免资源浪费。对团队:增加了回归测试,提升了代码质量,并为未来相关功能(如调度控制)提供测试基础。影响范围限于 disaggregation 模块。

核心路径变更 队列处理逻辑修改

关联 Issue

#20906 [Bug] disagg event loops do not respect /pause_generation

完整报告

执行摘要

此 PR 修复了 disaggregation 事件循环中 pause_generation 功能失效的 bug,通过在解码和预填充循环中添加暂停检查,确保调度器在暂停时停止生成,并添加了回归测试验证。改动小但关键,恢复了系统的可控制性。

功能与动机

动机源于 issue #20906,报告在 disaggregation 的 decode.py 和 prefill.py 中缺少 self._engine_paused 检查,导致调用 /pause_generation 时生成不暂停。PR 旨在恢复这一关键控制功能,引用 issue 描述:'Generation does not pause when /pause_generation is called.'

实现拆解

  • 解码模块(decode.py):在 event_loop_normal_disagg_decodeevent_loop_overlap_disagg_decode 函数中添加 if self._engine_paused: continue,跳过批次运行当引擎暂停时。
  • 预填充模块(prefill.py):在 event_loop_normal_disagg_prefillevent_loop_overlap_disagg_prefill 函数中添加类似检查,并调用 self.process_disagg_prefill_inflight_queue() 以确保 bootstrap 和 transfer 队列的处理在暂停时仍能完成。
  • 测试模块:在 test_disaggregation_basic.py 中添加 test_pause_resume_in_place 测试,模拟暂停场景,验证请求在暂停期间无进展,恢复后正常完成。

评论区精华

主要讨论集中在测试文件的放置。reviewer hnyls2002 指出:

'Do not add new E2E test files. Just put the pause generation test inside test_disaggregation_basic.'

作者据此调整,将测试集成到现有文件中,体现了团队对测试维护性和一致性的重视。没有其他技术争议。

风险与影响

风险:改动简单,风险较低。但需注意:1) 在 prefill.py 中添加的队列处理调用可能引入轻微性能开销;2) 修改调度循环需确保不影响其他功能,回归测试覆盖了基本场景。
影响:对用户,pause_generation 在 disaggregation 中现在正常工作,提升调试能力;对系统,修复了调度逻辑,避免资源浪费;对团队,加强了测试覆盖。

关联脉络

与 PR #22647(提取 pause_resume_in_place 测试工具包)相关,表明团队在系统调度和控制功能上持续演进。近期历史 PR 如 #22597(修复 SWA 输入长度限制)也涉及调度改进,显示该模块的重要性。

参与讨论