Stability-AI/generative-models · info
no module 'xformers'. Processing without...
Error message
no module 'xformers'. Processing without...
What it means
The module tries `import xformers` at load time; on ImportError it sets XFORMERS_IS_AVAILABLE=False and logs this warning. It is informational — the library still works — but xformers-accelerated attention modes will be unavailable and non-'softmax' attention modes will silently fall back to 'softmax'.
Source
Thrown at sgm/modules/attention.py:56
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):
return val is not None
def uniq(arr):
return {el: True for el in arr}.keys()
def default(val, d):
if exists(val):
return val
return d() if isfunction(d) else d
View on GitHub (pinned to e8cd657656)
Solutions
- Install xformers: pip install xformers (matching your torch/CUDA version from the xformers release matrix)
- If xformers is not needed, ignore the warning — the code falls back to PyTorch SDP native attention
- Verify import works: python -c "import xformers.ops"
Example fix
// before ModuleNotFoundError: No module named 'xformers' // after pip install xformers # version matching your torch build
Defensive patterns
Strategy: fallback
Validate before calling
try:
import xformers.ops
xformers_ok = True
except ImportError:
xformers_ok = False Type guard
def xformers_available() -> bool:
try:
import xformers.ops
return True
except ImportError:
return False Try / catch
try:
import xformers
XFORMERS_OK = True
except ImportError:
XFORMERS_OK = False
logger.warning("xformers missing; attention will use SDP fallback") Prevention
- Install xformers wheels matching your torch/CUDA combo
- Check XFORMERS_IS_AVAILABLE before requesting xformers attn_mode
- Reinstall xformers after every torch upgrade
When it happens
Trigger: Importing sgm.modules.attention in an environment without the xformers package installed, or with an xformers build incompatible with the installed torch (import fails inside the try).
Common situations: Fresh conda/venv setups; torch upgraded without reinstalling matching xformers wheels; using a non-softmax attn_mode in config and unknowingly getting native attention instead.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- No SDP backend available, likely because you are running in
- Attention mode '{attn_mode}' is not available. Falling back
- We do not support vanilla attention anymore, as it is too ex
- rearranging not available for {len(in_shape)}-dimensional in
- unknown merge strategy {self.merge_strategy}
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/0846a06ba8c8f061.
Report an issue: GitHub.