调研日期:2026-10-14(UTC 2026-10-14 16:2x) 目标机器:RTX 5060 Ti 16GB(sm_120)· PyTorch 2.11.0+cu130 · ComfyUI 0.38.0 · 驱动 595.71.05 · Deepin 25(GPU 机 192.168.31.31) 方法:web_search / web_fetch + 上游源码直读 + 在本机(GPU 机)做只读 torch 探针实测。未修改任何文件。
⚠️ 最重要的一条:任务背景里"怀疑 SageAttention 在 sm_120 上缺少官方内核、退化为 triton JIT"这个前提,经查证是错的。
- 上游
sageattention/core.py有显式 sm120 分支,而且主动避开 Triton(源码注释原文:"sm120 has accurate fp32 accumulator for fp8 mma and triton kernel is currently not usable on sm120"),实际调用的是_qattn_sm89这个 CUDA(非 Triton)扩展。- 所以"退化为 triton JIT"不成立;但"SageAttention 的 sm120 路径脆弱"这个直觉是对的——脆弱的是那条 int8-QK + per-channel FP8-PV 的 CUDA 内核路径,社区有一条症状几乎逐字对应你们历史的报告(见 §1.4)。
- 另外,你们现在的 ComfyUI 0.38.0 上根本没装 sageattention,也没装 xformers / flash-attn。默认走的是 PyTorch 内置 SDPA 的 FA2 内核(已实测确认,见 §3.5)。也就是说当前生产路径本身已经是最稳的那条。
| 后端 | sm_120 官方内核 | 消费卡(5060 Ti)实测 | 稳定性 | 建议 |
|---|---|---|---|---|
| PyTorch 内置 SDPA(默认) | ✅ 有(FA2 内核,无需装包) | 基线(最快且最稳) | ✅ 社区零掉卡报告 | ✅ 保持默认 |
comfy-kitchen int8 attention(--use-ck-attention) | ✅ 官方官方支持(CUDA arch 含 120f) | 本机 int8_attention_is_available=True 实测通过 | ⚠️ 无公开实测样本(不确定) | ⚠️ 想提速才试,先小规模验证 |
| SageAttention 2.2.0 | ✅ 有(CUDA _qattn_sm89,非 Triton) | SA2 快 1.0–1.1×(hd64)/ 1.3–1.7×(hd128) | 🔴 有 sm120 GPU 掉总线 / 静默噪声报告,且同款 5060 Ti | 🔴 不要留(尤其 FP8-PV) |
| SageAttention 3(FP4) | ✅ 名义支持 sm120(CUDA 源码编译) | 本机同类卡(5060 Ti)报 misaligned address | 🔴 不可用 | ❌ 不要 |
FlashAttention2(第三方 flash-attn 包) | ❌ 官方只支持 Ampere/Ada/Hopper | Windows 基本装不上 | — | ❌ 不要;用 PyTorch 内置的即可 |
| FlashAttention3 | ❌ Hopper 专属 | 不适用 | — | ❌ 不要 |
FlashAttention4(flash-attn-4) | 🟡 开发中,目标覆盖到 sm120 | 维护者明说测试只覆盖 sm90–sm100 | 🔴 sm120 仍有多个 open bug | ⚠️ 观察,别上生产 |
| xformers | ❌ 无 | 预编译 wheel 不支持 | 🔴 cutlass 路径在 Blackwell 被硬阻塞且无 fallback | ❌ 不要 |
官方 README 的"官方声明"是保守的:Current Features 只写 "Optimized kernels for Ampere, Ada and Hopper GPUs"。README 里 sm120 的唯一线索是更新日志:
[2025-02-15] 🔥 The compilation code is updated to support RTX5090! On RTX5090, SageAttention reaches 560T, 2.7x faster than FlashAttention2!
对应提交 4b0824de "sm120 early support (#109)"(2025-02-15),改动包括 setup.py(加 sm120 编译)、core.py(加 sm120 分发)。
但代码层面的支持是明确存在的。 sageattention/core.py 的 sageattn() 按算力分发:
elif arch == "sm120":
return sageattn_qk_int8_pv_fp8_cuda(q, k, v, ..., qk_quant_gran="per_warp",
pv_accum_dtype="fp32+fp16")
# 注释原文: sm120 has accurate fp32 accumulator for fp8 mma and
# triton kernel is currently not usable on sm120.
elif arch == "sm121": # DGX Spark,同样走这条
setup.py 默认编译目标(官方首次声明):
SUPPORTED_ARCHS = {"8.0", "8.6", "8.9", "9.0", "10.0", "12.0", "12.1"}
# 未指定时的 CUDA arch 列表在 cuda 分支里长这样:
# CUDA_VERSION >= 13000 → 加入 "12.0+PTX"(即 sm120 cubin 是默认产物)
历史坑:2025-11 曾有
{"10.0" "12.0"}缺逗号导致 sm120 被静默拼成字符串的 bug(issue #303),当前 main 已修。
版本对应关系:
sageattention==2.2.0 是 PyPI 最新(tag v2.2.0 = eb615cf6)。v2.2.0 的 core.py 里已包含 sm120 分支(已核对 tag 内容)。pip install sageattention 的默认版本可能仍是 1.0.6(README 明确写 "PyPI only ships 1.0.6" 的说法在多个社区文档里出现),要用请显式 pip install sageattention==2.2.0 --no-build-isolation 或装预编译 wheel。Windows(社区事实标准:woct0rdho fork)
torch2.10.0andhigher / cp310-abi3),不挑 CUDA 小版本和 Python 小版本(只区分 CUDA 12 / 13 大版本)triton-windows(SageAttention 2 的硬依赖,因为 quantization 的前处理在 Triton 里)--use-ck-attention rather than --use-sage-attention."sanjxz/sageattention-2.2.0-blackwell-sm120a(TORCH_CUDA_ARCH_LIST=12.0 + sm_120a 编译的 wheel)Linux(本机就是 Deepin 25)
# 官方推荐
pip install sageattention==2.2.0 --no-build-isolation
# 或源码编译(会按本机算力自动选 sm120)
git clone https://github.com/thu-ml/SageAttention && cd SageAttention
TORCH_CUDA_ARCH_LIST="12.0" python setup.py install
⚠️ 编译坑(如果非要编):
TORCH_CUDA_ARCH_LIST="9.0;12.0" 一起编 —— sm90a 的 wgmma 指令在 sm_120 上不被 ptxas 接受(issue #291:ptxas error: Instruction 'wgmma.fence' not supported on .target 'sm_120')。sm_120a(而非 sm_120)才能真正用上 Blackwell 的 tcgen05 路径(issue #303 的 Dockerfile 用 12.0,结果 只有约 6% 加速,远低于预期)。compiled_autograd.h 里 ::std::is_same_v<T, ::std::string> 触发 MSVC C2872 'std' ambiguous symbol),需要手工注释掉那两行。ComfyUI 里的启用方式(三种)
--use-sage-attention 启动参数 = 全局替换(comfy/ldm/modules/attention.py 里 optimized_attention = attention_sage)。Patch Sage Attention KJ 节点 = 单工作流替换,可选具体 kernel(auto / sageattn_qk_int8_pv_fp16_cuda / sageattn_qk_int8_pv_fp8_cuda / sageattn3_blackwell 等)。--use-ck-attention(ComfyUI 0.38 新增,官方推荐) —— 见 §1.6。社区一致的重要警告:
--use-sage-attention在 Qwen-Image / Wan 这类模型上会出黑图或噪声,官方建议改用 KJNodes 节点并显式选sageattn_qk_int8_pv_fp16_cuda("the least likely to overflow")。 ⚠️ 但这条建议对 sm_120 不成立——见下面 §1.4 的实测反驳。
官方(thu-ml)声明:
assets/5090_sageattn2++.png 的 kernel 速度图(未给具体数值)。社区实测 —— 最贴近你机器的数据(RTX 5060 Ti 16GB, sm_120, Windows, torch 2.12 nightly + cu132, sageattention 2.2.0, triton 3.6.0) 来源:Rogala/SageAttention-Benchmark-Viewer 的 results/5060-ti-16_Ref.json(我直接解析了该 JSON,下面的 ms 值是该文件的 mean_ms;基准里的 sdpa 即 PyTorch FA2 后端):
| 代表配置(head_dim) | SDPA (ms) | SA2 (ms) | SA2-fp8 (ms) | SA3-FP4 (ms) | SA2 vs SDPA |
|---|---|---|---|---|---|
| SDXL 1024², 4096 tok (hd64) | 1.953 | 0.616 | 0.589 | ERR(SA3 要求 hd=128) | 3.17× |
| SD3.5-L 1024², 4250 tok (hd64) | 7.735 | 1.864 | 1.962 | ERR | 4.15× |
| Flux.1-Dev 1024², 4352 tok (hd128) | 12.817 | 2.392 | 2.553 | 2.197 | 5.36× |
| Flux.2-Dev 1440², 8612 tok | 97.077 | 15.021 | 15.526 | 9.036 | 6.46× |
| Qwen-Image-2512 1920², 14489 tok | 136.10 | 19.745 | 20.174 | 12.398 | 6.89× |
| Wan2.2 1280×720, 18000 tok | 347.72 | 49.457 | 50.211 | 30.673 | 7.03× |
| Wan2.2 1920×1088, 40800 tok | 1774.7 | 241.88 | 242.73 | 152.83 | 7.34× |
| HunyuanVideo-1.5 1280×720, 111677 tok | 5451.3 | 709.4 | 707.0 | ERR | 7.69× |
| ACE-Step 1.5 audio 50s, 1250 tok | 0.798 | 0.356 | 0.436 | 0.979 | 2.24× |
⚠️ 阅读这段数据必须注意三点,否则会得出错误结论:
(a)症状逐字对应的一条:同款 GPU、同款模型、同款"掉总线" thu-ml/SageAttention#391(2026-08-16 开,2026-08-19 更新,open) 标题:[Bug][sm_120][Windows] Driver-level GPU lost during MiniMax H3 generation with int8-QK/FP8-PV kernel on RTX 5060 Ti; native attention control passes at higher load
| 项 | 内容 |
|---|---|
| GPU | NVIDIA GeForce RTX 5060 Ti 16GB (sm_120) ← 和你们同一张卡 |
| 环境 | Windows 11, 驱动 610.88, torch 2.12.0+cu130, sageattention v2.2.0 源码编译, ComfyUI 0.33.0 |
| 触发路径 | MiniMaxH3MemoryEfficientSageAttentionPatch → _sageattn_int8_fp8_nhd → _qattn_sm89.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn(int8-QK per-warp + per-channel FP8-PV) |
| 症状 | GPU is lost / Unable to determine the device handle for GPU0 → 必须重启;无蓝屏、无 Kernel-Power 41(排除电源) |
| 时间点 | 生成稳态 ~54 秒时,不是在加载、不是在功耗/温度峰值 |
| 单变量对照 | 同一工作流同一 seed:native PyTorch attention 成功(337 s 完成,峰值 15331 MiB / 182.94 W / 79 °C);Sage 路径 掉卡(13.0 GB / 159–175 W / 68–77 °C)→ 原生路径显存更高、功耗更高、同样温度下却能跑完,因此排除"显存吃满/撞功耗墙/过热" |
(b)作者给出的稳定 workaround(社区实测,不是推测) —— 同一 issue 的评论(2026-08-16):
保留 int8-QK,把 V 从 per-channel FP8 降为 FP16,把 kernel 从
_qattn_sm89.qk_int8_sv_f8_*换成_qattn_sm80.qk_int8_sv_f16_accum_f32_attn。
| 运行 | 路径 | 结果 |
|---|---|---|
| 原始 | int8-QK + per-channel fp8-V | GPU lost ~54 s |
| workaround run 1 | int8-QK + fp16-V,sm80 kernel | ✅ 成功 264.59 s |
| workaround run 2 | 同上 | ✅ 成功 261.93 s |
峰值与原生运行同量级(~15.5 GB / ~181 W / 78–79 °C),仍然比原生 PyTorch attention 快约 21%。 结论(引述):"this corroborates the existing suspicion that the FP8-PV kernel on sm120 is the fragile component"。
(c)同一内核的静默数据损坏
_qattn_sm89 确实编出了原生 sm_120a 代码,不是 SM89 二进制被静默顶替。(d)SageAttention3 在同款 5060 Ti 上直接报错 #357(2026-03-29 开,open):
sageattn3_blackwell在 RTX 5060 Ti (sm_120) / Windows 11 / torch 2.12.0.dev+cu130 / CUDA 13.0 上抛RuntimeError: CUDA error: misaligned address。作者补充 "SageAttention 2.2 works fine on the same system"。
(e)跨架构的同类模式(交叉印证) #391 的 AMD 侧评论(Newaiguy, 2026-08-19,RX 9070 XT / gfx1201 / Windows):
"the pattern — int8/fp8 quantized kernels misbehaving specifically on long sequences, on both sm_120 and gfx12, Windows in both cases — looks like a family worth tracking together."
(f)ComfyUI 侧的对应 issue(H3 专项)
"This works now on ComfyUI 0.31.1. ... 54 min against 94 with sage off." "Ignore the workaround I put here on 08-08. I said to use the KJNodes node on
sageattn_qk_int8_pv_fp16_cuda. It doesn't work on sm_120, it aborts on the first attention call, andfp16_tritonthrowscudaErrorIllegalAddress.autois the only mode that runs on that arch, and it isn't any of the entries under it in the dropdown." 关键一句:"The opt-out is not missing in any meaningful sense; the kernel selected on sm_120 is the actual fault."
即便完全不碰 attention,"驱动 595.71.05 + 5060 Ti"这个组合本身就有独立的 GSP 挂死记录: CachyOS 论坛 / JustFromArch, 2026-05-01
NVRM: Xid (PCI:0000:01:00): 79, GPU has fallen off the bus / NVRM: GPU ...: GPU is lost / nvidia 0000:01:00.0: PCI Bus ErrorNV_ERR_GPU_IS_LOSTNVreg_DynamicPowerManagement=0x00;另注:Blackwell 上 nvidia-open 强制使用 GSP,NVreg_EnableGpuFirmware=0 无效。对你们的意义:AGENTS.md 里"NVreg_DynamicPowerManagement=0x00 已生效(/proc 里读出来是 0)"这件事,并不能证明它防住了 GSP 挂死——在 595.71.05 上它对 P-state 转换引发的 GSP 崩溃没效果。Sage 的 FP8-PV 内核很可能只是"加重触发",而不是唯一根因。 这一条我标注为强相关但未确证(你们机器是 Deepin 25 Xorg+核显输出、驱动同为 595.71.05,与报告环境高度接近但不完全相同)。
ComfyUI 0.38.0 的 comfy/ldm/modules/attention.py 第一行就 import comfy_kitchen(硬依赖),并提供:
--use-ck-attention(cli_args.py:"Use Comfy Kitchen attention.")method 可取 comfy_kitchen_int8 / comfy_kitchen_sol(ConfigurableModule 机制)而 comfy-kitchen 自己有一份独立的 INT8 attention(Comfy-Org/comfy-kitchen → comfy_kitchen/sage_attention.py,头注释 "Pure INT8 scaled dot-product attention for NVIDIA tensor-core GPUs",SPDX 归属 NVIDIA):
_NATIVE_MINIMUM_CAPABILITY = (7, 5) → sm120 通过75-virtual;80;89;90a;100f;**120f**,Windows 75-virtual;80;89;**120f** → sm120 是官方默认编译目标我在你们 GPU 机上的实测(只读):
sageattention NOT INSTALLED
comfy-kitchen 0.2.37
triton 3.6.0
xformers NOT INSTALLED
flash-attn NOT INSTALLED
torch 2.11.0+cu130
→ comfy_kitchen.int8_attention_is_available() = True
→ comfy_kitchen.int8_attention_is_available(cuda:0) = True
→ comfy_kitchen.sol_attn_is_available(cuda:0) = True
→ comfy_kitchen.backends.cuda._EXT_AVAILABLE = True
即:这台机器具备使用 comfy-kitchen int8 attention 的全部条件,不需要装任何 SageAttention wheel。 ⚠️ 不确定项:这套内核在 sm120 + 长序列(H3 那种 150k+ token) 上的稳定性/精度我没有找到任何公开独立实测;它的量化形态(int8 + 缩放)与 Sage 的 FP8-PV 不完全相同,但同属"int8/fp8 量化 attention"家族,因此不能先验假定它一定不触发掉卡。建议:先小规模(短视频)验证,并在 GPU 机加派 §5 的捕获设施(RuntimeWatchdog / netconsole)之后再放开跑。
| 版本 | 官方声明支持的架构 | sm_120 |
|---|---|---|
| FA2(本仓库主体) | "Ampere, Ada, or Hopper GPUs (e.g., A100, RTX 3090, RTX 4090, H100)";CUDA ≥ 12.0;Linux(Windows 只是"Might work",且无预编译 wheel) | ❌ 未列入 |
FA3(hopper/) | "FlashAttention-3 is optimized for Hopper GPUs (e.g. H100)... Requirements: H100 / H800 GPU, CUDA >= 12.3"(β,FP16/BF16 前后向 + FP8 前向) | ❌ |
FA4(flash_attn.cute,CuTeDSL) | "optimized for Hopper and Blackwell GPUs (e.g. H100, B200). pip install flash-attn-4;CUDA 13 建议 flash-attn-4[cu13]" | 🟡 开发中 |
FA2 社区 issue:#1987 "Support for NVIDIA Blackwell (sm_120) architectures — any planned release date?" —— 2025-11-05 开,2026-03-09 仍 open / 无官方答复。报告者(RTX PRO 6000 Blackwell + torch 2.8.0+cu128)报 invalid argument。
[Dao-AILab/flash-attention#2376 "[FA4] Question: Which SM versions are currently supported?"](https://github.com/Dao-AILab/flash-attention/issues/2376) —— 维护者原话(两条,2026):
"Eventually we'll cover Sm80-Sm120. Rn some features are implemented for some arch but not others (hence many PRs). This is changing rapidly. You can look at the tests to see what is tested (currently Sm90 - Sm100)" "The tests will indicate what features are implemented / tested on which architecture. Ofc you're welcome to try with other architecture, it may work or need some small fix (or sometimes major implementation)."
同时 FA 仓库里针对 SM120 的 open PR/issue 密集且持续到 2026-10:
[FA4][SM120] flash_attn_varlen_func / flash_attn_func illegal memory access at >=4 varlen segments under real-workload memory layouts (b26/b29, GeForce Blackwell)[CuTe] Skip over-provisioned varlen tiles in the SM80/SM120 forward kernel (OOB read of cu_seqlens[num_batch+1])[CuTe, SM120] Forward walks every KV block for local (sliding-window) attention[CuTe, SM120] Reject backward configurations that exceed shared memory[CuTe, SM120] FP8 (E4M3) with paged KV cache — the gap at the intersection of #2348 and #2980[Cute,Fwd] Fix pack_gqa compute_ptr crd2idx crash on SM80/SM120 (#2444)结论:FA4 对 sm120 是"在修、能用一部分、别上生产"。 社区另有第三方 sm120 分叉在维护(SecondNatureComputing/flash-attn-4-sm120、vonkaiser/flash-attn-4-sm120),提交内容包括 "Apply Dao #2484 SM120 init-time fix: pack_gqa=False on Sm120/Sm120Tma" —— 侧面证明上游 sm120 路径默认参数都有坑。
这一条是把"第三方 flash-attn 包"和"PyTorch 内置 FA2 内核"分开的关键,也是本次调研最反直觉、最有操作价值的发现:
(a)源码层面,aten/src/ATen/native/transformers/cuda/sdp_utils.cpp(release/2.11 与 main 一致):
bool check_flash_attention_hardware_support(...) {
using sm80 = SMVersion<8, 0>;
using sm121 = SMVersion<12, 1>; // ← 上界是 sm121,不是 sm90
...
if (!check_sm_version<sm80, sm121>(dprops)) { ...警告... return false; }
return true;
}
(main 里同一文件还专门有 check_requires_grad_and_head_dim_gt192_constraints_on_sm86_89_or_120,把 sm120/sm121 单独列出来处理反向的 head_dim 约束 —— 进一步说明 sm120 是被当作一等公民对待的。)
(b)实测确认(在你们 GPU 机 192.168.31.31,只读探针):
device NVIDIA GeForce RTX 5060 Ti (12, 0)
is_flash_attention_available: True
flash_sdp_enabled / mem_efficient_sdp_enabled / math_sdp_enabled / cudnn_sdp_enabled: 全部 True
can_use_flash_attention(SDPAParams(bf16, hd=64/128/256)) = True(三种 head_dim 全 True)
每个后端单独跑 1024 token 小 shape,全部成功:
FLASH_ATTENTION maxdiff 0.0
EFFICIENT_ATTENTION maxdiff 0.001953125
CUDNN_ATTENTION maxdiff 0.001953125
MATH maxdiff 0.001953125
用 torch.profiler 抓默认路径真正执行的 kernel:
default (1, 32, 4096, 128) → pytorch_flash::flash_fwd_kernel<Flash_fwd_kernel_traits<128,128,64,4,...bf16...>>
default (1, 56, 16384, 128) → pytorch_flash::flash_fwd_kernel<...128,128,64,4...>
default (1, 32, 4096, 256) → pytorch_flash::flash_fwd_kernel<...256,64,64,4...>
→ 在 sm_120 上,PyTorch 2.11 的默认 SDPA 走的就是 FlashAttention-2 前向内核(PyTorch 自己编进 libtorch_cuda.so 的那份 pytorch_flash,与 pip 的 flash-attn 包无关)。
(c)因此关于 ComfyUI --use-flash-attention:
flash_attn 包(attention.py: from flash_attn import flash_attn_func;cli_args.py: "Use FlashAttention.")。在本机它会直接失败——flash_attn 未安装;若加上该 flag,ComfyUI 会打印 To use the --use-flash-attention feature, the flash-attn package must be installed first 并 exit(-1)。attention_pytorch 已经在用 FA2 内核(上面 profiler 实证)。装 flash-attn 只会在 attention_pytorch 之外多出一条更窄、且未经 sm120 验证的路径(它会 fallback 回 SDPA,见 attention_flash 的 except: logging.warning("Flash Attention failed, using default SDPA"))。sdp_utils.cpp,release/2.11 与 main 逐行核对)// flash_attention V2 is universally faster than efficient_attention and Math
std::array<SDPBackend, num_backends> priority_order(sdp_params const& params) {
if (!priority_order_init_) {
priority_order_init_ = true;
if (check_prefer_cudnn_attention()) { // ← 注意这个条件
cudnn_order = { cudnn_attention, flash_attention, efficient_attention, math };
at::globalContext().setSDPPriorityOrder(cudnn_order);
}
}
return at::globalContext().sDPPriorityOrder();
}
check_prefer_cudnn_attention()(2.11 全文):
static const bool prefer_cudnn =
c10::utils::check_env("TORCH_CUDNN_SDPA_DEPRIORITIZED") != true; // ← 调试用 env
if (!prefer_cudnn) return false;
// cuDNN 9.15.1 required for seq_len not divisible by 128 fix, CUDA <= 12.9 wheels
// ship with older cuDNN see #169849
#if defined(CUDNN_VERSION)
static long cudnn_version = ...versionRuntimeCuDNN();
auto dprops = at::cuda::getCurrentDeviceProperties();
auto major = dprops->major; auto minor = dprops->minor;
return cudnn_version > 91500 && (major == 9 || major == 10) && (!minor || minor == 3);
#else
return false;
#endif
解读:
flash → efficient(mem-efficient) → cudnn → math。with sdpa_kernel(SDPBackend.CUDNN_ATTENTION))。| 后端 | 源码硬件门限(2.11 / main) | sm120 实测 |
|---|---|---|
| flash | check_sm_version<sm80, sm121> | ✅ can_use_flash_attention=True(hd 64/128/256) |
| mem-efficient | check_sm_version<sm50, sm121> | ✅ True |
| cudnn | check_sm_version<sm80, sm121>(cuDNN MHA only supports gpu architectures in the range [sm80, sm121]) | ✅ hd≤128 True;❌ hd=256 False(打印 Warning: head_dim should be no more than 128 (check_cudnn_tensor_shapes)) |
| math | 无架构限制 | ✅ |
mem-efficient 的 kernel 到底跑得起来吗? mem_eff_attention/kernels/cutlassF.h:
if (std::is_same_v<DT, cutlass::bfloat16_t> && 80 <= cc && cc <= 120) dispatch_cutlassF_bf16_sm80(cb, cc);
if (std::is_same_v<DT, cutlass::half_t> && 80 <= cc && cc <= 120) dispatch_cutlassF_f16_sm80(cb, cc);
if (std::is_same_v<DT, float> && 80 <= cc && cc <= 120) dispatch_cutlassF_f32_sm80(cb, cc);
→ sm120(cc=120)会落到 sm80 目标内核上(CUTLASS Sm80 模板在 sm120 上前向可用),不是空实现。这也解释了我实测里 EFFICIENT_ATTENTION 能跑通。
pytorch/pytorch#181379(open):[cuDNN][SDPA] head_dim limit stuck at 128 on sm_120 (RTX 5090), blocking head_dim=256 models。 本机实测复现(见 §2.3 表):hd=256 时 can_use_cudnn_attention = False 并打出同一条 warning。 (check_cudnn_d256_bprop_head_dim 里对 d=256 的支持条件写的是 is_sm90_or_sm10x,不含 sm12x。) 影响:如果你用 f16 且 head_dim=256 的模型,且恰好触发了 cuDNN 路径,会静默换后端或报错。对 H3 不属于主要风险(H3 的 attention 有更直接的 Sage 问题),但在做后端对比实验时要记住这一点。
① 看 ComfyUI 启动日志(最快) comfy/ldm/modules/attention.py 在 import 时按固定顺序打印:
Using sage attention ← --use-sage-attention
Using Flash Attention ← --use-flash-attention
Using xformers attention ← 装了 xformers 且未被禁用
Using pytorch attention ← --use-pytorch-cross-attention(本机 ENABLE_PYTORCH_ATTENTION 也被自动打开)
Using Comfy Kitchen attention ← --use-ck-attention + int8 kernel 可用
(都没有则)Using split optimization / sub quadratic optimization
启动命令里带不带这些 flag 也可以直接 ps -eo args | grep main.py 看(本机当前:--lowvram --force-fp16 --reserve-vram 1.0 --fast-disk --cache-lru 2 --disable-pinned-memory --preview-method none → 一个 attention flag 都没有 → 走 attention_pytorch)。
② 用 PyTorch 的 can_use_* + debug 打印看"为什么没被选中"
import torch
from torch.backends.cuda import SDPAParams
q = torch.randn(1, 32, 4096, 128, dtype=torch.bfloat16, device="cuda")
p = SDPAParams(q, q, q, None, 0.0, False, False) # (q,k,v,mask,dropout,is_causal,enable_gqa)
torch.backends.cuda.can_use_flash_attention(p, True) # debug=True → 打印被拒原因
torch.backends.cuda.can_use_efficient_attention(p, True)
torch.backends.cuda.can_use_cudnn_attention(p, True)
这就是我上面用来实测的方式(torch.backends.cuda.can_use_* 在 2.11 上都在)。
③ 用 sdpa_kernel 上下文逐个强制,确认哪个能跑/哪个更快
from torch.nn.attention import SDPBackend, sdpa_kernel
with sdpa_kernel(SDPBackend.FLASH_ATTENTION): o = F.scaled_dot_product_attention(q,k,v)
with sdpa_kernel(SDPBackend.EFFICIENT_ATTENTION): ...
with sdpa_kernel(SDPBackend.CUDNN_ATTENTION): ...
with sdpa_kernel(SDPBackend.MATH): ...
④ 终极手段:profiler 看真正执行的 kernel 名(我上面用的就是这招,最不容易被骗)
from torch.profiler import profile, ProfilerActivity
with profile(activities=[ProfilerActivity.CUDA]) as prof:
F.scaled_dot_product_attention(q, k, v); torch.cuda.synchronize()
print(prof.key_averages().table(sort_by="cuda_time_total"))
判读:pytorch_flash::flash_fwd_kernel = FA2;fmha_cutlassF_* / cutlass = mem-efficient;cudnn* / cudnn_frontend = cuDNN;纯 softmax/bmm = math。
⑤ 相关开关/环境变量
torch.backends.cuda.enable_flash_sdp(True/False)
torch.backends.cuda.enable_mem_efficient_sdp(True/False)
torch.backends.cuda.enable_math_sdp(True/False)
torch.backends.cuda.enable_cudnn_sdp(True/False)
torch.backends.cuda.flash_sdp_enabled() / mem_efficient_sdp_enabled() / math_sdp_enabled() / cudnn_sdp_enabled()
TORCH_CUDNN_SDPA_DEPRIORITIZED=1 → 强制取消 cuDNN 优先(建议在你们这套机器上固定设置,见 §5)。注意:即使不设,sm_120 本来也不会 prefer cuDNN,所以这条更多是"防御性"的,防止未来 torch/cuDNN 版本改变判断。torch.nn.attention.list_flash_attention_impls() / current_flash_attention_impl() / activate_flash_attention_impl() 与 TORCH_FLASH_ATTENTION_IMPL env。本机实测 list_flash_attention_impls() == ['FA3', 'FA4']、current_flash_attention_impl() is None —— 这是新机制,含义是"可注册的 FA 实现列表",当前未激活任何自定义实现,默认仍走内置 pytorch_flash(profiler 已证实)。⚠️ 不确定项:FA3/FA4 在这份 wheel 里以什么形式存在(是否只是 registry 占位),我没有进一步验证;从 profiler 结果看不影响默认路径。在 5060 Ti + torch 2.11.0+cu130 + bf16/fp16 + 典型 DiT 形状下:
默认 = attention_pytorch → PyTorch SDPA → priority_order = flash → efficient → cudnn → math
→ check_prefer_cudnn_attention() = false(major=12 不满足 9||10)
→ can_use_flash_attention = True
→ 实跑: pytorch_flash::flash_fwd_kernel ✅
换句话说:你们现在这条生产路径已经在用 FA2,而且这是 sm_120 上目前最稳妥的选择。
结论:sm_120 无支持,不要装。 依据(全部为 open issue,多数长期无解):
| Issue | 标题 / 要点 |
|---|---|
| facebookresearch/xformers#1342 | Issue with 50-Series Graphics Card Compatibility for xFormers(2025-10-05 开) |
| #1279 | "The xformers wheel does not support the 50-series GPUs." |
| #1356 | requires device with capability < (8, 0) but your GPU has capability (12, 0) (too new) |
| #1357 | "cutlass attention completely blocked on Blackwell with no fallback path" |
| #1329 | 带 Flash Attention 编译 xformers 后 RTX 50 系直接 CUDA error |
| #1231 | 5090(D) + CUDA 12.8 编译在 /sparse24_gemm_sm90.cu:292 失败 |
| #1395 | Blackwell Support(2026-04-29 开,feature request) |
| #1282 | [FEATURE] FA3 Blackwell |
旁证:Rogala/AI_Attention 的选型建议直接写 "You have SageAttention → Skip xFormers — it adds no benefit when SageAttention is active";本机 xformers NOT INSTALLED、xformers_enabled() 因此为 False。 ComfyUI 侧:--disable-xformers 是既有 flag,但既然包都没装,这条不适用。
| 优先级 | 方案 | 理由 | 动作 |
|---|---|---|---|
| 1(默认,强烈推荐) | 保持现状:PyTorch SDPA 内置 FA2 | sm_120 上唯一同时满足"官方支持 + 已实测 + 零掉卡报告"的路径;你现在的运行命令里一个 attention flag 都没有,已经在用 | 什么都不用做;把"当前后端"记进运维记录,避免以后误加 flag |
| 2(想再快,需谨慎验证) | --use-ck-attention(comfy-kitchen int8 attention) | ComfyUI 0.38 + woct0rdho 官方推荐路线;本机 int8_attention_is_available=True 已实测;不需要装 sageattention wheel,没有版本错配/DLL 风险;CUDA arch 默认含 120f | 先在 1 个短视频上跑通 + 目视检查输出(防 §1.4c 那类静默噪声);确认无误再放开 |
| 3(不推荐) | SageAttention 2.2.0 + FP8-PV(无论 --use-sage-attention 还是 KJNodes auto) | 有同款 GPU / 同款模型的 GPU lost 报告,且单变量对照排除了显存/功耗/温度;另有两个静默数据损坏 issue | 🔴 不要再加;当前机器也确实没装 |
| 3'(若因某些原因必须用 Sage) | Sage 但强制走 fp16-PV:sageattn_qk_int8_pv_fp16_cuda(或 issue #391 评论里的 sm80 fp16 kernel 改法) | 社区实测:保留 int8-QK 的加速、去掉 FP8-PV 后,两次运行均稳定,且仍比原生快 ~21% | 仅在必须有 Sage 时;注意 ComfyUI #15263 的编辑说 sm120 上该 KJNodes 选项"第一次 attention 调用就 abort",两个说法冲突 → 必须自己实测 |
| 4(不要) | xformers / 第三方 flash-attn / flash-attn-3 | sm_120 无支持(xformers 甚至硬阻塞无 fallback);flash-attn 在 Windows 无预编译 wheel 且官方不支持 Blackwell;而它们想提供的 FA2 你已经通过 PyTorch 内置拿到了 | ❌ |
| 5(观察) | flash-attn-4[cu13] | 维护者明说"最终会覆盖 sm80–sm120,但当前测试只覆盖 sm90–sm100",sm120 仍有 open 的 illegal memory access / OOB / 长序列 bug,PR 活跃到 2026-10-11 | 3–6 个月后再评估 |
一句话:这台卡的最优解就是"什么都不装" —— PyTorch 2.11 内置的 FA2 已经覆盖 sm_120,任何第三方注意力包在当前阶段都是风险 > 收益。真要提速,优先试官方路线 --use-ck-attention,而不是 SageAttention。
# ① 看启动命令(有没有 attention flag)
ps -eo args | grep "[m]ain.py"
# ② 看启动日志里的那一行
grep -E "Using (sage|Flash|xformers|pytorch|Comfy Kitchen|split|sub quadratic)" <comfyui日志路径>
# ③ 在 ComfyUI 的 venv 里跑后端资格探针(只读,不改文件)
/home/zyw/ComfyUI/venv/bin/python - <<'EOF'
import torch, torch.nn.functional as F
from torch.backends.cuda import SDPAParams
from torch.nn.attention import SDPBackend, sdpa_kernel
from torch.profiler import profile, ProfilerActivity
print("torch", torch.__version__, "| cap", torch.cuda.get_device_capability(0))
print("enabled: flash=%s mem_eff=%s cudnn=%s math=%s" % (
torch.backends.cuda.flash_sdp_enabled(), torch.backends.cuda.mem_efficient_sdp_enabled(),
torch.backends.cuda.cudnn_sdp_enabled(), torch.backends.cuda.math_sdp_enabled()))
for D in (64, 128, 256):
q = torch.randn(1, 32, 4096, D, dtype=torch.bfloat16, device="cuda")
p = SDPAParams(q, q, q, None, 0.0, False, False)
print("hd", D, "flash", torch.backends.cuda.can_use_flash_attention(p),
"eff", torch.backends.cuda.can_use_efficient_attention(p),
"cudnn", torch.backends.cuda.can_use_cudnn_attention(p))
q = torch.randn(1, 32, 4096, 128, dtype=torch.bfloat16, device="cuda")
for _ in range(3): F.scaled_dot_product_attention(q, q, q)
torch.cuda.synchronize()
with profile(activities=[ProfilerActivity.CUDA]) as prof:
F.scaled_dot_product_attention(q, q, q); torch.cuda.synchronize()
for e in prof.key_averages():
if any(t in e.key.lower() for t in ("flash", "cudnn", "fmha", "cutlass", "softmax")):
print(" KERNEL:", e.key[:110])
EOF
判读表:pytorch_flash::flash_fwd_kernel* → FA2(你们的目标状态);fmha_cutlassF_* → mem-efficient;含 cudnn → cuDNN;只有 softmax/bmm → math(说明前两者都被拒了,要看 debug 原因)。
另建议:既然 §1.5 的驱动 GSP bug 无法用 NVreg_DynamicPowerManagement=0x00 规避,无论选哪个注意力后端,都应该先把 AGENTS.md 里记的"10-03 报告 §5 捕获/自愈设施"落地(RuntimeWatchdogSec=30s / netconsole / kdump / lm-sensors —— 至今一项没落地),这样下次掉总线时才有第二次样本可归因。
cudnn 91900(9.19)。PyTorch 2.11+cu130 wheel 自带 cuDNN,但系统也可能装了 NVIDIA 的 libcudnn9-cuda-13。二者都会满足 >91500;不过对 sm120 的 prefer_cudnn 判定关键是 major==9||10,与 cuDNN 版本无关,所以不影响 §3.1 的结论。list_flash_attention_impls() == ['FA3','FA4'] 的实际含义:这两个"实现"是否真的可在 sm_120 上激活未验证;它不影响默认路径(profiler 已确认走 pytorch_flash)。| 内容 | URL | 日期 |
|---|---|---|
| SageAttention 主 README(Ampere/Ada/Hopper 声明、5090 更新日志、安装) | https://github.com/thu-ml/SageAttention | 提交 c03f15fb 2025-12-22(main HEAD 状态) |
sageattention/core.py(sm120 分发分支与注释) | https://github.com/thu-ml/SageAttention/blob/main/sageattention/core.py | 2025-12-22 |
setup.py(SUPPORTED_ARCHS 含 12.0/12.1) | https://github.com/thu-ml/SageAttention/blob/main/setup.py | 同上 |
| SageAttention3 Blackwell 子目录 README(需 python≥3.13/torch≥2.8/CUDA≥12.8,须源码编译,仅 5090 档) | https://github.com/thu-ml/SageAttention/tree/main/sageattention3_blackwell | 2025-09-27 发布 |
提交 4b0824de "sm120 early support (#109)" | https://github.com/thu-ml/SageAttention/commit/4b0824de | 2025-02-15 |
| FlashAttention README(FA2/FA3/FA4 支持声明) | https://github.com/Dao-AILab/flash-attention | 当前 main |
PyTorch sdp_utils.cpp(优先级 + 各后端硬件门限) | https://github.com/pytorch/pytorch/blob/release/2.11/aten/src/ATen/native/transformers/cuda/sdp_utils.cpp | release/2.11 |
PyTorch cutlassF.h(mem-efficient 的 80<=cc<=120 分发) | https://github.com/pytorch/pytorch/blob/release/2.11/aten/src/ATen/native/transformers/cuda/mem_eff_attention/kernels/cutlassF.h | release/2.11 |
comfy-kitchen README(CUDA arch 默认含 120f;int8_attention 能力表) | https://github.com/Comfy-Org/comfy-kitchen | pushed 2026-10-14 |
comfy-kitchen sage_attention.py(_NATIVE_MINIMUM_CAPABILITY=(7,5)) | https://github.com/Comfy-Org/comfy-kitchen/blob/main/comfy_kitchen/sage_attention.py | 同上 |
ComfyUI attention.py / cli_args.py / model_management.py | https://github.com/comfyanonymous/ComfyUI | master(0.38.0) |
| 内容 | URL | 日期 / 状态 |
|---|---|---|
| 同款 5060 Ti:H3 生成中 GPU lost(int8-QK/FP8-PV),含单变量对照 + 稳定 workaround | https://github.com/thu-ml/SageAttention/issues/391 | 2026-08-16 开 / 2026-08-19 更新 / open |
| sm_120 FP8-PV >160k token 静默噪声 | https://github.com/thu-ml/SageAttention/issues/388 | 2026-08-14 开 / 2026-10-07 更新 / open |
| sm_120 CUDA Graph 重放静默算错 | https://github.com/thu-ml/SageAttention/issues/392 | 2026-08-18 开 / open |
同款 5060 Ti:SageAttention3 misaligned address | https://github.com/thu-ml/SageAttention/issues/357 | 2026-03-29 开 / open |
| RTX PRO 5000 (sm_120) SA3-FP4 只有 1.17×(occupancy 20%) | https://github.com/thu-ml/SageAttention/issues/378 | 2026-07-21 开 / open |
| sm_120 TMA descriptor 在 ~74k token 失败 + illegal instruction | https://github.com/thu-ml/SageAttention/issues/382 | 2026-08-05 开 / open |
| 5090 编译:wgmma 在 sm_120 不被支持 | https://github.com/thu-ml/SageAttention/issues/291 | 2025-10-30 开 / 2026-04-20 更新 / open |
| 2.2 是否支持 sm120(含缺逗号 bug + "只有约 6% 加速") | https://github.com/thu-ml/SageAttention/issues/303 | 2025-11-15 / closed(提问者自认"大概就是这样") |
| 50 系通用失败(55 条评论,跨年) | https://github.com/thu-ml/SageAttention/issues/148 | 2025-03-24 开 / open |
| SageAttention3 仅 5090 档,是否扩展到其它 Blackwell | https://github.com/thu-ml/SageAttention/issues/237 | 2025-08-12 开 / open |
| FA2 Blackwell 支持请求(无官方答复) | https://github.com/Dao-AILab/flash-attention/issues/1987 | 2025-11-05 开 / 2026-03-09 更新 / open |
| FA4 支持哪些 SM(维护者澄清:最终覆盖 sm80–sm120,当前测试只到 sm90–sm100) | https://github.com/Dao-AILab/flash-attention/issues/2376 | 2026 / open |
| FA4 SM120 支持询问 | https://github.com/Dao-AILab/flash-attention/issues/2307 | open |
| cuDNN SDPA 在 sm_120 的 head_dim 上限卡在 128 | https://github.com/pytorch/pytorch/issues/181379 | open |
| xformers 50 系兼容性 | https://github.com/facebookresearch/xformers/issues/1342 | 2025-10-05 开 / open |
| xformers wheel 不支持 50 系 | https://github.com/facebookresearch/xformers/issues/1279 | open |
xformers capability (12,0) too new | https://github.com/facebookresearch/xformers/issues/1356 | open |
| xformers cutlass attention 在 Blackwell 被完全阻塞且无 fallback | https://github.com/facebookresearch/xformers/issues/1357 | open |
| xformers Blackwell Support(feature request) | https://github.com/facebookresearch/xformers/issues/1395 | 2026-04-29 开 / open |
| ComfyUI:H3 + Sage sm_120 噪声(含"0.31.1 后好像好了"+ sm120 上 KJNodes 选项全废的编辑) | https://github.com/Comfy-Org/ComfyUI/issues/15263 | 2026-08-03 开 / open |
| ComfyUI:H3 Linux 多卡 INT8 ConvRot 整机硬重启 | https://github.com/Comfy-Org/ComfyUI/issues/15455 | 2026-08-20 开 / open |
| ComfyUI:H3 fp8_scaled + Sage + dynamic VRAM 时进程 abort | https://github.com/Comfy-Org/ComfyUI/issues/15566 | 2026-08-13 开 / open |
| ComfyUI:RTX 5090 跑 H3 崩溃 | https://github.com/Comfy-Org/ComfyUI/issues/15275 | 2026-08-11 开 / open |
| 驱动 595.71.05 + 5060 Ti 的 GSP P-state 崩溃(GPU fallen off the bus) | https://discuss.cachyos.org/t/.../28856 | 2026-05-01 |
| 上游 GSP 掉总线追踪 | https://github.com/NVIDIA/open-gpu-kernel-modules/issues/739 | open |
| 内容 | URL | 日期 |
|---|---|---|
woct0rdho SageAttention Windows fork(wheel 覆盖 sm120;推荐 ComfyUI 改用 --use-ck-attention) | https://github.com/woct0rdho/SageAttention | pushed 2026-10-09 |
RTX 5060 Ti 16GB 的注意力 kernel 基准 JSON(env: torch 2.12.0.dev+cu132 / cu132 / sageattention 2.2.0 / sa3 1.0.0 / triton 3.6.0 / Windows) | https://github.com/Rogala/SageAttention-Benchmark-Viewer (results/5060-ti-16_Ref.json) | JSON 内 env 未标日期;仓库活跃 |
| 可视化查看器 | https://rogala.github.io/SageAttention-Benchmark-Viewer/ | 同上 |
| SM120 的 xFormers/SageAttention/FlashAttention Windows 预编译包 + 选型建议 | https://github.com/Rogala/AI_Attention | 当前 |
| SageAttention 2.2.0 Blackwell sm_120 wheel(cu128/cu130, torch 2.11 nightly)+ 端到端 ~35%(5090 Laptop) | https://github.com/mobcat40/sageattention-blackwell | 2026-01-28 |
| 同上(cp313 变体) | https://github.com/ziggyxp/sageattention-blackwell-pt211-cu130-cp313 | — |
sm_120a 编译的 2.2.0 wheel | https://huggingface.co/sanjxz/sageattention-2.2.0-blackwell-sm120a | — |
| SageAttention3 Blackwell FP4 预编译 | https://huggingface.co/nhathoangfoto/SageAttention-3-Blackwell-FP4 | — |
FA4 sm120 社区分叉(含 pack_gqa=False on Sm120/Sm120Tma 修复) | https://huggingface.co/SecondNatureComputing/flash-attn-4-sm120 · https://huggingface.co/vonkaiser/flash-attn-4-sm120 | — |
社区运维 skill:"kitchen INT8 attention 可用时优先 --use-ck-attention,跳过 sageattention wheel" | https://raw.githubusercontent.com/artokun/comfyui-mcp/main/plugin/skills/triton-sageattention/SKILL.md | 校对于 2026-06 |
192.168.31.31:torch 2.11.0+cu130 / cuda 13.0 / cudnn 91900 / RTX 5060 Ti (12,0) / comfy-kitchen 0.2.37 / triton 3.6.0 / torch 2.11.0+cu130; sageattention、sageattn3、xformers、flash_attn 均 未安装; can_use_flash_attention=True(hd 64/128/256)、can_use_cudnn_attention=False(hd 256); profiler 默认路径 = pytorch_flash::flash_fwd_kernel; comfy_kitchen.int8_attention_is_available() / sol_attn_is_available() = True; ComfyUI 0.38.0 运行命令不含任何 attention flag。