diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-01-25 16:12:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 16:12:29 +0000 |
commit | 1574e967297586d013e4cfbb6628eae595c9fba2 (patch) | |
tree | 99374009f63cf73cadc713b02db5fbba0701e516 /modules/sd_hijack_utils.py | |
parent | 1982ef68900fe3c5eee704dfbda5416c1bb5470b (diff) | |
parent | e3b53fd295aca784253dfc8668ec87b537a72f43 (diff) | |
download | stable-diffusion-webui-gfx803-1574e967297586d013e4cfbb6628eae595c9fba2.tar.gz stable-diffusion-webui-gfx803-1574e967297586d013e4cfbb6628eae595c9fba2.tar.bz2 stable-diffusion-webui-gfx803-1574e967297586d013e4cfbb6628eae595c9fba2.zip |
Merge pull request #6510 from brkirch/unet16-upcast-precision
Add upcast options, full precision sampling from float16 UNet and upcasting attention for inference using SD 2.1 models without --no-half
Diffstat (limited to 'modules/sd_hijack_utils.py')
-rw-r--r-- | modules/sd_hijack_utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/sd_hijack_utils.py b/modules/sd_hijack_utils.py new file mode 100644 index 00000000..f81b169a --- /dev/null +++ b/modules/sd_hijack_utils.py @@ -0,0 +1,28 @@ +import importlib
+
+class CondFunc:
+ def __new__(cls, orig_func, sub_func, cond_func):
+ self = super(CondFunc, cls).__new__(cls)
+ if isinstance(orig_func, str):
+ func_path = orig_func.split('.')
+ for i in range(len(func_path)-2, -1, -1):
+ try:
+ resolved_obj = importlib.import_module('.'.join(func_path[:i]))
+ break
+ except ImportError:
+ pass
+ for attr_name in func_path[i:-1]:
+ resolved_obj = getattr(resolved_obj, attr_name)
+ orig_func = getattr(resolved_obj, func_path[-1])
+ setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
+ self.__init__(orig_func, sub_func, cond_func)
+ return lambda *args, **kwargs: self(*args, **kwargs) + def __init__(self, orig_func, sub_func, cond_func): + self.__orig_func = orig_func + self.__sub_func = sub_func + self.__cond_func = cond_func + def __call__(self, *args, **kwargs): + if not self.__cond_func or self.__cond_func(self.__orig_func, *args, **kwargs): + return self.__sub_func(self.__orig_func, *args, **kwargs) + else: + return self.__orig_func(*args, **kwargs) |