Attention Backends
Every native diffusion family routes its attention computation through one shared dispatcher. Instead of hard-coding a single attention implementation, PotionUI probes what your hardware and Python environment actually support, then picks the fastest option automatically. Faster attention kernels reduce generation time without changing the sampler, schedule, or any other setting — the speedup is "free" as long as the kernel is available and the call shape qualifies (no attention mask, fp16/bf16 activations).
Five backends are eligible for automatic selection, in priority order from fastest to the universal
fallback: sage3 > sage2 > sage > flash > sdpa. sdpa (PyTorch's built-in
scaled_dot_product_attention) is always available and is the numerical reference every other
backend is checked against — a masked or fp32 call transparently falls back to it regardless of
which backend is selected, so correctness never depends on which kernel ran. A causal call whose
query and key lengths differ takes the same fallback, because sdpa and the accelerated kernels
disagree on how the triangle is aligned there. The fallback happens inside the dispatcher, never in
the calling model, and the log notes each distinct (backend, reason) pair once. A sixth backend,
sparge, exists but is never chosen automatically; it must be pinned explicitly (see below).
Grouped-query attention (fewer key/value heads than query heads) goes through the same single call:
sdpa takes the grouped heads as they are, and every other backend gets them expanded to the query
head count first.
Backend requirements, high to low priority:
sage3(SageAttention3) needs an exact-match Blackwell compute capability —(10,0)(datacenter B100/B200),(12,0)(consumer RTX 50-series), or(12,1)(Blackwell Ultra) — plus CUDA runtime >= 12.8 and Python >= 3.13. It uses hardware FP4 tensor cores unique to those dies, so it will not run on Ampere/Ada/Hopper or older Blackwell-adjacent cards, and a Python interpreter below 3.13 is treated as unsupported rather than silently degrading.sage2needs an SM 8.0+ (Ampere or newer) GPU and thesageattentionpackage installed.sage(the original SageAttention) has a lower hardware floor than sage2/sage3.flashneeds FlashAttention installed and a supported GPU.sdpaalways works — CPU or GPU, any hardware.
If none of the accelerated kernels are installed or supported, generation silently runs on sdpa.
When to use it#
Leave the backend on auto-select for normal use — PotionUI already picks the fastest kernel your
machine supports, and every candidate is numerically near-lossless (masked/fp32 calls fall back to
sdpa automatically, so switching backends should not change output quality in the common case).
Pin a specific backend only when you need to: force sdpa to rule out an attention-kernel-specific
bug while debugging, benchmark backends against each other, or opt into sparge for extra speed on
supported hardware after checking its outputs.
How to enable it#
No action is needed for automatic selection — this is on by default. To pin a backend explicitly,
use Admin -> Backends -> your native backend -> Optimizations -> Attention backend (the
native_attention_backend setting in that backend's configuration, default auto). It accepts
sdpa, sage, sage2, sage3, flash and sparge, including sparge, which auto-selection
never picks on its own. On a remote native backend it is a plain select, and the worker receives the
pin with every job. The pin takes effect on the next generation, with no restart.
The old NATIVE_ATTENTION environment variable, which used to override the pin, is no longer read;
the per-backend pin is the only way to choose an attention backend.
Using sparge (SpargeAttention)
sparge is training-free sparse attention: a two-stage online filter predicts and skips
low-contribution attention blocks. Unlike the other backends, it is approximate rather than
numerically near-lossless — output quality depends on content and on its topk sparsity setting
(defaults to 0.5, the upstream tune-free default). Because of that, it is only ever used when you
explicitly request it (an admin pin set to sparge) — auto-selection will never choose
it for you, no matter how fast or well-supported it is on your hardware. It additionally requires a
sequence length >= 128 and a head dimension of 64 or 128, and only compiles for Ampere/Ada/Hopper
(compute capability major 8 or 9) — it does not currently support Blackwell. Calls outside those
bounds fall back to sdpa.
Tradeoffs and limitations#
- Backend choice does not change how you configure a generation — it only affects speed and, for
sparge, a real quality/speed tradeoff you opt into knowingly. sage3andspargeboth have narrow hardware/software gates; most setups will land onsage2,sage,flash, or the universalsdpafallback.sageneeded a numerical workaround for one architecture: its kernel can overflow fp16 internally on very large activations at large joint-sequence attention shapes, producing NaNs. PotionUI's dispatcher pre-scales the value tensor down by 256 before the call and scales the output back up afterward (mathematically exact, no extra GPU sync), with a finalnan_to_numas a zero-cost safety net — so this is handled for you and does not require any setting. The pre-scale engages only when the largest value magnitude exceeds 1024: applying it unconditionally pushed small values toward fp16's subnormal range and left a film-grain pattern across LTX 2.3 generations. From 32768 rows up the dispatcher checks that magnitude with one host sync instead, because the two full-size copies the sync-free form needs cost gigabytes at that size.sparge's quality varies by content; benchmark and inspect outputs on your own workloads before relying on it for production generations.