diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-12-30 11:49:52 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-30 11:49:52 +0000 |
commit | 908fb4ea71ef1cb8404cce705d749adec7615abc (patch) | |
tree | d6f803154ab3a225722d2d751efa82af1fbbd91a /modules/processing.py | |
parent | c9c105c7dbdca65c0fe62f78cd9c9d41f9a5af1f (diff) | |
parent | bfe418a58d39c69ca2672e7d8a1fd7ad2b34869b (diff) | |
download | stable-diffusion-webui-gfx803-908fb4ea71ef1cb8404cce705d749adec7615abc.tar.gz stable-diffusion-webui-gfx803-908fb4ea71ef1cb8404cce705d749adec7615abc.tar.bz2 stable-diffusion-webui-gfx803-908fb4ea71ef1cb8404cce705d749adec7615abc.zip |
Merge pull request #14390 from wangqyqq/sdxl-inpaint
Supporting for SDXL-Inpaint Model
Diffstat (limited to 'modules/processing.py')
-rw-r--r-- | modules/processing.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/processing.py b/modules/processing.py index 2f11d5f8..7789f9a4 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -113,6 +113,21 @@ def txt2img_image_conditioning(sd_model, x, width, height): return x.new_zeros(x.shape[0], 2*sd_model.noise_augmentor.time_embed.dim, dtype=x.dtype, device=x.device)
else:
+ sd = sd_model.model.state_dict()
+ diffusion_model_input = sd.get('diffusion_model.input_blocks.0.0.weight', None)
+ if diffusion_model_input is not None:
+ if diffusion_model_input.shape[1] == 9:
+ # The "masked-image" in this case will just be all 0.5 since the entire image is masked.
+ image_conditioning = torch.ones(x.shape[0], 3, height, width, device=x.device) * 0.5
+ image_conditioning = images_tensor_to_samples(image_conditioning,
+ approximation_indexes.get(opts.sd_vae_encode_method))
+
+ # Add the fake full 1s mask to the first dimension.
+ image_conditioning = torch.nn.functional.pad(image_conditioning, (0, 0, 0, 0, 1, 0), value=1.0)
+ image_conditioning = image_conditioning.to(x.dtype)
+
+ return image_conditioning
+
# Dummy zero conditioning if we're not using inpainting or unclip models.
# Still takes up a bit of memory, but no encoder call.
# Pretty sure we can just make this a 1x1 image since its not going to be used besides its batch size.
@@ -371,6 +386,12 @@ class StableDiffusionProcessing: if self.sampler.conditioning_key == "crossattn-adm":
return self.unclip_image_conditioning(source_image)
+ sd = self.sampler.model_wrap.inner_model.model.state_dict()
+ diffusion_model_input = sd.get('diffusion_model.input_blocks.0.0.weight', None)
+ if diffusion_model_input is not None:
+ if diffusion_model_input.shape[1] == 9:
+ return self.inpainting_image_conditioning(source_image, latent_image, image_mask=image_mask)
+
# Dummy zero conditioning if we're not using inpainting or depth model.
return latent_image.new_zeros(latent_image.shape[0], 5, 1, 1)
|