{"record":{"id":"6f72cade7c7b3f0d","repo":"invoke-ai/InvokeAI","slug":"inpaintmodelext-should-be-used-only-on-inpaint-mod","errorCode":null,"errorMessage":"InpaintModelExt should be used only on inpaint models!","messagePattern":"InpaintModelExt should be used only on inpaint models!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/stable_diffusion/extensions/inpaint_model.py","lineNumber":61,"sourceCode":"        if mask is not None:\n            self._mask = 1 - mask\n        self._masked_latents = masked_latents\n        self._is_gradient_mask = is_gradient_mask\n\n    @staticmethod\n    def _is_inpaint_model(unet: UNet2DConditionModel):\n        \"\"\"Checks if the provided UNet belongs to a regular model.\n        The `in_channels` of a UNet vary depending on model type:\n        - normal - 4\n        - depth - 5\n        - inpaint - 9\n        \"\"\"\n        return unet.conv_in.in_channels == 9\n\n    @callback(ExtensionCallbackType.PRE_DENOISE_LOOP)\n    def init_tensors(self, ctx: DenoiseContext):\n        if not self._is_inpaint_model(ctx.unet):\n            raise ValueError(\"InpaintModelExt should be used only on inpaint models!\")\n\n        if self._mask is None:\n            self._mask = torch.ones_like(ctx.latents[:1, :1])\n        self._mask = self._mask.to(device=ctx.latents.device, dtype=ctx.latents.dtype)\n\n        if self._masked_latents is None:\n            self._masked_latents = torch.zeros_like(ctx.latents[:1])\n        self._masked_latents = self._masked_latents.to(device=ctx.latents.device, dtype=ctx.latents.dtype)\n\n    # Do last so that other extensions works with normal latents\n    @callback(ExtensionCallbackType.PRE_UNET, order=1000)\n    def append_inpaint_layers(self, ctx: DenoiseContext):\n        batch_size = ctx.unet_kwargs.sample.shape[0]\n        b_mask = torch.cat([self._mask] * batch_size)\n        b_masked_latents = torch.cat([self._masked_latents] * batch_size)\n        ctx.unet_kwargs.sample = torch.cat(\n            [ctx.unet_kwargs.sample, b_mask, b_masked_latents],\n            dim=1,","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/stable_diffusion/extensions/inpaint_model.py#L43-L79","documentation":"InpaintModelExt feeds the 9-channel inpainting UNet, so init_tensors asserts _is_inpaint_model(ctx.unet) (conv_in.in_channels == 9). Attaching it to a normal 4-channel UNet raises ValueError — the inverse check of InpaintExt.","triggerScenarios":"A denoise graph registers InpaintModelExt while the loaded UNet is a standard (non-inpainting) model, so the callback fires with the wrong unet.","commonSituations":"User selecting an inpaint-style workflow against a regular SD checkpoint; model misconfigured/mislabeled as inpainting; custom extension wiring that doesn't check unet type.","solutions":["Use InpaintExt (for normal models) instead of InpaintModelExt when the UNet is not 9-channel.","Load an actual inpainting checkpoint (e.g. SD-inpainting variant) for this workflow.","Re-probe/re-add the model if it was mislabeled in the model manager.","Check unet.conv_in.in_channels == 9 before attaching the extension in custom code."],"exampleFix":"// before\nextensions.append(InpaintModelExt(mask, masked_latents))  # normal unet\n// after\nif unet.conv_in.in_channels == 9:\n    extensions.append(InpaintModelExt(mask, masked_latents))\nelse:\n    extensions.append(InpaintExt(mask, masked_latents))","handlingStrategy":"validation","validationCode":"if unet.conv_in.in_channels != 9:\n    raise ValueError(\"InpaintModelExt requires an inpainting (9-channel) UNet\")","typeGuard":"def is_inpaint_model(unet) -> bool:\n    return unet.conv_in.in_channels == 9","tryCatchPattern":"try:\n    result = pipeline(...)\nexcept ValueError as e:\n    if \"InpaintModelExt should be used only on inpaint models\" in str(e):\n        result = run_with_inpaint_ext(pipeline, mask, masked_latents)\n    else:\n        raise","preventionTips":["Only attach InpaintModelExt to 9-channel inpainting checkpoints","Select the correct workflow for the loaded model type","Verify model variant after re-adding/re-probing checkpoints","Share one helper (conv_in.in_channels check) for extension selection"],"tags":["python","valueerror","inpainting","extension"],"backgroundTag":"wrong-inpaint-extension","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}