aboutsummaryrefslogtreecommitdiff
path: root/modules/sd_hijack.py
diff options
context:
space:
mode:
authorezxzeng <zhixuan.zeng@gmail.com>2023-11-07 15:25:27 -0500
committerGitHub <noreply@github.com>2023-11-07 15:25:27 -0500
commitf9c14a8c8c8b682c2a7f7a11306b26e2a28ebeec (patch)
tree1c7f6abc11bd2aacd2a0d16a0b7db1963c9b26cd /modules/sd_hijack.py
parent759515316e8ec536f34fad616e8c6a33674a164b (diff)
parent5e80d9ee99c5899e5e2b130408ffb65a0585a62a (diff)
Merge branch 'dev' into ui_mobile_optimizations
Diffstat (limited to 'modules/sd_hijack.py')
-rw-r--r--modules/sd_hijack.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py
index bc5fbcd3..0157e19f 100644
--- a/modules/sd_hijack.py
+++ b/modules/sd_hijack.py
@@ -184,6 +184,20 @@ class StableDiffusionModelHijack:
errors.display(e, "applying cross attention optimization")
undo_optimizations()
+ def convert_sdxl_to_ssd(self, m):
+ """Converts an SDXL model to a Segmind Stable Diffusion model (see https://huggingface.co/segmind/SSD-1B)"""
+
+ delattr(m.model.diffusion_model.middle_block, '1')
+ delattr(m.model.diffusion_model.middle_block, '2')
+ for i in ['9', '8', '7', '6', '5', '4']:
+ delattr(m.model.diffusion_model.input_blocks[7][1].transformer_blocks, i)
+ delattr(m.model.diffusion_model.input_blocks[8][1].transformer_blocks, i)
+ delattr(m.model.diffusion_model.output_blocks[0][1].transformer_blocks, i)
+ delattr(m.model.diffusion_model.output_blocks[1][1].transformer_blocks, i)
+ delattr(m.model.diffusion_model.output_blocks[4][1].transformer_blocks, '1')
+ delattr(m.model.diffusion_model.output_blocks[5][1].transformer_blocks, '1')
+ devices.torch_gc()
+
def hijack(self, m):
conditioner = getattr(m, 'conditioner', None)
if conditioner:
@@ -242,8 +256,12 @@ class StableDiffusionModelHijack:
self.layers = flatten(m)
+ import modules.models.diffusion.ddpm_edit
+
if isinstance(m, ldm.models.diffusion.ddpm.LatentDiffusion):
sd_unet.original_forward = ldm_original_forward
+ elif isinstance(m, modules.models.diffusion.ddpm_edit.LatentDiffusion):
+ sd_unet.original_forward = ldm_original_forward
elif isinstance(m, sgm.models.diffusion.DiffusionEngine):
sd_unet.original_forward = sgm_original_forward
else: