invoke-ai/InvokeAI · error · ValueError
Wan latents-to-video expects a 5D latent tensor [B, C, T, H,
Error message
Wan latents-to-video expects a 5D latent tensor [B, C, T, H, W]; got {tuple(latents.shape)}. What it means
After promoting 4D tensors to 5D, invoke() requires the latent tensor to be rank 5 ([B, C, T, H, W]). Anything else (1D, 2D, 3D, or 6D+) cannot be interpreted as video latents, so a ValueError with the actual shape tuple is raised.
Source
Thrown at invokeai/app/invocations/wan_latents_to_video.py:99
latents: LatentsField = InputField(description=FieldDescriptions.latents, input=Input.Connection)
vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)
fps: int = InputField(
default=16,
ge=1,
le=120,
description="Frames-per-second for the encoded MP4. Wan 2.2 was trained at 16 FPS.",
)
@torch.no_grad()
def invoke(self, context: InvocationContext) -> VideoOutput:
latents = context.tensors.load(self.latents.latents_name)
_validate_video_latent_batch(latents)
if latents.ndim == 4:
# Promote 4D (single-frame) to 5D so this node can also serve as a
# one-frame "video" encode if someone wires it that way.
latents = latents.unsqueeze(2)
if latents.ndim != 5:
raise ValueError(
f"Wan latents-to-video expects a 5D latent tensor [B, C, T, H, W]; got {tuple(latents.shape)}."
)
if any(size == 0 for size in latents.shape[2:]):
raise ValueError("Wan latents-to-video requires non-empty temporal and spatial dimensions.")
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__}.")
if latents.shape[1] != vae_info.model.config.z_dim:
raise ValueError(
f"Latent channel mismatch: these latents have {latents.shape[1]} channels but the "
f"selected VAE expects {vae_info.model.config.z_dim}. A14B models need the 16-channel Wan 2.1 VAE; "
"TI2V-5B needs the 48-channel Wan 2.2 VAE."
)
_, _, t_lat, h_lat, w_lat = latents.shape
spatial_scale = getattr(vae_info.model.config, "scale_factor_spatial", None) or 8View on GitHub (pinned to 0b6a024f2f)
Solutions
- Ensure the input is a Wan denoiser output of rank 5 [B, C, T, H, W].
- If you have single-frame 4D latents [B,C,H,W], the node auto-promotes them — verify no extra squeeze/dim edits occurred upstream.
- Print latents.shape before invoking and reshape correctly (e.g. latents.unsqueeze(0) for a missing batch dim).
Example fix
// before latents = torch.randn(16, 8, 64) # 3D, invalid video = wan_latents_to_video(latents=latents) // after latents = torch.randn(1, 16, 8, 64, 64) # [B, C, T, H, W] video = wan_latents_to_video(latents=latents)
Defensive patterns
Strategy: validation
Validate before calling
if latents.ndim not in (4, 5):
raise ValueError(f"Expected 4D or 5D Wan latents, got shape {tuple(latents.shape)}") Type guard
def is_video_latent_tensor(t) -> bool:
return isinstance(t, torch.Tensor) and t.ndim in (4, 5) Try / catch
try:
video = node.invoke(context)
except ValueError as e:
if "5D latent tensor" in str(e):
latents = fix_rank(latents) # e.g. unsqueeze(0) for missing batch
video = node.invoke(context)
else:
raise Prevention
- Feed only Wan denoiser outputs into the video node.
- Avoid ad-hoc squeeze/reshape between denoiser and video node.
- Log tensor shapes at workflow boundaries.
- Use type-checked graph connections where possible.
When it happens
Trigger: Passing a tensor of ndim other than 4 or 5 into wan_latents_to_video — e.g. a 2D noise tensor, an image-latent [B,C,H,W] mis-shaped into 3D, or a corrupted tensor from an upstream node.
Common situations: Wiring an image latents node (4D) through reshaping that drops dims; feeding raw noise instead of denoiser output; version drift where an upstream node changed its output rank.
Related errors
- Wan reference condition must be a 5D tensor; got shape {tupl
- Wan latents-to-video requires batch size 1; got {latents.sha
- Wan latents-to-video requires non-empty temporal and spatial
- num_frames must satisfy (num_frames - 1) %% 4 == 0 for the W
- num_frames must satisfy (num_frames - 1) %% 4 == 0 for the W
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/699013383a95e378.
Report an issue: GitHub.