Skip to content

Commit 5810cee

Browse files
Suggested changes
Co-Authored-By: Ryan Dick <[email protected]>
1 parent bd8890b commit 5810cee

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

invokeai/app/invocations/denoise_latents.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ def step_callback(state: PipelineIntermediateState) -> None:
775775

776776
### inpaint
777777
mask, masked_latents, is_gradient_mask = self.prep_inpaint_mask(context, latents)
778+
# NOTE: We used to identify inpainting models by inpecting the shape of the loaded UNet model weights. Now we
779+
# use the ModelVariantType config. During testing, there was a report of a user with models that had an
780+
# incorrect ModelVariantType value. Re-installing the model fixed the issue. If this issue turns out to be
781+
# prevalent, we will have to revisit how we initialize the inpainting extensions.
778782
if unet_config.variant == ModelVariantType.Inpaint:
779783
ext_manager.add_extension(InpaintModelExt(mask, masked_latents, is_gradient_mask))
780784
elif mask is not None:
@@ -830,6 +834,8 @@ def _old_invoke(self, context: InvocationContext) -> LatentsOutput:
830834
seed, noise, latents = self.prepare_noise_and_latents(context, self.noise, self.latents)
831835

832836
mask, masked_latents, gradient_mask = self.prep_inpaint_mask(context, latents)
837+
# At this point, the mask ranges from 0 (leave unchanged) to 1 (inpaint).
838+
# We invert the mask here for compatibility with the old backend implementation.
833839
if mask is not None:
834840
mask = 1 - mask
835841

invokeai/backend/stable_diffusion/extensions/inpaint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def _apply_mask(self, ctx: DenoiseContext, latents: torch.Tensor, t: torch.Tenso
7575
@callback(ExtensionCallbackType.PRE_DENOISE_LOOP)
7676
def init_tensors(self, ctx: DenoiseContext):
7777
if not self._is_normal_model(ctx.unet):
78-
raise ValueError("InpaintExt should be used only on normal models!")
78+
raise ValueError(
79+
"InpaintExt should be used only on normal (non-inpainting) models. This could be caused by an "
80+
"inpainting model that was incorrectly marked as a non-inpainting model. In some cases, this can be "
81+
"fixed by removing and re-adding the model (so that it gets re-probed)."
82+
)
7983

8084
self._mask = self._mask.to(device=ctx.latents.device, dtype=ctx.latents.dtype)
8185

0 commit comments

Comments
 (0)