Prhub

#30235 [Intel GPU] xpu_piecewise: fall back to eager when PCG capture stream is unset

原始 PR 作者 ckvermaAI 合并时间 2026-07-09 10:21 文件变更 1 提交数 3 评论 5 代码增减 +16 / -3

执行摘要

XPU PCG 回退 eager 避免崩溃

某些预填充批次 token 数超出 PCG 捕获范围(如 8192 vs 512)时,Dynamo 会静默重编译子图,导致 capture stream 未设置,原先的 assert 会杀死调度器。

值得合并,修复了潜在的崩溃问题,且保持了与 CUDA/HIP 后端的行为一致性。建议在后续增加针对该 fallback 路径的单元测试。

讨论亮点

Gemini Code Assist Bot 指出注释中 PrefillCudaGraphRunner 拼写错误,应改为 PiecewiseCudaGraphRunner。该建议已被采纳,体现在最终提交中。

实现拆解

  1. 新增导入xpu_piecewise_backend.py 中导入 print_warning_once 工具函数。
  2. 替换断言为条件检查assert stream is not None 改为 if stream is None 分支,调用 print_warning_once 打印一次性警告,然后直接返回 entry.runnable(*args) 执行 eager 模式。
  3. 添加注释说明 复用了 CUDA 后端的 HIP fallback 注释,并修正了评论中类名。
文件 模块 状态 重要度
python/sglang/srt/compilation/xpu_piecewise_backend.py 编译后端 modified 6.18

关键符号

XPUPiecewiseBackend.__call__

关键源码片段

python/sglang/srt/compilation/xpu_piecewise_backend.py dependency-wiring

核心修改文件,将 assert 替换为条件 fallback,新增导入 print_warning_once。

# xpu_piecewise_backend.py
# 当 PCG capture stream 未设置时(Dynamo 运行时重编译导致),
# 降级为 eager 执行,避免调度器崩溃。# 导入 print_warning_once 工具函数
from sglang.srt.utils.common import print_warning_oncedef __call__(self, *args) -> Any:
    # ... 前面的逻辑省略 ...
    if entry.cudagraph is None:
        if entry.num_finished_warmup < 1:
            entry.num_finished_warmup += 1
            return entry.runnable(*args)
​
        # 获取 PCG capture stream:正常捕获时由 set_pcg_capture_stream 保证有效
        # 但 Dynamo 重编译后的后端实例可能没有该 stream
        stream = get_pcg_capture_stream()
        if stream is None:
            # 一次性警告后 fallback 到 eager 执行
            print_warning_once(
                "PCG capture stream is not set; likely a Dynamo runtime "
                "recompilation. Falling back to eager execution for this "
                "subgraph."
            )
            return entry.runnable(*args)
        # 剩余正常 graph capture 逻辑 ...

评论区精华

注释中类名拼写错误 style

Gemini Code Assist Bot 指出注释中 'PrefillCudaGraphRunner' 应为 'PiecewiseCudaGraphRunner'。

结论:作者已接受建议并修正。 · 已解决

风险与影响

当 fallback 发生时,该子图使用 eager 而非 graph 执行,可能导致性能退化。但这是预期行为,且仅在一次警告后发生,不影响整体调度器稳定性。风险低。

影响范围小,仅涉及 Intel GPU(XPU)上的 PCG 流程。修复了在 token 数超出捕获范围时的崩溃问题,提高了鲁棒性。CI 测试中已包含相关场景(Extra tests 失败需确认)。

缺少测试覆盖

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论