2026-10-14-RTX50系列sm120注意力后端调研.md

RTX 50 系(Blackwell / sm_120)在 ComfyUI + PyTorch 生态的注意力后端与加速内核现状

调研日期: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 探针实测。未修改任何文件。


0. 结论速览(含一处必须先纠正的前提)

⚠️ 最重要的一条:任务背景里"怀疑 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/HopperWindows 基本装不上—❌ 不要;用 PyTorch 内置的即可
FlashAttention3❌ Hopper 专属不适用—❌ 不要
FlashAttention4(flash-attn-4)🟡 开发中,目标覆盖到 sm120维护者明说测试只覆盖 sm90–sm100🔴 sm120 仍有多个 open bug⚠️ 观察,别上生产
xformers❌ 无预编译 wheel 不支持🔴 cutlass 路径在 Blackwell 被硬阻塞且无 fallback❌ 不要

1. SageAttention

1.1 官方声明 vs 实际代码(2.x)

官方 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 已修。

版本对应关系:

1.2 安装与启用的正确方式

Windows(社区事实标准:woct0rdho fork)

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

⚠️ 编译坑(如果非要编):

ComfyUI 里的启用方式(三种)

  1. --use-sage-attention 启动参数 = 全局替换(comfy/ldm/modules/attention.py 里 optimized_attention = attention_sage)。
  2. KJNodes 的 Patch Sage Attention KJ 节点 = 单工作流替换,可选具体 kernel(auto / sageattn_qk_int8_pv_fp16_cuda / sageattn_qk_int8_pv_fp8_cuda / sageattn3_blackwell 等)。
  3. --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 的实测反驳。

1.3 速度收益(区分"官方数据"与"社区实测")

官方(thu-ml)声明:

社区实测 —— 最贴近你机器的数据(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.9530.6160.589ERR(SA3 要求 hd=128)3.17×
SD3.5-L 1024², 4250 tok (hd64)7.7351.8641.962ERR4.15×
Flux.1-Dev 1024², 4352 tok (hd128)12.8172.3922.5532.1975.36×
Flux.2-Dev 1440², 8612 tok97.07715.02115.5269.0366.46×
Qwen-Image-2512 1920², 14489 tok136.1019.74520.17412.3986.89×
Wan2.2 1280×720, 18000 tok347.7249.45750.21130.6737.03×
Wan2.2 1920×1088, 40800 tok1774.7241.88242.73152.837.34×
HunyuanVideo-1.5 1280×720, 111677 tok5451.3709.4707.0ERR7.69×
ACE-Step 1.5 audio 50s, 1250 tok0.7980.3560.4360.9792.24×

⚠️ 阅读这段数据必须注意三点,否则会得出错误结论:

  1. 这是 kernel 级(attention 算子)加速,不是端到端。真实端到端收益被采样器/VAE/其它算子摊薄。mobcat40 在 5090 Laptop 上实测端到端 ~35%;artokun/comfyui-mcp 的 triton-sageattention skill 给的社区经验值是 ~20–40%。
  2. head_dim=64 的模型(SDXL/SD3.5)SDPA 本来就很快,Sage 的绝对收益很小(0.6ms vs 1.9ms,但占比整个采样步很低);hd=128 的 DiT(Flux/Qwen/Wan/LTX/H3)才是 Sage 的主场。
  3. SA3-FP4 在同一张 5060 Ti 上确实比 SA2 再快 ~20–40%(与 §1.4 的 bug 报告形成对照:能跑就快,但有卡跑不了)。另有 issue #378 报告在 RTX PRO 5000(sm_120, 110 SM) 上 SA3-FP4 只有 1.17× 于 SA2(论文是 1.84×),原因被 Nsight 定位为 occupancy 只有 ~20%、1 block/SM、寄存器+共享内存双重受限、kernel 是 latency-bound。

1.4 崩溃 / 挂死报告 —— 🔴 这一节和你们的历史问题高度重合

(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

项内容
GPUNVIDIA 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-VGPU lost ~54 s
workaround run 1int8-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)同一内核的静默数据损坏

(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 专项)

1.5 ⚠️ 必须单独提的一条:驱动 595.71.05 自身就有 GSP 掉总线 bug(与本机驱动版本完全一致)

即便完全不碰 attention,"驱动 595.71.05 + 5060 Ti"这个组合本身就有独立的 GSP 挂死记录: CachyOS 论坛 / JustFromArch, 2026-05-01

对你们的意义:AGENTS.md 里"NVreg_DynamicPowerManagement=0x00 已生效(/proc 里读出来是 0)"这件事,并不能证明它防住了 GSP 挂死——在 595.71.05 上它对 P-state 转换引发的 GSP 崩溃没效果。Sage 的 FP8-PV 内核很可能只是"加重触发",而不是唯一根因。 这一条我标注为强相关但未确证(你们机器是 Deepin 25 Xorg+核显输出、驱动同为 595.71.05,与报告环境高度接近但不完全相同)。

1.6 ⭐ 你们这台机器上其实已经有一个官方推荐的替代:comfy-kitchen int8 attention

ComfyUI 0.38.0 的 comfy/ldm/modules/attention.py 第一行就 import comfy_kitchen(硬依赖),并提供:

而 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):

