Patch VAE Attention DN
Pick Your VAE's Attention Backend Without Restarting ComfyUI
- vae
- vae
Your VAE's attention backend is a decision ComfyUI makes once, at startup, and then quietly forgets you'd ever want to change. On some machines that decision is wrong, slow, or both - and the only "official" way to fix it is to edit launch args and restart. If you've ever run the desktop ComfyUI build, you know that's not even an option: the electron app swallows most launch args. Patch VAE Attention DN turns that startup choice into a per-workflow switch. Wire it in, pick pytorch, xformers, or split, and the VAE that comes out the other end uses exactly that attention implementation - no restart, no args.
What it actually does
It's a tiny patch, and the source is small enough that you should read it once. ComfyUI's VAE is built out of AttnBlocks, and every AttnBlock grabs an attention function at construction time via vae_attention(). That dispatcher picks xformers if available, then PyTorch's scaled dot-product attention, then falls back to "split" - the classic slice-based attention that chunks the computation to fit in VRAM. Your startup log (Using split attention in VAE) is literally that function running.
This node walks the VAE's first_stage_model, finds every AttnBlock, and overwrites its optimized_attention with the backend you chose. No new files, no model weights, no API calls. The three options map exactly onto ComfyUI's own functions: pytorch is pytorch_attention (SDPA, with an automatic slice fallback on OOM), xformers is memory-efficient xformers attention, and split is normal_attention - the low-memory slicing path. Same code, just forced.
Why you'd reach for it
The honest use cases, in order of how often people actually hit them:
- AMD/ROCm users stuck on split. This is the big one. On AMD cards ComfyUI frequently falls back to split attention for the VAE, and it's dramatically slower than the SDPA path an NVIDIA card picks. Real thread from a 7900XTX owner: VAE step several times slower than their old 3060, purely because one used pytorch and the other split. Forcing
pytorchhere is a genuinely free speedup. - You just installed (or removed) xformers. The startup check won't re-run until restart. This node sidesteps that.
- A huge decode on low VRAM. If
VAE Decodeis OOMing on a big latent, forcingsplittrades speed for memory headroom without touching the rest of the graph.
The inputs that matter
Only three, and you'll touch two:
vae- fromLoad VAEorLoad Checkpoint (VAE). This is where the "wire the patched VAE into your decoder" part matters: the output is a new reference to the same VAE, so the patch only applies to whatever runs downstream of this node.attention- the enum:pytorch,xformers,split. Start withpytorch; drop tosplitif you need memory.enabled- defaulttrue. Set itfalseto bypass the patch and pass the VAE through untouched. Handy for A/B testing the same workflow.
The single output is the (patched) vae, which feeds straight into VAE Decode.
Installing it
No dependencies - all three backends are already inside ComfyUI's core, so there's nothing to pip install. Through ComfyUI Manager, search "Patch VAE Attention DN" or just the repo name; or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/0xDELUXA/ComfyUI-DN_PatchVAEAttention
Restart ComfyUI and look for it under DN > VAEAttention > Patch VAE Attention DN. The one optional piece: if you want the xformers option to do anything, xformers needs to be installed in your ComfyUI Python environment yourself.
Troubleshooting & gotchas
- Ignore the startup log line. You'll still see
Using split attention in VAEat boot - that's logged before any node runs. The node is working if you getPatchVAEAttentionDN: VAE attention successfully patched to Xshortly after execution. Don't go hunting for an error that isn't there. xformerssilently downgrades. Pick it without a working xformers install and you get a warning plus a fallback to pytorch, not a crash.splitis the slow, frugal option. It's the memory-saving path, not a quality knob. It can change nothing perceptible about your output on most models; it's a memory/speed trade.- It's marked
EXPERIMENTAL, one commit, no release history. For a patch this small that's not scary - but read the 80 lines ofpatch_vae_attention.pybefore you trust it with anything important. The mechanism is sound; the maintenance guarantee is whatever "initial commit" implies.
If your VAE decode is the slow part of your pipeline and you're on AMD, this is the first node I'd try. If you're on NVIDIA and everything's fine, you probably don't need it - but now you know the knob exists.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| vae | VAE | — | |
| attention | COMBO | 3 options: pytorch, xformers, split | |
| enabled | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| vae | VAE | — |