invoke-ai/InvokeAI · error · ValueError
Incompatible 'noise' and 'latents' shapes: ${latents.shape=}
Error message
Incompatible 'noise' and 'latents' shapes: ${latents.shape=} ${noise.shape=} What it means
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.
Source
Thrown at invokeai/app/invocations/denoise_latents.py:848
- Text-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.
- Image-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.
NOTE(ryand): I wrote this docstring, but I am not the original author of this code. There may be other workflows
I haven't considered.
"""
noise = None
if noise_field is not None:
noise = context.tensors.load(noise_field.latents_name)
if latents_field is not None:
latents = context.tensors.load(latents_field.latents_name)
elif noise is not None:
latents = torch.zeros_like(noise)
else:
raise ValueError("'latents' or 'noise' must be provided!")
if noise is not None and noise.shape[1:] != latents.shape[1:]:
raise ValueError(f"Incompatible 'noise' and 'latents' shapes: {latents.shape=} {noise.shape=}")
# The seed comes from (in order of priority): the noise field, the latents field, or 0.
seed = 0
if noise_field is not None and noise_field.seed is not None:
seed = noise_field.seed
elif latents_field is not None and latents_field.seed is not None:
seed = latents_field.seed
else:
seed = 0
return seed, noise, latents
def invoke(self, context: InvocationContext) -> LatentsOutput:
if os.environ.get("USE_MODULAR_DENOISE", False):
return self._new_invoke(context)
else:
return self._old_invoke(context)
View on GitHub (pinned to 0b6a024f2f)
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)
Example fix
// before noise = NoiseInvocation(width=1024, height=1024) latents = vae_encode(image_resized_to_768x512) // after noise = NoiseInvocation(width=1024, height=1024) latents = vae_encode(image_resized_to_1024x1024) # dims now match noise
Defensive patterns
Strategy: validation
Validate before calling
if noise is not None and latents is not None and noise.shape[1:] != latents.shape[1:]:
raise ValueError(f"noise {noise.shape} and latents {latents.shape} trailing dims must match") Type guard
def shapes_compatible(noise, latents) -> bool:
return noise is None or latents is None or noise.shape[1:] == latents.shape[1:] Try / catch
try:
out = invocation.invoke(context)
except ValueError as e:
if "Incompatible 'noise' and 'latents' shapes" in str(e):
latents = resize_latents_to(latents, noise.shape[2:])
out = invocation.invoke(context)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- 'latents' or 'noise' must be provided!
- Unexpected T2I-Adapter base model type: '${t2i_adapter_model
- denoising_start must be 0 when no initial latents are provid
- Latents to blend must be the same size.
- Invalid mode selected
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/6b871ba5a05d8973.
Report an issue: GitHub.