Nodes/ComfyUI_Swwan/Patch Sage Attention KJ (KJ Alternative)
ComfyUI Node

Patch Sage Attention KJ (KJ Alternative)

SageAttention, minus the KJNodes dependency

By aining2022·Created 10 months ago·Updated 18 days ago· 33
Patch Sage Attention KJ (KJ Alternative)
  • model
  • MODEL
sage_attentiondisabled
allow_compilefalse

SageAttention is the cheapest speedup in ComfyUI and the one people bounce off hardest, because when it breaks it's almost never the node's fault. This is the version of kijai's famous "Patch Sage Attention KJ" that ships inside the ComfyUI_Swwan pack, under its own class name so both can sit in the same graph without colliding.

What it is

You feed it a MODEL, pick a SageAttention kernel, and it patches the model's attention to run THU-ML's quantized kernels instead of the default path. That's the whole job - no models to download, no API, no hidden files. On video diffusion - Wan, Hunyuan, the LTX family - this is where the "free 1.5x" reports come from (kijai measured about that on HunyuanVideo when v2.1 landed).

The sage_attention dropdown is a list of kernel variants, and the names are doing real work:

  • auto - let the node decide.
  • sageattn_qk_int8_pv_fp16_cuda / _triton - the classic v2 kernels on a CUDA or Triton backend.
  • _fp8_cuda, _fp8_cuda++ (Blackwell), _fp8_cuda_sm90 (Hopper) - fp8 variants for newer architectures.
  • sageattn3 / sageattn3_per_block_mean - the v3 kernels, only if you've actually installed sageattn3.
  • disabled - removes the override. This is the escape hatch people forget about: if you patched a model and it's producing garbage, set disabled and you're back to stock attention without reloading the checkpoint.

There's one optional toggle, allow_compile, which lets torch.compile run inside the SageAttention wrapper on backends that support it. Leave it off unless you know you want it.

Where people get burned

The install. The node is in the pack, but SageAttention itself is not - it has to be in the ComfyUI Python environment:

pip install sageattention      # or: pip install sageattn3

On Linux that's often genuinely it. On Windows it's the classic saga: try prebuilt wheels first, and if you have to compile you'll be digging out MSVC's cl.exe and matching CUDA versions to your torch build. The single most common error - no module named sageattention - is exactly this: the node updated, the kernel didn't.

Two more real ones. First, not every model plays nice. The community found Qwen + SageAttention producing all-black images, and the consensus was to just delete the node for Qwen rather than hunt a config that doesn't exist. Second, "I see no speedup" sometimes just means the kernel doesn't match your GPU - if you're on an older card, the fp16 or Triton variants beat the fp8 ones, and some models gain almost nothing from Sage at all.

Install the pack

ComfyUI Manager, search "ComfyUI_Swwan", or:

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
pip install -r ComfyUI_Swwan/requirements.txt

restart, done. The pack's own requirements are modest - torch, numpy, opencv, spandrel, color-matcher - none of it is the SageAttention stack, which stays your responsibility.

The honest verdict

When it works it's a real speedup on video models, the kind you reach for before buying hardware. When it doesn't, it's version-mismatch whack-a-mole between torch, CUDA, Triton and the kernel - none of which this node controls. Test it on one workflow before you wire it into all of them, and keep the disabled option in your back pocket.

CategorySwwan/model

Inputs (3)

NameTypeDefaultDescription
modelMODEL
sage_attentionCOMBOdisabledPatch the model attention override to use SageAttention. Choose disabled to remove an existing SageAttention override.
allow_compileoptBOOLEANfalseAllow torch.compile inside the SageAttention wrapper when the backend supports it.

Outputs (1)

NameTypeDescription
MODELMODEL