From 9db0e9d696397b9b2313111995c68aae4a89d416 Mon Sep 17 00:00:00 2001 From: Ryan Dick Date: Fri, 26 Jul 2024 10:18:10 -0400 Subject: [PATCH] Add better documentation/errors around the possibility that inpainting models may be incorrectly labelled as non-inpainting models. --- invokeai/app/invocations/denoise_latents.py | 4 ++++ invokeai/backend/stable_diffusion/extensions/inpaint.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/invokeai/app/invocations/denoise_latents.py b/invokeai/app/invocations/denoise_latents.py index b7a296a9b4..d42fd8c60e 100644 --- a/invokeai/app/invocations/denoise_latents.py +++ b/invokeai/app/invocations/denoise_latents.py @@ -775,6 +775,10 @@ class DenoiseLatentsInvocation(BaseInvocation): ### inpaint mask, masked_latents, is_gradient_mask = self.prep_inpaint_mask(context, latents) + # NOTE: We used to identify inpainting models by inpecting the shape of the loaded UNet model weights. Now we + # use the ModelVariantType config. During testing, there was a report of a user with models that had an + # incorrect ModelVariantType value. Re-installing the model fixed the issue. If this issue turns out to be + # prevalent, we will have to revisit how we initialize the inpainting extensions. if unet_config.variant == ModelVariantType.Inpaint: ext_manager.add_extension(InpaintModelExt(mask, masked_latents, is_gradient_mask)) elif mask is not None: diff --git a/invokeai/backend/stable_diffusion/extensions/inpaint.py b/invokeai/backend/stable_diffusion/extensions/inpaint.py index 7bdd9238df..437e06df76 100644 --- a/invokeai/backend/stable_diffusion/extensions/inpaint.py +++ b/invokeai/backend/stable_diffusion/extensions/inpaint.py @@ -75,7 +75,11 @@ class InpaintExt(ExtensionBase): @callback(ExtensionCallbackType.PRE_DENOISE_LOOP) def init_tensors(self, ctx: DenoiseContext): if not self._is_normal_model(ctx.unet): - raise ValueError("InpaintExt should be used only on normal models!") + raise ValueError( + "InpaintExt should be used only on normal (non-inpainting) models. This could be caused by an " + "inpainting model that was incorrectly marked as a non-inpainting model. In some cases, this can be " + "fixed by removing and re-adding the model (so that it gets re-probed)." + ) self._mask = self._mask.to(device=ctx.latents.device, dtype=ctx.latents.dtype)