ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

using sageattention 2 qwen-image in comfyui shows black images due to buggy upstream sageattention triton implementation, includes fix

Open doctorpangloss opened this issue 1 year ago • 11 comments

Custom Node Testing

Expected Behavior

when the user specifies --use-sage-attention and tries to inference with qwen-image, the user will get NaNs (i.e. black images)

Actual Behavior

NaNs and black images when using sage-attention with qwen-image (related to #9046 #9184 #9077)

the triton backend seems to be broken in 2.2 for qwen-image on ampere, so

    if arch in ("sm80", "sm86"):
        return sageattn_qk_int8_pv_fp16_cuda(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse, pv_accum_dtype="fp32")
    # elif arch == "sm86":
    #     return sageattn_qk_int8_pv_fp16_triton(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse)

fixes the issue

Steps to Reproduce

--use-sage-attention with sageattention 2.2+ and the qwen-image default workflow

Debug Logs

n/a

Other

No response

doctorpangloss avatar Sep 08 '25 21:09 doctorpangloss

When I want to use qwen-image I have to start up without sage attention, I have this same bug too and I just updated to the latest version last night.

aivrar avatar Sep 13 '25 19:09 aivrar

the triton backend seems to be broken in 2.2 for qwen-image on ampere, so

if arch in ("sm80", "sm86"):
    return sageattn_qk_int8_pv_fp16_cuda(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse, pv_accum_dtype="fp32")
# elif arch == "sm86":
#     return sageattn_qk_int8_pv_fp16_triton(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse)

fixes the issue

can you point me to a specific file in ComfyUI to replace bugged code?

orakul99 avatar Sep 19 '25 11:09 orakul99

the triton backend seems to be broken in 2.2 for qwen-image on ampere, so

if arch in ("sm80", "sm86"):
    return sageattn_qk_int8_pv_fp16_cuda(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse, pv_accum_dtype="fp32")
# elif arch == "sm86":
#     return sageattn_qk_int8_pv_fp16_triton(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse)

fixes the issue

can you point me to a specific file in ComfyUI to replace bugged code?

It's fixed in the fork

https://github.com/hiddenswitch/comfyui

There isn't a line in upstream to point to sorry

doctorpangloss avatar Sep 19 '25 16:09 doctorpangloss

Using the old KJNodes 'Patch Sage Attention' but set it to fp16_cuda (not auto or disabled) makes it work. Otherwise I was getting black images with --use-sage-attention in my startup.

triton-windows  3.3.1.post19
sageattention 2.2.0
pytorch 2.7.1 cuda 12.8

On an RTX 3xxx series.

jorismak avatar Sep 30 '25 17:09 jorismak

Если использовать старые KJNodes «Patch Sage Attention», но настроить их на fp16_cuda (не на auto или отключённые), то всё заработает. В противном случае при запуске я получал чёрные изображения с --use-sage-attention

triton-windows  3.3.1.post19
sageattention 2.2.0
pytorch 2.7.1 cuda 12.8

На видеокарте серии RTX 3xxx.

Thanks! It also works on RTX 4090.

alexvorf avatar Sep 30 '25 18:09 alexvorf

i have the same problem here since the new update today.

I'm using Stability Matrix Installation Version. Sage Attention seems to work for Wan, but i do not notice any speed upgrades.

Total VRAM 24564 MB, total RAM 65447 MB pytorch version: 2.8.0+cu129 xformers version: 0.0.32.post1 Set vram state to: NORMAL_VRAM Device: cuda:0 NVIDIA GeForce RTX 4090 : cudaMallocAsync Using sage attention Python version: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] ComfyUI version: 0.3.63 ComfyUI frontend version: 1.27.7

720x1280 Wan2.2 test was like this:

loaded partially 8751.377719974518 8751.37771987915 0 Patching comfy attention to use sageattn 100%|██████████| 6/6 [03:44<00:00, 37.36s/it] Restoring initial comfy attention Requested to load WanVAE loaded completely 1779.9325942993164 242.02829551696777 True loaded partially 7549.748311047077 7549.748264312744 0 Patching comfy attention to use sageattn 100%|██████████| 6/6 [03:50<00:00, 38.34s/it] Restoring initial comfy attention Requested to load WanVAE loaded completely 2054.9863471984863 242.02829551696777 True loaded partially 7549.748311047077 7549.748264312744 0 Patching comfy attention to use sageattn 100%|██████████| 6/6 [03:47<00:00, 37.98s/it] Restoring initial comfy attention Requested to load WanVAE loaded completely 2455.0645332336426 242.02829551696777 True Prompt executed in 00:15:00

