Nodes/ComfyUI-UtilsCollection/Unified Attention Patcher
ComfyUI Node

Unified Attention Patcher

FlashAttention or SageAttention

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Unified Attention Patcher
  • model
  • model
attention_mode

Some models are slow until you swap their attention kernel. ComfyUI already picks a sensible backend for you most of the time, but when a sampler is eating VRAM or crawling along, UC_UnifiedAttentionPatcher lets you choose the backend from a dropdown - FlashAttention or SageAttention - applied to a cloned model so you can test without wrecking your loaded one. It's experimental, it needs matching packages installed, and when it works it can be dramatically faster.

What it is

A model patcher. You feed in a model, pick an attention_mode, and get back a patched model you hand to a KSampler. Crucially, it operates on a clone, so Core's loaded model is untouched - you can A/B test backends in the same session and the failure mode is "revert to disabled", not "reload everything".

The attention_mode is a dynamic combo with three states:

  • disabled - no patching, pass-through. Always your baseline for comparison.
  • FlashAttention - the classic fused kernel, with an optional allow_compile toggle (faster after a slow first compile run; leave off if compilation causes problems).
  • SageAttention - a newer quantized attention backend that's been the speed winner on several architectures, with sage_mode, allow_compile, and an H3-specific h3_memory_optimizations flag (MiniMax H3 only; needs CUDA and a compatible SageAttention install).

The catch: packages

The tooltip says it plainly: "It needs its matching installed package." FlashAttention requires flash-attn; SageAttention requires sageattention. These are compiled CUDA extensions, not pip-friendly pure Python. If you pick FlashAttention without flash-attn installed, the node errors out - so install the backend you intend to use first, in the same environment ComfyUI runs in.

The H3 flag is worth a separate callout: h3_memory_optimizations reduces peak VRAM during attention for MiniMax H3 video generation only, and it specifically requires CUDA plus a compatible SageAttention build. If you're not generating H3 video, leave it off - it's ignored elsewhere anyway.

The input and output

  • model - the loaded model you want to patch.
  • attention_mode - the backend dropdown (with its sub-options when enabled).
  • Output: model - the patched clone, straight into a KSampler.

Installing it

Part of ComfyUI-UtilsCollection:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart ComfyUI (or use Manager, search "ComfyUI-UtilsCollection"). The pack itself only needs opencv-python and typing-extensions; the attention backends are the extra, per-backend dependency you opt into.

Common issues

The classic mistake is expecting a speedup with nothing installed. Check you actually have flash-attn / sageattention before flipping the dropdown - errors here look like import failures, and they happen at queue time, not at node add. If compilation (allow_compile) hangs or makes things slower on your card, turn it off; the tooltip explicitly blesses that. And because this is flagged experimental in a fast-moving pack, test against the disabled baseline before you trust any gains - some of these backend wins are architecture-specific, and "faster on a 4090" doesn't always transfer to your GPU.

Categoryadvanced/model/patches

Inputs (2)

NameTypeDefaultDescription
modelMODEL
attention_modeCOMBOChoose an attention backend. It needs its matching installed package.

Outputs (1)

NameTypeDescription
modelMODEL