invoke-ai/InvokeAI · error · ValueError
Wan latents-to-image expects a 4D or 5D latent tensor [B, C,
Error message
Wan latents-to-image expects a 4D or 5D latent tensor [B, C, (T), H, W]; got {tuple(latents.shape)}. What it means
Wan Latents to Image decodes a single image and expects the latents tensor to be 4D [B,C,H,W] or 5D [B,C,T,H,W]. Any other rank (2D, 3D, 6D, etc.) cannot be interpreted, so the node raises with the actual shape. This catches feeding incompatible latents from other pipelines.
Source
Thrown at invokeai/app/invocations/wan_latents_to_image.py:54
"wan_l2i",
title="Latents to Image - Wan 2.2",
tags=["latents", "image", "vae", "l2i", "wan"],
category="latents",
version="1.0.0",
classification=Classification.Prototype,
)
class WanLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard):
"""Decodes Wan latents back to RGB."""
latents: LatentsField = InputField(description=FieldDescriptions.latents, input=Input.Connection)
vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)
@torch.no_grad()
def invoke(self, context: InvocationContext) -> ImageOutput:
latents = context.tensors.load(self.latents.latents_name)
if latents.ndim not in (4, 5):
raise ValueError(
f"Wan latents-to-image expects a 4D or 5D latent tensor [B, C, (T), H, W]; got {tuple(latents.shape)}."
)
if latents.shape[0] != 1:
raise ValueError(f"Wan latents-to-image requires batch size 1; got {latents.shape[0]}.")
# This node decodes exactly one image. Multi-frame video latents would otherwise
# run the full (expensive) multi-frame VAE decode — under a working-memory
# estimate that assumed one frame — and then die in an opaque einops rank error
# at the final rearrange. Checked before the VAE is even loaded.
if latents.ndim == 5 and latents.shape[2] != 1:
raise ValueError(
f"These latents hold {latents.shape[2]} frames of video; this node decodes a single "
"image. Use 'Latents to Video - Wan 2.2' (wan_l2v) for video latents."
)
vae_info = context.models.load(self.vae.vae)
if not isinstance(vae_info.model, AutoencoderKLWan):
raise TypeError(f"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.")View on GitHub (pinned to 0b6a024f2f)
Solutions
- Supply latents from Wan Image to Latents or a Wan denoise node ([B,C,H,W] or [B,C,1,H,W])
- Check the upstream node type — replace non-Wan latents-to-image with the Wan one
- Inspect the tensor with tensor.shape; reshape/pad to rank 4 or 5 before decoding
Example fix
// before latents.shape == (C, H, W) // ndim=3 -> error // after latents = latents.unsqueeze(0) // (1, C, H, W)
Defensive patterns
Strategy: type-guard
Validate before calling
if latents.ndim not in (4, 5):
raise ValueError(f"expected 4D/5D latents, got ndim={latents.ndim} shape={tuple(latents.shape)}") Type guard
def is_valid_wan_latents(t: torch.Tensor) -> bool:
return t.ndim in (4, 5) and t.shape[0] == 1 Try / catch
try:
out = wan_latents_to_image.invoke(context)
except ValueError as e:
if '4D or 5D latent tensor' in str(e):
latents = latents.unsqueeze(0) # reshape as appropriate
else:
raise Prevention
- Source latents only from Wan nodes
- Check tensor.shape before passing between nodes
- Keep batch and channel dims intact through intermediate steps
When it happens
Trigger: Loading latents produced by a non-Wan node or with an unexpected rank into the Wan latents-to-image node; passing preview/noise tensors or manually truncated tensors whose ndim is not 4 or 5.
Common situations: Wiring standard SD latents-to-image tensors into the Wan node; corrupt or hand-edited tensor files; intermediate debug tensors with squeezed batch/channel dims.
Related errors
- Wan image denoise expects initial latent dimensions {expecte
- Krea-2 conditioning mask shape {tuple(mask.shape)} does not
- All Krea-2 conditioning batch items must have the same valid
- denoising_start should be 0 when initial latents are not pro
- Initial latents are required when using an inpaint mask (img
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/87e0c15cdcb6365c.
Report an issue: GitHub.