From 1d6b5de64b4adcb7a8a2ce845e9f529a5bd3999c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 25 Jul 2023 17:21:51 +0300 Subject: [PATCH] fall back to vanilla if xformers is not available This is a rebase of #51. --- sgm/modules/diffusionmodules/model.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sgm/modules/diffusionmodules/model.py b/sgm/modules/diffusionmodules/model.py index 4cf9d9214..5cce399f4 100644 --- a/sgm/modules/diffusionmodules/model.py +++ b/sgm/modules/diffusionmodules/model.py @@ -1,5 +1,6 @@ # pytorch_diffusion + derived encoder decoder import logging +import warnings import math from typing import Any, Callable, Optional @@ -291,6 +292,13 @@ def make_attn(in_channels, attn_type="vanilla", attn_kwargs=None): f"as it is too expensive. Please install xformers via e.g. 'pip install xformers==0.0.16'" ) attn_type = "vanilla-xformers" + if attn_type == "vanilla-xformers" and not XFORMERS_IS_AVAILABLE: + warnings.warn( + f"Requested attention type {attn_type!r} but Xformers is not available; " + f"falling back to vanilla attention" + ) + attn_type = "vanilla" + attn_kwargs = None logpy.info(f"making attention of type '{attn_type}' with {in_channels} in_channels") if attn_type == "vanilla": assert attn_kwargs is None