我在你们 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)之后再放开跑。


2. FlashAttention

2.1 官方支持状态

版本官方声明支持的架构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。

2.2 FA4 的真实成熟度(这是最关键的官方口头澄清)

[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 是"在修、能用一部分、别上生产"。 社区另有第三方 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 路径默认参数都有坑。

2.3 ⭐ PyTorch 内置 SDPA 的 flash backend 确实覆盖 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:


3. PyTorch 原生 SDPA:sm_120 默认走哪个后端

3.1 优先级表(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

解读:

3.2 各后端的 sm120 资格(源码 + 实测)

后端源码硬件门限(2.11 / main)sm120 实测
flashcheck_sm_version<sm80, sm121>✅ can_use_flash_attention=True(hd 64/128/256)
mem-efficientcheck_sm_version<sm50, sm121>✅ True
cudnncheck_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 能跑通。

3.3 cuDNN 在 sm120 的一个已知硬缺口(会影响 f16 hd=256 的模型)

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 问题),但在做后端对比实验时要记住这一点。

3.4 怎么确认当前实际用的是哪个后端(四层,从粗到细)

① 看 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()

3.5 落在这台机器上的结论

在 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 上目前最稳妥的选择。


4. xformers

结论:sm_120 无支持,不要装。 依据(全部为 open issue,多数长期无解):

Issue标题 / 要点
facebookresearch/xformers#1342Issue with 50-Series Graphics Card Compatibility for xFormers(2025-10-05 开)
#1279"The xformers wheel does not support the 50-series GPUs."
#1356requires 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
#12315090(D) + CUDA 12.8 编译在 /sparse24_gemm_sm90.cu:292 失败
#1395Blackwell 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,但既然包都没装,这条不适用。


5. 结论与建议(针对这台 5060 Ti 16GB / sm_120)

5.1 推荐决策

优先级方案理由动作
1(默认,强烈推荐)保持现状:PyTorch SDPA 内置 FA2sm_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-3sm_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-113–6 个月后再评估

一句话:这台卡的最优解就是"什么都不装" —— PyTorch 2.11 内置的 FA2 已经覆盖 sm_120,任何第三方注意力包在当前阶段都是风险 > 收益。真要提速,优先试官方路线 --use-ck-attention,而不是 SageAttention。

5.2 在 ComfyUI 里验证"当前到底用哪个后端"的可执行清单

# ① 看启动命令(有没有 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 —— 至今一项没落地),这样下次掉总线时才有第二次样本可归因。

5.3 明确标注的不确定项

  1. 驱动 595.71.05 的 GSP P-state bug 与本机历史掉总线之间的因果权重:环境高度相似(同为 5060 Ti + 595.71.05 + open 模块),但不是同一台机器/同一发行版,无法确证是主因还是次要因素。
  2. comfy-kitchen int8 attention 在 sm120 + H3 级长序列(150k+ token)上的稳定性与精度:未找到任何公开独立实测;不排除与 Sage FP8-PV 同源风险。上生产前必须小规模验证。
  3. Sage sm120 路径是否存在"确证的机械缺陷":目前只有 #391 的单变量对照(很有说服力)与 #388/#392 的静默错误的报告;上游没有任何一条被 fix/关闭,也没有官方回应。无法断言"已修"或"必崩"。
  4. 本机 cuDNN 运行时版本来源:torch 报告 cudnn 91900(9.19)。PyTorch 2.11+cu130 wheel 自带 cuDNN,但系统也可能装了 NVIDIA 的 libcudnn9-cuda-13。二者都会满足 >91500;不过对 sm120 的 prefer_cudnn 判定关键是 major==9||10,与 cuDNN 版本无关,所以不影响 §3.1 的结论。
  5. list_flash_attention_impls() == ['FA3','FA4'] 的实际含义:这两个"实现"是否真的可在 sm_120 上激活未验证;它不影响默认路径(profiler 已确认走 pytorch_flash)。
  6. ComfyUI#15263 的编辑说 ComfyUI 0.31.1 之后 H3 + Sage 在 sm_120 上"又好了"(54 min vs 94 min),但报告者自己也说 "两件事变了(ComfyUI 和 text encoder),所以我还不说它修好了",且没有后续的独立复现;与 #391(2026-08-16,0.33.0)、#388(0.32.0)两个更晚/相近的报告冲突 → 这条不可作为放开 Sage 的依据。

附:参考来源与日期

官方源码 / 官方文档

内容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.py2025-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_blackwell2025-09-27 发布
提交 4b0824de "sm120 early support (#109)"https://github.com/thu-ml/SageAttention/commit/4b0824de2025-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.cpprelease/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.hrelease/2.11
comfy-kitchen README(CUDA arch 默认含 120f;int8_attention 能力表)https://github.com/Comfy-Org/comfy-kitchenpushed 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.pyhttps://github.com/comfyanonymous/ComfyUImaster(0.38.0)

GitHub Issues(社区实测 / bug 报告)

内容URL日期 / 状态
同款 5060 Ti:H3 生成中 GPU lost(int8-QK/FP8-PV),含单变量对照 + 稳定 workaroundhttps://github.com/thu-ml/SageAttention/issues/3912026-08-16 开 / 2026-08-19 更新 / open
sm_120 FP8-PV >160k token 静默噪声https://github.com/thu-ml/SageAttention/issues/3882026-08-14 开 / 2026-10-07 更新 / open
sm_120 CUDA Graph 重放静默算错https://github.com/thu-ml/SageAttention/issues/3922026-08-18 开 / open
同款 5060 Ti:SageAttention3 misaligned addresshttps://github.com/thu-ml/SageAttention/issues/3572026-03-29 开 / open
RTX PRO 5000 (sm_120) SA3-FP4 只有 1.17×(occupancy 20%)https://github.com/thu-ml/SageAttention/issues/3782026-07-21 开 / open
sm_120 TMA descriptor 在 ~74k token 失败 + illegal instructionhttps://github.com/thu-ml/SageAttention/issues/3822026-08-05 开 / open
5090 编译:wgmma 在 sm_120 不被支持https://github.com/thu-ml/SageAttention/issues/2912025-10-30 开 / 2026-04-20 更新 / open
2.2 是否支持 sm120(含缺逗号 bug + "只有约 6% 加速")https://github.com/thu-ml/SageAttention/issues/3032025-11-15 / closed(提问者自认"大概就是这样")
50 系通用失败(55 条评论,跨年)https://github.com/thu-ml/SageAttention/issues/1482025-03-24 开 / open
SageAttention3 仅 5090 档,是否扩展到其它 Blackwellhttps://github.com/thu-ml/SageAttention/issues/2372025-08-12 开 / open
FA2 Blackwell 支持请求(无官方答复)https://github.com/Dao-AILab/flash-attention/issues/19872025-11-05 开 / 2026-03-09 更新 / open
FA4 支持哪些 SM(维护者澄清:最终覆盖 sm80–sm120,当前测试只到 sm90–sm100)https://github.com/Dao-AILab/flash-attention/issues/23762026 / open
FA4 SM120 支持询问https://github.com/Dao-AILab/flash-attention/issues/2307open
cuDNN SDPA 在 sm_120 的 head_dim 上限卡在 128https://github.com/pytorch/pytorch/issues/181379open
xformers 50 系兼容性https://github.com/facebookresearch/xformers/issues/13422025-10-05 开 / open
xformers wheel 不支持 50 系https://github.com/facebookresearch/xformers/issues/1279open
xformers capability (12,0) too newhttps://github.com/facebookresearch/xformers/issues/1356open
xformers cutlass attention 在 Blackwell 被完全阻塞且无 fallbackhttps://github.com/facebookresearch/xformers/issues/1357open
xformers Blackwell Support(feature request)https://github.com/facebookresearch/xformers/issues/13952026-04-29 开 / open
ComfyUI:H3 + Sage sm_120 噪声(含"0.31.1 后好像好了"+ sm120 上 KJNodes 选项全废的编辑)https://github.com/Comfy-Org/ComfyUI/issues/152632026-08-03 开 / open
ComfyUI:H3 Linux 多卡 INT8 ConvRot 整机硬重启https://github.com/Comfy-Org/ComfyUI/issues/154552026-08-20 开 / open
ComfyUI:H3 fp8_scaled + Sage + dynamic VRAM 时进程 aborthttps://github.com/Comfy-Org/ComfyUI/issues/155662026-08-13 开 / open
ComfyUI:RTX 5090 跑 H3 崩溃https://github.com/Comfy-Org/ComfyUI/issues/152752026-08-11 开 / open
驱动 595.71.05 + 5060 Ti 的 GSP P-state 崩溃(GPU fallen off the bus)https://discuss.cachyos.org/t/.../288562026-05-01
上游 GSP 掉总线追踪https://github.com/NVIDIA/open-gpu-kernel-modules/issues/739open

社区工程与实测数据

内容URL日期
woct0rdho SageAttention Windows fork(wheel 覆盖 sm120;推荐 ComfyUI 改用 --use-ck-attention)https://github.com/woct0rdho/SageAttentionpushed 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-blackwell2026-01-28
同上(cp313 变体)https://github.com/ziggyxp/sageattention-blackwell-pt211-cu130-cp313—
sm_120a 编译的 2.2.0 wheelhttps://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

本机只读实测(会话内完成,未写入任何文件)

下载此文件