But with Qwen Edit or Image i only receive Black Output, no matther which setting i chosse for the sageattention node.

Nakasara1 avatar Oct 07 '25 09:10 Nakasara1

go to ComfyUI/venv/lib/python3.10/site-packages/sageattention/core.py go to line 118 replace with this arch = get_cuda_arch_versions()[q.device.index] if arch in ("sm80", "sm86"): return sageattn_qk_int8_pv_fp16_cuda(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse, pv_accum_dtype="fp32") # elif arch == "sm86": # return sageattn_qk_int8_pv_fp16_triton(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse) elif arch == "sm89":

jandan520 avatar Mar 10 '26 20:03 jandan520

@jandan520 could you give a bigger context for this change? I'm using a different version of sageattention and line 118 for sure isn't the one I should be replacing...

ssuukk avatar Mar 11 '26 14:03 ssuukk

I found this is caused by the triton kernel in SageAttention computing NaNs when handling these specific tensor formats on sm86 (Ampere) architectures like the RTX 3090.

Environment:

  • GPU: RTX 3090 (sm86)
  • PyTorch: 2.10.0+cu128
  • SageAttention: 2.2.0

The Workaround / Fix: Forcing the sm86 architecture to fall back to the cuda kernel instead of the default triton kernel completely resolves the NaN issue and restores both image output and acceleration.

In sageattention/core.py, modify the routing logic around line 118:

Before:

    if arch == "sm80":
        return sageattn_qk_int8_pv_fp16_cuda(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse, pv_accum_dtype="fp32")
    elif arch == "sm86":
        return sageattn_qk_int8_pv_fp16_triton(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse)

After:

    if arch in ("sm80", "sm86"):
        return sageattn_qk_int8_pv_fp16_cuda(q, k, v, tensor_layout=tensor_layout, is_causal=is_causal, sm_scale=sm_scale, return_lse=return_lse, pv_accum_dtype="fp32")
    # elif arch == "sm86":
    #     return sageattn_qk_int8_pv_fp16_triton(...)

This might be helpful for anyone stuck with black images using Qwen DiT models on 30-series cards while wanting to keep SageAttention enabled globally.


jandan520 avatar Mar 11 '26 16:03 jandan520

I built a quick custom node that allows for per model opt out. my situation was that sage worked (rtx 3070) for most things, but not for 2511, and I didn't want to disable sage for everything just to get compatibility for one model family.

https://github.com/EnviralDesign/comfy-sageattention-optout-customnodes

EnviralDesign avatar Mar 26 '26 19:03 EnviralDesign

Thanks, that's very handy!

XenoAmp - a media player with a difference • Demo on [image: YouTube] YouTube https://www.youtube.com/watch?v=DnuQzpIodto • Get it ftom Google Play https://play.google.com/store/apps/details?id=pl.qus.xenoamp • Folow it on Twitter https://twitter.com/XenoAmpMusic • Report bugs to XDA Thread http://forum.xda-developers.com/showthread.php?t=1822492

[image: XenoBanner]

czw., 26 mar 2026, 20:46 użytkownik LUCAS M MORGAN @.***> napisał:

EnviralDesign left a comment (Comfy-Org/ComfyUI#9773) https://github.com/Comfy-Org/ComfyUI/issues/9773#issuecomment-4137759694

I built a quick custom node that allows for per model opt out. my situation was that sage worked (rtx 3070) for most things, but not for 2511, and I didn't want to disable sage for everything just to get compatibility for one model family.

https://github.com/EnviralDesign/comfy-sageattention-optout-customnodes

— Reply to this email directly, view it on GitHub https://github.com/Comfy-Org/ComfyUI/issues/9773?email_source=notifications&email_token=AAV3O6O757E5PPN73I6RXTD4SWCKFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMJTG43TKOJWHE2KM4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4137759694, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3O6IVFVQPZYFXBRG5MOT4SWCKFAVCNFSM6AAAAACF6YRXI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DCMZXG42TSNRZGQ . You are receiving this because you commented.Message ID: @.***>

ssuukk avatar Mar 28 '26 12:03 ssuukk