{"record":{"id":"6b871ba5a05d8973","repo":"invoke-ai/InvokeAI","slug":"incompatible-noise-and-latents-shapes-laten","errorCode":null,"errorMessage":"Incompatible 'noise' and 'latents' shapes: ${latents.shape=} ${noise.shape=}","messagePattern":"Incompatible 'noise' and 'latents' shapes: (.+?) (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/denoise_latents.py","lineNumber":848,"sourceCode":"        - Text-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.\n        - Image-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.\n\n        NOTE(ryand): I wrote this docstring, but I am not the original author of this code. There may be other workflows\n        I haven't considered.\n        \"\"\"\n        noise = None\n        if noise_field is not None:\n            noise = context.tensors.load(noise_field.latents_name)\n\n        if latents_field is not None:\n            latents = context.tensors.load(latents_field.latents_name)\n        elif noise is not None:\n            latents = torch.zeros_like(noise)\n        else:\n            raise ValueError(\"'latents' or 'noise' must be provided!\")\n\n        if noise is not None and noise.shape[1:] != latents.shape[1:]:\n            raise ValueError(f\"Incompatible 'noise' and 'latents' shapes: {latents.shape=} {noise.shape=}\")\n\n        # The seed comes from (in order of priority): the noise field, the latents field, or 0.\n        seed = 0\n        if noise_field is not None and noise_field.seed is not None:\n            seed = noise_field.seed\n        elif latents_field is not None and latents_field.seed is not None:\n            seed = latents_field.seed\n        else:\n            seed = 0\n\n        return seed, noise, latents\n\n    def invoke(self, context: InvocationContext) -> LatentsOutput:\n        if os.environ.get(\"USE_MODULAR_DENOISE\", False):\n            return self._new_invoke(context)\n        else:\n            return self._old_invoke(context)\n","sourceCodeStart":830,"sourceCodeEnd":866,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/denoise_latents.py#L830-L866","documentation":"After resolving latents, the function checks that `noise` and `latents` have matching trailing dimensions (channel/height/width). A mismatch means the noise schedule and the initial sample describe different latent sizes, which would break the diffusion loop, so it raises with both shapes in the message.","triggerScenarios":"Providing noise generated for one resolution (e.g. 1024x1024 latents) together with latents from an image of a different size (e.g. 768x512 VAE output), or latents from a different model whose channel count differs.","commonSituations":"Img2img where the uploaded image wasn't resized to the declared width/height; mixing latents across SD1 (4ch) and SDXL (4ch different H/W) or other architectures; manually constructed tensors with wrong dimensions.","solutions":["Resize the source image / re-encode latents so their HxW matches the noise dimensions (multiples of the latent scale factor)","Regenerate noise with width/height matching the latents","Confirm both come from the same model family (same latent channel count)"],"exampleFix":"// before\nnoise = NoiseInvocation(width=1024, height=1024)\nlatents = vae_encode(image_resized_to_768x512)\n// after\nnoise = NoiseInvocation(width=1024, height=1024)\nlatents = vae_encode(image_resized_to_1024x1024)  # dims now match noise","handlingStrategy":"validation","validationCode":"if noise is not None and latents is not None and noise.shape[1:] != latents.shape[1:]:\n    raise ValueError(f\"noise {noise.shape} and latents {latents.shape} trailing dims must match\")","typeGuard":"def shapes_compatible(noise, latents) -> bool:\n    return noise is None or latents is None or noise.shape[1:] == latents.shape[1:]","tryCatchPattern":"try:\n    out = invocation.invoke(context)\nexcept ValueError as e:\n    if \"Incompatible 'noise' and 'latents' shapes\" in str(e):\n        latents = resize_latents_to(latents, noise.shape[2:])\n        out = invocation.invoke(context)\n    else:\n        raise","preventionTips":["Resize source images so VAE latents match the noise width/height","Keep latent dims multiples of 8 pixels (latent scale factor)","Never mix latents across models with different latent shapes"],"tags":["python","valueerror","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"}