{"record":{"id":"2aa311964463edad","repo":"invoke-ai/InvokeAI","slug":"latents-to-blend-must-be-the-same-size","errorCode":null,"errorMessage":"Latents to blend must be the same size.","messagePattern":"Latents to blend must be the same size\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/blend_latents.py","lineNumber":108,"sourceCode":"        if output.dtype != torch.float16:\n            output = torch.add(output, mask_tensor * torch.sub(other_tensor, tensor))\n        else:\n            output = torch.add(output, mask_tensor.half() * torch.sub(other_tensor, tensor))\n        return output\n\n    def invoke(self, context: InvocationContext) -> LatentsOutput:\n        latents_a = context.tensors.load(self.latents_a.latents_name)\n        latents_b = context.tensors.load(self.latents_b.latents_name)\n        if self.mask is None:\n            mask_tensor = torch.zeros(latents_a.shape[-2:])\n        else:\n            mask_tensor = self.prep_mask_tensor(context.images.get_pil(self.mask.image_name))\n            mask_tensor = tv_resize(mask_tensor, latents_a.shape[-2:], T.InterpolationMode.BILINEAR, antialias=False)\n\n        latents_b = self.replace_tensor_from_masked_tensor(latents_b, latents_a, mask_tensor)\n\n        if latents_a.shape != latents_b.shape:\n            raise ValueError(\"Latents to blend must be the same size.\")\n\n        device = TorchDevice.choose_torch_device()\n\n        # blend\n        blended_latents = slerp(self.alpha, latents_a, latents_b, device)\n\n        # https://discuss.huggingface.co/t/memory-usage-by-later-pipeline-stages/23699\n        blended_latents = blended_latents.to(\"cpu\")\n        TorchDevice.empty_cache()\n\n        name = context.tensors.save(tensor=blended_latents)\n        return LatentsOutput.build(latents_name=name, latents=blended_latents)\n","sourceCodeStart":90,"sourceCodeEnd":121,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/blend_latents.py#L90-L121","documentation":"BlendLatents.invoke() raises ValueError when, after mask-based tensor replacement, latents_a and latents_b still have different shapes. Both latent tensors must share identical channel/spatial dimensions to be slerp-blended. Mismatch typically comes from the two inputs being produced at different resolutions or from mask replacement producing different shapes.","triggerScenarios":"Blending latents from denoise nodes configured with different width/height, latents from different VAE encodes, or a mask whose replacement logic yields a different-shaped latents_b; mask resize path only resizes the mask, not latents.","commonSituations":"Workflow editor graphs wiring BlendLatents with two denoise nodes at different resolutions; using latents from an img2img pass alongside latents from a txt2img pass at other dimensions; prompt/regional blending setups where one region changed size.","solutions":["Make both latent sources use identical width/height (and the same scheduler/VAE scaling) before blending.","Insert resize latents nodes on one branch so both latents match in shape.","Verify the mask replacement step: ensure replace_tensor_from_masked_tensor receives tensors of the same shape.","Log latents_a.shape and latents_b.shape just before the blend to find which branch differs."],"exampleFix":"// before\nblend = BlendLatents(latents_a=big_latents, latents_b=small_latents, mask=mask, alpha=0.5)\n\n// after\nresized = ResizeLatents(latents=small_latents, width=W, height=H)\nblend = BlendLatents(latents_a=big_latents, latents_b=resized.latents, mask=mask, alpha=0.5)","handlingStrategy":"validation","validationCode":"assert latents_a.shape == latents_b.shape, (\n    f\"latents shape mismatch: {latents_a.shape} vs {latents_b.shape}; \"\n    \"resize latents to the same width/height before blending\"\n)","typeGuard":null,"tryCatchPattern":"try:\n    blended = blend_latents.invoke(context)\nexcept ValueError as e:\n    if \"same size\" in str(e):\n        logger.error(\"latent shapes differ; align denoise resolutions before blending\")","preventionTips":["Keep all latent-producing branches at identical width/height","Insert resize-latents nodes where branches diverge in resolution","Log tensor shapes at blend inputs during workflow debugging"],"tags":["tensor-shape-mismatch","latents","stable-diffusion"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}