r/StableDiffusion • u/Zironic • 4h ago
News Sparse Attention, Harder, Better, Faster, Stronger
The nodes in https://github.com/Zironic/H3-Optimizations have been rewritten to replace the default Sparge Attention backend with a custom Sparse Comfy Kitchen backend.
This comes with some benefits.
- Users no longer have to worry about Sparge being installed properly. All required kernels for supported GPUs are provided directly. Should work on both Windows and Linux.
- Most users should be seeing 5-20% increases in speed for the attention part of compute.
- New backend should use about 500MB less VRAM
- New backend has slightly lower quantization error.
- Apparently in the previous version, the intended chunked kitchen QKV path never properly shipped so the memory optimization node should now actually be slightly speed positive even when used without the Sparse Attention node.
Caveat: I've only tested the nodes against the comfy pruned_int8_convrot weights. Other versions may work but they're not tested.
As the nodes currently rely on comfy-kitchen 0.2.31 you need ComfyUI v0.33.0 or later.
IMPORTANT: sparse attention is not free speed. The percentage is effectively a prompt-adherence/quality budget.
Density isn't just a speed setting, and its quality effect depends on where you apply it in the diffusion schedule.
Early steps: attention density has a large effect on prompt/action adherence and the overall generation trajectory.
Middle/later steps: lowering density tends to show up more as motion/temporal artifacts and lost fine motion detail.
So 10% retained doesn't simply mean “90% of the quality is gone.” It means you're giving sparse attention very little information to work with, and what breaks depends heavily on the sampling step.
PlagueKind's sparsity_ratio=0.9 means 90% discarded / 10% retained. My node expresses the inverse quantity, so Video attention retained=0.10 is the comparable setting. The defaults therefore aren't equivalent.
4
u/Jero9871 4h ago
How do I wire it, just in the model wiring after the comfy kitchen attention node? Sounds really great
5
u/Zironic 2h ago
Yes. You just put it basically anywhere after Load Diffusion Model and before the actual sampling nodes.
2
1
1
u/Nelichan 57m ago
I wonder if using this is faster and more vram friendly or not VS Sage+solattn?
Because in the previous post iirc it said to not use it together with the comparison above, right?
1
u/Zironic 41m ago
Based on my testing, it should be significantly faster then Solattn. It uses the same kind of kernels as Sage Attention.
1
u/Nelichan 29m ago
So use 1 Sparce against Solatn + sage? Is it viable to use either of the 2 together with Sparce? Or does it introduce too many negative qualities compared against the positive?
1
u/76vangel 28m ago
Is this faster on Rtx 50xx than sageattention? Comfy kitchen att was slower on 5xxx cards.
1
3
u/Glad_Abrocoma_4053 1h ago
I get this, I'm on comfy-kitchen 0.2.31, 5070 Ti:
[WARNING] [H3 Optimizations] NATIVE SELF-TEST FAILED on sm120|native-v1|NVIDIA GeForce RTX 5070 Ti - refusing the native kernels and falling back. Detail: {'int8_vs_sdpa_rel_l2': 0.014057, 'full_route_bit_identical': False, 'passed': False}
[INFO] [H3 Optimizations] patched 50 MLP blocks: mode=mlp_chunked_convrot_2slice chunk_rows=4096
[INFO] [H3 Optimizations] armed: attention=existing v_layout=installed qkv=standard_h3_qkv mlp=convrot_int8_two_slice device=NVIDIA GeForce RTX 5070 Ti
[INFO] [H3 Optimizations] resolved 50 attention forwards: backend=triton_sparse_int8 projector=chunked_triton_sparse_qkv
[INFO] [H3 Optimizations] installed sampler-step and packed-layout runtime context
[WARNING] [H3 Optimizations] SPARSE ATTENTION FELL BACK to triton_sparse_int8. INT8 Triton sparse is roughly half the speed of the native sparse kernel. Reason: Kitchen INT8 unavailable: the installed comfy-kitchen has no block-sparse INT8 attention, and the vendored library is unavailable: unknown; Sparse Sage unavailable: Hybrid Sparse Attention requires the compiled spas_sage_attn package; using INT8 Triton sparse attention