Prhub

#28053 Disable dsr1 prefill cudagraphs by default

原始 PR 作者 nvjullin 合并时间 2026-06-30 16:34 文件变更 1 提交数 1 评论 9 代码增减 +31 / -0

执行摘要

默认禁用 DSR1 prefill CUDA graph 以修复 13% 性能回退

DSR1 与 trtllm_mla 后端组合下,捕获的 prefill CUDA graph 强制回退 FlashAttention,导致 TTFT 增加约 17%、TPOT 增加约 14%、吞吐量下降约 12%。提供关闭该后端的默认行为以避免回归。

可快速合并,该 PR 直接解决已验证的性能回归,代码简洁且测试充分(CI 已通过)。建议后续考虑 reviewer 建议,进行通用化改造,但非当前阻塞项。

讨论亮点
  • gemini-code-assist[bot] 建议将架构检查改为后端通用检查,以覆盖使用 trtllm_mla 的 draft 模型等,避免硬编码架构限制。
  • mmangkad 评审:虽未完全复现 13% TPOT 回退,但多次运行确认 PCG 开启一致比关闭差约 4%,因此默认禁用合理。
  • 决策:保留架构检查,避免影响其他可使用 trtllm_mla 但无回退的模型。

实现拆解

  1. python/sglang/srt/server_args.py 新增 _disable_prefill_cuda_graph_for_deepseek_trtllm_mla 方法,在 __post_init__ 的注意力后端解析后调用。
  2. 方法检查预填 CUDA graph 是否已锁定或禁用,若已禁用则跳过;若模型架构非 DeepseekV3ForCausalLM 或预填注意力后端非 trtllm_mla,也跳过,确保仅对特定模型生效。
  3. 满足条件时打印警告日志,并将预填 CUDA graph 后设置为 DISABLED,覆盖默认的 tc_piecewise 行为。
  4. 通过 _cuda_graph_config_locked 机制允许用户显式指定后端以覆盖此默认行为。
文件 模块 状态 重要度
python/sglang/srt/server_args.py 模型服务 modified 7.25

关键符号

_disable_prefill_cuda_graph_for_deepseek_trtllm_mla

关键源码片段

python/sglang/srt/server_args.py core-logic

核心实现,新增方法默认禁用 DSR1 prefill CUDA graph 以修复性能回退。

def _disable_prefill_cuda_graph_for_deepseek_trtllm_mla(self):
    """Disable prefill CUDA graph for dsr1 by default when using the trtllm_mla
    attention backend. Under any captured prefill CUDA graph (tc_piecewise or
    breakable) trtllm_mla falls back to FlashAttention for prefill and regresses
    performance, so disable whichever prefill graph backend is in effect.
    """
    # 如果 prefill 后端已被用户锁定则跳过
    if (Phase.PREFILL, "backend") in self._cuda_graph_config_locked:
        return
    # 如果 prefill CUDA graph 已禁用则无需操作
    if self.cuda_graph_config.prefill.backend == Backend.DISABLED:
        return
    # 仅对 DeepseekV3ForCausalLM 架构生效(目前 DSR1 使用此架构)
    if (
        "DeepseekV3ForCausalLM"
        not in self.get_model_config().hf_config.architectures
    ):
        return
    # 获取 prefill 注意力后端
    prefill_attention_backend, _ = self.get_attention_backends()
    # 仅当后端是 trtllm_mla 时禁用
    if prefill_attention_backend != "trtllm_mla":
        return
    # 发出警告并禁用 prefill CUDA graph
    logger.warning(
        "Disabling prefill CUDA graph (%s) by default for the DeepSeek-V3 arch on "
        "the trtllm_mla attention backend (a captured prefill graph forces a "
        "FlashAttention fallback that regresses prefill). Set the prefill cuda graph "
        "backend explicitly (e.g. --cuda-graph-backend-prefill tc_piecewise) to override.",
        self.cuda_graph_config.prefill.backend,
    )
    self.cuda_graph_config.prefill.backend = Backend.DISABLED

评论区精华

架构检查是否应该通用化 设计

gemini-code-assist[bot] 建议移除架构硬编码,对任意使用 trtllm_mla 后端且预填 CUDA graph 导致回退的模型禁用,避免遗漏 draft 模型等。

结论:保持当前架构特定检查,因为仅 DSR1 被确认存在该回归;后续可考虑泛化。 · 已解决

性能回归幅度验证 other

mmangkad 无法复现 13% TPOT 回退,但多次运行检测到约 4% 的稳定性能差异,因此仍认为默认禁用合理。

结论:CI 通过,数据支持合并。 · 已解决

风险与影响

  • 如果用户依赖 prefill CUDA graph 提升其他场景(如非 trtllm_mla 后端或 draft 模型)的性能,默认关闭可能引入轻微回退。
  • 已考虑锁定机制和手动覆盖选项,风险可控。
  • 需关注未来 draft 模型可能受此影响,但当前未发现性能问题。
  • 用户影响:DSR1 用户默认获得更好性能(TTFT 和 TPOT 降低),无需手动调整。
  • 系统影响:仅影响 DSR1(DeepseekV3ForCausalLM)与 trtllm_mla 后端的组合;其他模型和默认后端不受影响。
  • 团队影响:降低维护负担,避免性能倒退报告。
核心路径变更 回归可能性存在

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论