Nodes/ComfyUI-ppm/Model Attention Selector
ComfyUI Node

Model Attention Selector

Switch to SageAttention without restarting

By pamparamm·Created 2 years ago·Updated about 19 hours ago· 265
Model Attention Selector
  • model
  • MODEL
attentionoptimized

Want SageAttention on this workflow but plain SDPA on the next, without relaunching ComfyUI each time? That's what this node is for. Model Attention Selector swaps the diffusion model's attention backend - pytorch/SDPA, SageAttention, xformers - as a dropdown on the canvas. The usual way to pick an attention algorithm is a startup flag (--use-sage-attention) and a full restart to compare; this turns it into a per-workflow choice.

Why this is the one that actually matters

Attention is the expensive math at the heart of every denoising step, and there are several drop-in implementations of it. The diffusion model runs that math dozens of times per generation, so this is where the backend choice moves the needle - unlike the CLIP text encoder, which runs attention once and barely registers on your clock. If you're chasing speed, this node is the lever; its sibling CLIPAttentionSelector isn't.

The three you'll meet: SDPA (PyTorch's built-in, labeled "optimized," the reliable default), xformers (older memory-efficient option), and SageAttention (the current speed pick - it quantizes attention for a real wall-clock win, which is why the high-res and video crowd swear by it). All three should produce near-identical images; the payoff is time and VRAM, not quality.

Inputs and outputs

The node's description says it exactly: it "replaces diffusion model's attention with another registered attention function."

  • model (MODEL) in, patched MODEL out.
  • attention (dropdown, default "optimized") - pick your backend. Only backends actually installed in your environment show up.

Wire it right after your checkpoint loader, before your sampler, and the whole sampling run uses the backend you picked.

Install

The node itself has no dependencies, but the backends it lists are separate installs. SDPA comes with PyTorch; SageAttention and xformers you install yourself, and if they're missing they simply won't appear in the dropdown.

  • ComfyUI Manager: search "ComfyUI-ppm", install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/pamparamm/ComfyUI-ppm, then restart.

Real talk on the speedup

SageAttention is genuinely faster, but manage expectations. The gain is biggest at high resolution and on long video runs where attention dominates; on a quick 1024×1024 SDXL image it's there but modest. And "quantized" means the attention math is approximated - outputs are very close but not bit-identical to SDPA. For iteration that's a non-issue; if you're locking a final render and need exact reproducibility across a series, note which backend you used, because switching it mid-series can shift results a hair.

The reason to use the node rather than the launch flag: flexibility and testing. You can run SageAttention on your heavy workflow and flip a fussy one back to SDPA in the same session - handy because some models or custom nodes don't get along with a given backend, and being able to swap instantly turns a "restart and pray" debugging loop into a dropdown change. If a backend produces artifacts or errors on a specific model, flip to "optimized" and you've isolated it.

Gotchas

If the backend you want isn't in the dropdown, it isn't installed - that's an environment fix (install SageAttention/xformers), not a node bug. Expect near-identical, not identical, output when you switch. And the pack-wide rule holds: if the node errors after a ComfyUI-ppm update, delete it and re-add it.

Categoryadvanced/model

Inputs (2)

NameTypeDefaultDescription
modelMODEL
attentionCOMBOoptimized5 options: optimized, sage, pytorch, sub_quad, split

Outputs (1)

NameTypeDescription
MODELMODEL