Stability-AI/generative-models · error
We do not support vanilla attention anymore, as it is too ex
Error message
We do not support vanilla attention anymore, as it is too expensive. Sorry.
What it means
When attn_mode is 'softmax' but PyTorch SDP (SDP_IS_AVAILABLE False, torch < 2.0) is unavailable, the code warns that vanilla (naive) attention is no longer supported because it is too expensive, and then asserts False — terminating with AssertionError if xformers is also missing (the assert's message directs to installing xformers).
Source
Thrown at sgm/modules/attention.py:486
context_dim=None,
gated_ff=True,
checkpoint=True,
disable_self_attn=False,
attn_mode="softmax",
sdp_backend=None,
):
super().__init__()
assert attn_mode in self.ATTENTION_MODES
if attn_mode != "softmax" and not XFORMERS_IS_AVAILABLE:
logpy.warn(
f"Attention mode '{attn_mode}' is not available. Falling "
f"back to native attention. This is not a problem in "
f"Pytorch >= 2.0. FYI, you are running with PyTorch "
f"version {torch.__version__}."
)
attn_mode = "softmax"
elif attn_mode == "softmax" and not SDP_IS_AVAILABLE:
logpy.warn(
"We do not support vanilla attention anymore, as it is too "
"expensive. Sorry."
)
if not XFORMERS_IS_AVAILABLE:
assert (
False
), "Please install xformers via e.g. 'pip install xformers==0.0.16'"
else:
logpy.info("Falling back to xformers efficient attention.")
attn_mode = "softmax-xformers"
attn_cls = self.ATTENTION_MODES[attn_mode]
if version.parse(torch.__version__) >= version.parse("2.0.0"):
assert sdp_backend is None or isinstance(sdp_backend, SDPBackend)
else:
assert sdp_backend is None
self.disable_self_attn = disable_self_attn
self.attn1 = attn_cls(
query_dim=dim,View on GitHub (pinned to e8cd657656)
Solutions
- Upgrade PyTorch to >= 2.0 so SDP attention is available
- Install xformers so the assert's fallback (memory-efficient attention) succeeds: pip install xformers
- If neither is possible, patch attention.py to allow a naive-attention implementation (not recommended — very slow/high memory)
Example fix
// before pip list # torch 1.13.0, no xformers -> AssertionError in attention.py // after pip install "torch>=2.0" xformers
Defensive patterns
Strategy: validation
Validate before calling
import torch
sdp = hasattr(torch.nn.functional, "scaled_dot_product_attention")
try:
import xformers.ops
xf = True
except ImportError:
xf = False
assert sdp or xf, "need torch>=2.0 SDP or xformers before building the model" Type guard
def any_attention_backend() -> bool:
import torch
if hasattr(torch.nn.functional, "scaled_dot_product_attention"):
return True
try:
import xformers.ops
return True
except ImportError:
return False Try / catch
try:
model = instantiate_from_config(config)
except AssertionError:
raise RuntimeError("No attention backend: install torch>=2.0 or xformers") Prevention
- Check torch and xformers versions in an env preflight script
- Never run torch 1.x without xformers in this codebase
- Add a startup assertion for attention backend availability
When it happens
Trigger: Running with PyTorch < 2.0 (no SDP) AND xformers not installed, while instantiating attention with the default attn_mode='softmax'.
Common situations: Legacy torch 1.x environments without xformers attempting to run the SD model; stripped-down deployments lacking both backends; CPU-only images where xformers is hard to install.
Related errors
- Attention mode '{attn_mode}' is not available. Falling back
- input has {x.ndim} dims but target_dims is {target_dims}, wh
- Did not find parameters for pattern {pattern_}
- No SDP backend available, likely because you are running in
- no module 'xformers'. Processing without...
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/99cfba35c45548ad.
Report an issue: GitHub.