{"record":{"id":"a0f747748ed3220f","repo":"invoke-ai/InvokeAI","slug":"initial-latents-are-required-when-using-an-inpaint-a0f747","errorCode":null,"errorMessage":"Initial latents are required when using an inpaint mask (img2img inpainting).","messagePattern":"Initial latents are required when using an inpaint mask \\(img2img inpainting\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_denoise.py","lineNumber":600,"sourceCode":"                s_0 = float(sigmas[0])\n                latents = s_0 * noise + (1.0 - s_0) * init_latents_5d\n            else:\n                latents = init_latents_5d\n        else:\n            if self.denoising_start > 1e-5:\n                raise ValueError(\"denoising_start should be 0 when initial latents are not provided.\")\n            latents = noise\n\n        if total_steps <= 0:\n            return latents.squeeze(2)\n\n        # Inpaint extension (4D space — the existing extension is shape-agnostic\n        # but operates on the squeezed-T shape we use for masks).\n        inpaint_mask = self._prep_inpaint_mask(context, latents.squeeze(2))\n        inpaint_extension: RectifiedFlowInpaintExtension | None = None\n        if inpaint_mask is not None:\n            if init_latents_5d is None:\n                raise ValueError(\"Initial latents are required when using an inpaint mask (img2img inpainting).\")\n            inpaint_extension = RectifiedFlowInpaintExtension(\n                init_latents=init_latents_5d.squeeze(2),\n                inpaint_mask=inpaint_mask,\n                noise=noise.squeeze(2),\n            )\n\n        step_callback = self._build_step_callback(context)\n\n        # Resolve experts and the boundary timestep that triggers the MoE swap.\n        #\n        # We deliberately do NOT call ``context.models.load(...)`` for the\n        # transformer experts here — that would put both ~9 GB GGUF handles\n        # in the model cache concurrently. With UMT5-XXL (~10 GB) competing\n        # for the same cache, the LRU policy can drop one of them by the\n        # time the denoise loop swaps in, producing the\n        # \"has already been dropped from the RAM cache\" warning and forcing\n        # a disk reload per swap. The swapper calls ``models.load`` lazily\n        # inside each ``get()`` instead, so handles are always fresh.","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_denoise.py#L582-L618","documentation":"The Wan denoise node supports inpaint masking only in img2img mode: the mask blends the original latents back into regions the mask preserves. If an inpaint mask is connected but there are no initial latents, there is nothing to blend, so the node raises instead of producing meaningless output.","triggerScenarios":"Connecting an inpaint mask input to a WanDenoise node in text-to-video mode (no image/initial latents); using the mask from an img2img inpaint workflow after removing the image input.","commonSituations":"Reusing an inpaint workflow template but deleting the image-to-latents path; users expecting mask-based inpainting from pure noise (not supported by this node).","solutions":["Connect a source image through Wan Image to Latents into the denoise node's initial latents input","Or disconnect the inpaint mask if you intend pure txt2img generation"],"exampleFix":"// before\ninpaintMask -> wanDenoise.inpaint_mask, no init latents\n// after\nimage -> wanImageToLatents -> wanDenoise.init_latents AND inpaintMask -> wanDenoise.inpaint_mask","handlingStrategy":"validation","validationCode":"if inpaint_mask is not None and init_latents is None:\n    raise ValueError(\"inpaint mask requires initial latents (img2img inpainting)\")","typeGuard":null,"tryCatchPattern":"try:\n    result = wan_denoise.invoke(context)\nexcept ValueError as e:\n    if 'inpaint mask' in str(e):\n        connect_image_to_latents(...)  # or remove the mask\n    else:\n        raise","preventionTips":["Only connect inpaint masks when an image path is wired","Disconnect the mask when converting to txt2img","Verify all denoise inputs in the workflow editor before running"],"tags":["invokeai","wan","inpainting","missing-input"],"backgroundTag":"missing-required-input","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}