Prhub

#49380 [CI][Bugfix] Fix ROCm FP8 KV cache dtype in attention backend test

原始 PR 作者 peizhang56 合并时间 2026-07-22 09:34 文件变更 1 提交数 1 评论 0 代码增减 +5 / -2

执行摘要

修复 ROCm FP8 KV cache dtype 导致测试 NaN 失败

在 ROCm gfx94x / MI300 上,test_causal_backend_correctness[fp8*] 测试失败,报错 '[AttentionBackendEnum.TRITON_ATTN] produced non-finite values'。根本原因是测试硬编码了 torch.float8_e4m3fn,但 backends 运行时通过 current_platform.fp8_dtype() 重新解释字节,该函数在 ROCm 上返回 e4m3fnuz,两种格式的指数偏置和 NaN 编码不同(如 0x80 在 e4m3fn 中是 -0.0,在 e4m3fnuz 中是 NaN)。修复使测试存储 dtype 与运行时一致。

值得快速合并,修复了跨平台测试一致性问题,无潜在风险。

讨论亮点

无审核评论讨论,仅 AndreasKaratzas 批准。

实现拆解

在 tests/v1/attention/test_attention_backends.py 中,将 FP8_KV_CACHE_DTYPES 字典的两个值从硬编码的 torch.float8_e4m3fn 替换为 current_platform.fp8_dtype(),并添加注释说明原因。该函数在 CUDA 上返回 e4m3fn,在 ROCm gfx94x 上返回 e4m3fnuz,从而匹配 backends 运行时的 reinterpret 逻辑。

文件 模块 状态 重要度
tests/v1/attention/test_attention_backends.py 注意力 modified 4.16

关键源码片段

tests/v1/attention/test_attention_backends.py test-coverage

修复了 FP8 KV cache dtype 硬编码问题,使测试在 ROCm 上正确运行。

# Use the platform's preferred FP8 type so the stored cache matches what the
# backends reinterpret at runtime. On ROCm gfx94x this is e4m3fnuz, not e4m3fn;
# storing e4m3fn bytes there would be re-read as fnuz and produce NaNs.
FP8_KV_CACHE_DTYPES = {
    "fp8": current_platform.fp8_dtype(),
    "fp8_e4m3": current_platform.fp8_dtype(),
}

评论区精华

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

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

风险与影响

变更极小(5行),仅在测试中修改 dtype 值。CUDA 上 function 返回相同 dtype,因此无回归风险。ROCm 上修复了 NaN 问题。风险极低。

影响限于 ROCm 平台下 FP8 attention 测试的正确性。CUDA 用户无感知。

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论