Attention Selector
One Dropdown That Swaps ComfyUI's Attention Engine
- model
- model
Most of the time your GPU spends in a ComfyUI generation is inside attention - the Q/K/V math where every pixel decides which other pixels to look at. ComfyUI ships with a decent default implementation (PyTorch's SDPA), and for most people that's genuinely fine. But "fine" and "fast" are not the same thing, and which attention implementation wins depends on your GPU, your model, and your resolution. Attention Selector is the answer to that fiddling: one node, one dropdown, and it swaps the attention backend your model runs without recompiling, touching your Python env, or restarting with different flags. If you've ever watched a Wan or Flux workflow crawl and wondered whether SageAttention would help, this is the node that makes trying it a ten-second experiment.
What it actually does
The mechanism is almost anticlimactically simple, which is the point. The node clones your model and writes an optimized_attention_override into the model's transformer options - ComfyUI's own hook for replacing its attention function. The clone is non-destructive (model.clone()), so if you hate the result you just bypass the node and your base model is untouched. For the basic, sub_quad, split, pytorch, and xformers backends it just grabs the attention functions ComfyUI already ships; for sage and flash it wraps those external packages and adapts them to ComfyUI's tensor layouts. One detail worth knowing: if the backend you pick isn't installed, the node silently falls back to pytorch and only prints a line to the console. No error box, no red border - a quiet trap for anyone who assumes a dropdown choice is working.
The inputs that matter
Only two, and one of them is the whole node:
- attention_backend (dropdown):
pytorch(default),xformers,sage,flash,basic,sub_quad,split. - model (MODEL, marked optional - don't leave it empty). No model in, no model out; the node literally returns
None. Wire your checkpoint/UNET here and the outputmodelgoes into your first KSampler.
What to actually pick: on a 30-series card with a modern torch, SDPA is usually fine and xformers is mostly a legacy choice. On RTX 40xx/50xx, sage is where the real speedup lives - it quantizes Q/K to INT8 and accumulates PV in FP8/FP16, which is why it's fast and why it's the current community darling. flash wants a from-source build of flash-attn and a CUDA toolkit, so skip it unless you already know you need it. basic, sub_quad, and split are the emergency low-VRAM options - slower, but they'll squeeze a huge prompt or big latent through a small card.
Installing
ComfyUI Manager → search "comfyui-attention-selector", or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/huagusam/comfyui-attention-selector
Then restart ComfyUI. Here's the pleasant part: this pack has no requirements.txt - zero dependencies of its own, so no dependency hell, which is rare enough in this ecosystem to be worth a paragraph. The optional backends are on you:
pip install xformers # optional, xformers backend
pip install git+https://github.com/thu-ml/SageAttention.git # optional, sage (v2.x, recommended)
pip install flash-attn --no-build-isolation # optional, flash (needs CUDA toolkit)
Common issues
- Silent fallback. Pick "sage" without installing
sageattentionand you're silently on pytorch. Watch the console after first run. - flash-attn is the painful one. It compiles from source and needs CUDA dev tools; on Windows this is a known slog. If it fights you, Sage or SDPA will serve you fine.
- Sage can shave quality. It's quantized attention, so with aggressive speed LoRAs (Lightning-era Wan distills are the classic case) people report artifacts - community threads call it out specifically. If a render looks off, A/B it against pytorch before blaming the model.
- The patch only flows downstream. One node patches only the model branch it's on. Put it right after the checkpoint loader, and if you have separate branches, each needs its own.
It's a small tool, honestly - a nicer wrapper around things a confident power user could do by hand. But it's dependency-free, non-destructive, and it turns "which attention backend should I use" from a research project into a dropdown toggle. Try sage on a 40-series card and you'll probably keep it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| attention_backend | COMBO | pytorch | 7 options: pytorch, xformers, sage, flash, basic, sub_quad, +1 |
| modelopt | MODEL | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |