From 35e1017e3ea0a3ad9ec28c9b447200a70a65c0ae Mon Sep 17 00:00:00 2001 From: Akiba Date: Fri, 16 Dec 2022 20:43:09 +0800 Subject: fix: xformers --- modules/import_hook.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 modules/import_hook.py (limited to 'modules/import_hook.py') diff --git a/modules/import_hook.py b/modules/import_hook.py new file mode 100644 index 00000000..eb10e4fd --- /dev/null +++ b/modules/import_hook.py @@ -0,0 +1,18 @@ +import builtins +import sys + +old_import = builtins.__import__ +IMPORT_BLACKLIST = [] + + +if "xformers" not in "".join(sys.argv): + IMPORT_BLACKLIST.append("xformers") + + +def import_hook(*args, **kwargs): + if args[0] in IMPORT_BLACKLIST: + raise ImportError("Import of %s is blacklisted" % args[0]) + return old_import(*args, **kwargs) + + +builtins.__import__ = import_hook -- cgit v1.2.3 From 13e0295ab682299e3280eb6ff28be0870f2bc57c Mon Sep 17 00:00:00 2001 From: Akiba Date: Sat, 24 Dec 2022 11:17:21 +0800 Subject: fix: xformers use importlib --- modules/import_hook.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'modules/import_hook.py') diff --git a/modules/import_hook.py b/modules/import_hook.py index eb10e4fd..7403135d 100644 --- a/modules/import_hook.py +++ b/modules/import_hook.py @@ -1,18 +1,5 @@ -import builtins import sys -old_import = builtins.__import__ -IMPORT_BLACKLIST = [] - if "xformers" not in "".join(sys.argv): - IMPORT_BLACKLIST.append("xformers") - - -def import_hook(*args, **kwargs): - if args[0] in IMPORT_BLACKLIST: - raise ImportError("Import of %s is blacklisted" % args[0]) - return old_import(*args, **kwargs) - - -builtins.__import__ = import_hook + sys.modules["xformers"] = None -- cgit v1.2.3 From 0c747d4013f41f6c887a63d256af884aa8872f91 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 24 Dec 2022 07:57:56 +0300 Subject: add a comment for disable xformers hack --- modules/import_hook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/import_hook.py') diff --git a/modules/import_hook.py b/modules/import_hook.py index 7403135d..28c67dfa 100644 --- a/modules/import_hook.py +++ b/modules/import_hook.py @@ -1,5 +1,5 @@ import sys - -if "xformers" not in "".join(sys.argv): +# 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 -- cgit v1.2.3