Merge pull request #14186 from akx/torchvision-basicsr-hack

Add import_hook hack to work around basicsr/torchvision incompatibility
This commit is contained in:
AUTOMATIC1111 2023-12-03 19:58:53 +03:00 committed by GitHub
commit 334298d473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,3 +3,14 @@ import sys
# this will break any attempt to import xformers which will prevent stability diffusion repo from trying to use it
if "--xformers" not in "".join(sys.argv):
sys.modules["xformers"] = None
# Hack to fix a changed import in torchvision 0.17+, which otherwise breaks
# basicsr; see https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13985
try:
import torchvision.transforms.functional_tensor # noqa: F401
except ImportError:
try:
import torchvision.transforms.functional as functional
sys.modules["torchvision.transforms.functional_tensor"] = functional
except ImportError:
pass # shrug...