Skip to content

Commit ef520df

Browse files
authored
fall back to vanilla if xformers is not available (Stability-AI#51)
1 parent 2897fdc commit ef520df

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sgm/modules/diffusionmodules/model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# pytorch_diffusion + derived encoder decoder
22
import logging
3+
import warnings
4+
35
import math
46
from typing import Any, Callable, Optional
57

@@ -291,6 +293,13 @@ def make_attn(in_channels, attn_type="vanilla", attn_kwargs=None):
291293
f"as it is too expensive. Please install xformers via e.g. 'pip install xformers==0.0.16'"
292294
)
293295
attn_type = "vanilla-xformers"
296+
if attn_type == "vanilla-xformers" and not XFORMERS_IS_AVAILABLE:
297+
warnings.warn(
298+
f"Requested attention type {attn_type!r} but Xformers is not available; "
299+
f"falling back to vanilla attention"
300+
)
301+
attn_type = "vanilla"
302+
attn_kwargs = None
294303
logger.debug(f"making attention of type '{attn_type}' with {in_channels} in_channels")
295304
if attn_type == "vanilla":
296305
assert attn_kwargs is None

0 commit comments

Comments
 (0)