aboutsummaryrefslogtreecommitdiffstats
path: root/modules/sd_hijack_unet.py
diff options
context:
space:
mode:
authorpapuSpartan <30642826+papuSpartan@users.noreply.github.com>2022-12-10 08:02:39 +0000
committerGitHub <noreply@github.com>2022-12-10 08:02:39 +0000
commit6387043fd2c3311d66690ff27d7da0e030b29cd8 (patch)
tree075559ce3e52511cdd459da2b4cc33360d6eb258 /modules/sd_hijack_unet.py
parent00ebc26c4e2962a31e067539d89cd695d999539a (diff)
parent1d01404c5615debfca24f7fbe429ddd2f5b11eb9 (diff)
downloadstable-diffusion-webui-gfx803-6387043fd2c3311d66690ff27d7da0e030b29cd8.tar.gz
stable-diffusion-webui-gfx803-6387043fd2c3311d66690ff27d7da0e030b29cd8.tar.bz2
stable-diffusion-webui-gfx803-6387043fd2c3311d66690ff27d7da0e030b29cd8.zip
Merge branch 'AUTOMATIC1111:master' into master
Diffstat (limited to 'modules/sd_hijack_unet.py')
-rw-r--r--modules/sd_hijack_unet.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/sd_hijack_unet.py b/modules/sd_hijack_unet.py
new file mode 100644
index 00000000..1b9d7757
--- /dev/null
+++ b/modules/sd_hijack_unet.py
@@ -0,0 +1,30 @@
+import torch
+
+
+class TorchHijackForUnet:
+ """
+ This is torch, but with cat that resizes tensors to appropriate dimensions if they do not match;
+ this makes it possible to create pictures with dimensions that are muliples of 8 rather than 64
+ """
+
+ def __getattr__(self, item):
+ if item == 'cat':
+ return self.cat
+
+ if hasattr(torch, item):
+ return getattr(torch, item)
+
+ raise AttributeError("'{}' object has no attribute '{}'".format(type(self).__name__, item))
+
+ def cat(self, tensors, *args, **kwargs):
+ if len(tensors) == 2:
+ a, b = tensors
+ if a.shape[-2:] != b.shape[-2:]:
+ a = torch.nn.functional.interpolate(a, b.shape[-2:], mode="nearest")
+
+ tensors = (a, b)
+
+ return torch.cat(tensors, *args, **kwargs)
+
+
+th = TorchHijackForUnet()