Stability-AI/generative-models · info
No SDP backend available, likely because you are running in
Error message
No SDP backend available, likely because you are running in pytorch versions < 2.0. In fact, you are using PyTorch {torch.__version__}. You might want to consider upgrading. What it means
attention.py imports torch.nn.functional.sdp_kernel / scaled_dot_product_attention guarded by a version check. If torch.nn does not expose SDP (PyTorch < 2.0), it logs this warning, sets SDP_IS_AVAILABLE=False, and substitutes a nullcontext — meaning attention runs through slower fallback paths.
Source
Thrown at sgm/modules/attention.py:43
SDPBackend.FLASH_ATTENTION: {
"enable_math": False,
"enable_flash": True,
"enable_mem_efficient": False,
},
SDPBackend.EFFICIENT_ATTENTION: {
"enable_math": False,
"enable_flash": False,
"enable_mem_efficient": True,
},
None: {"enable_math": True, "enable_flash": True, "enable_mem_efficient": True},
}
else:
from contextlib import nullcontext
SDP_IS_AVAILABLE = False
sdp_kernel = nullcontext
BACKEND_MAP = {}
logpy.warn(
f"No SDP backend available, likely because you are running in pytorch "
f"versions < 2.0. In fact, you are using PyTorch {torch.__version__}. "
f"You might want to consider upgrading."
)
try:
import xformers
import xformers.ops
XFORMERS_IS_AVAILABLE = True
except:
XFORMERS_IS_AVAILABLE = False
logpy.warn("no module 'xformers'. Processing without...")
# from .diffusionmodules.util import mixed_checkpoint as checkpoint
def exists(val):View on GitHub (pinned to e8cd657656)
Solutions
- Upgrade PyTorch to >= 2.0: pip install --upgrade torch
- If you must stay on 1.x, accept the warning and ensure xformers is installed so attention still runs efficiently
- Pin your environment (requirements.txt) to torch>=2.0 for this codebase
Example fix
// before torch 1.13.1 // after pip install "torch>=2.0.0"
Defensive patterns
Strategy: validation
Validate before calling
import torch
assert tuple(map(int, torch.__version__.split("+")[0].split(".")[:2])) >= (2, 0), \
f"need torch>=2.0, got {torch.__version__}" Type guard
def sdp_available() -> bool:
return hasattr(torch.nn.functional, "scaled_dot_product_attention") Try / catch
try:
import sgm.modules.attention # may warn at import
except Exception:
pass
if not sdp_available():
print("install torch>=2.0 for SDP attention") Prevention
- Pin torch>=2.0 in requirements
- Log torch.__version__ at startup
- Smoke-test imports in CI on the target torch build
When it happens
Trigger: Importing sgm.modules.attention with PyTorch < 2.0 installed (or a build without SDP support); the message is emitted at import time and includes the detected torch.__version__.
Common situations: Old environments pinned to torch 1.13 or earlier; CPU-only or custom torch builds lacking SDP kernels; forgetting to upgrade torch after cloning newer generative-models code.
Related errors
- input has {x.ndim} dims but target_dims is {target_dims}, wh
- Did not find parameters for pattern {pattern_}
- no module 'xformers'. Processing without...
- We do not support vanilla attention anymore, as it is too ex
- rearranging not available for {len(in_shape)}-dimensional in
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/941465fb9839f16a.
Report an issue: GitHub.