Prhub

#30278 Fix LTX2 RoPE JIT kernel CI

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

执行摘要

修复 LTX2 RoPE JIT 内核测试精度问题

CI 测试失败(参见 PR body 中的 CI 日志链接),原因是 JIT 内核测试未能通过精度校验。根因是测试参考实现使用了 torch.nn.RMSNorm 配合 autocast,导致归一化在 bf16 下舍入,与 CUDA 内核的 fp32 归一化行为不匹配,产生精度误差。

该 PR 属于小型修复,对于关注 CI 稳定性和精度模型的开发者有一定参考价值。值得注意的决策是使用 F.rms_norm 在 fp32 域直接计算,避免了 nn.RMSNormautocast 下的隐式类型转换,这是一种通用的测试精度修复模式。

讨论亮点

PR 没有 review 评论或讨论。但参考 PR body 的 CI 失败链接和提交记录可以推断,问题在于测试参考实现与 CUDA 内核的精度模型不一致。

实现拆解

  1. 修正测试参考实现test/registered/jit/diffusion/test_ltx2_qknorm_split_rope.py):将 _reference 函数中的 torch.nn.RMSNorm + autocast 替换为 F.rms_norm,并在 fp32 域执行计算,避免额外的类型转换和舍入。添加了导入 F
  2. 更新 CUDA 内核注释python/sglang/jit_kernel/csrc/diffusion/ltx2_qknorm_split_rope.cuh):修改注释以准确描述精度模型——RMSNorm 和 split RoPE 都在 fp32 下运行,仅在最终 attention 输入前舍入到 bf16。
文件 模块 状态 重要度
test/registered/jit/diffusion/test_ltx2_qknorm_split_rope.py 测试 modified 5.05
python/sglang/jit_kernel/csrc/diffusion/ltx2_qknorm_split_rope.cuh JIT 内核 modified 2.64

关键符号

_reference

关键源码片段

test/registered/jit/diffusion/test_ltx2_qknorm_split_rope.py test-coverage

测试参考实现的核心修改:用 F.rms_norm 替换 nn.RMSNorm + autocast,使精度模型与 CUDA 内核一致。

def _reference(
    q: torch.Tensor,
    k: torch.Tensor,
    q_cos: torch.Tensor,
    q_sin: torch.Tensor,
    k_cos: torch.Tensor,
    k_sin: torch.Tensor,
    q_weight: torch.Tensor,
    k_weight: torch.Tensor,
    eps: float,
) -> tuple[torch.Tensor, torch.Tensor]:
    # rms_norm isn't autocast fp32-preserving, so feed fp32 inputs directly
    # to keep the normalized value unrounded until the final RoPE output.
    q_norm = F.rms_norm(q.float(), (q.shape[-1],), q_weight.float(), eps)
    k_norm = F.rms_norm(k.float(), (k.shape[-1],), k_weight.float(), eps)
    q_ref = _apply_split_rotary_ref(q_norm, q_cos, q_sin)
    k_ref = _apply_split_rotary_ref(k_norm, k_cos, k_sin)
    return q_ref.to(dtype=torch.bfloat16), k_ref.to(dtype=torch.bfloat16)

评论区精华

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

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

风险与影响

风险极低。变更仅限于测试文件和注释,不影响任何生产逻辑。所有 5 个测试用例均通过 CI。

影响范围仅限于 LTX2 QKNorm split-RoPE JIT 内核的 CI 测试。修复后 CI 测试将不再因精度问题失败,保障了该内核的持续集成可靠性。

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论