invoke-ai/InvokeAI · error · ValueError
Wan latents-to-video requires non-empty temporal and spatial
Error message
Wan latents-to-video requires non-empty temporal and spatial dimensions.
What it means
A 5D latent tensor whose temporal (T) or spatial (H/W) dimensions contain a zero cannot be decoded into a video, so invoke() rejects it early with this ValueError. This guards the VAE against empty video tensors that would produce zero or undefined frames.
Source
Thrown at invokeai/app/invocations/wan_latents_to_video.py:103
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 8
temporal_scale = getattr(vae_info.model.config, "scale_factor_temporal", None) or 4
t_pixel = (t_lat - 1) * temporal_scale + 1
h_pixel, w_pixel = h_lat * spatial_scale, w_lat * spatial_scale
optimize_memory = context.config.get().wan_memory_optimizationView on GitHub (pinned to 0b6a024f2f)
Solutions
- Fix the upstream computation/slicing so T, H, W are all >= 1.
- Validate latents.shape[2:] before invoking and abort the workflow branch early.
- Check that source image/video dimensions are non-zero before latent generation.
Example fix
// before latents = denoise(prompt, num_frames=0) # T == 0 video = wan_latents_to_video(latents=latents) # ValueError // after assert latents.shape[2] > 0 and latents.shape[3] > 0 and latents.shape[4] > 0 video = wan_latents_to_video(latents=latents)
Defensive patterns
Strategy: validation
Validate before calling
if latents.ndim == 5 and any(s == 0 for s in latents.shape[2:]):
raise ValueError(f"Wan video latents have an empty T/H/W dim: {tuple(latents.shape)}") Type guard
def has_nonempty_video_dims(t) -> bool:
return t.ndim == 5 and all(s > 0 for s in t.shape[2:]) Try / catch
try:
video = node.invoke(context)
except ValueError as e:
if "non-empty temporal and spatial" in str(e):
raise WorkflowSkip("video branch produced empty latents")
raise Prevention
- Guard upstream slicing so frame/size computations never hit 0.
- Check source media dimensions before latent generation.
- Skip video branches early when inputs are placeholders.
- Assert all latent dims > 0 before invoke.
When it happens
Trigger: Passing latents where any of shape[2], shape[3], shape[4] is 0 — usually the result of an upstream slicing bug, an empty sequence after frame dropping, or an arithmetic error in latent size computation (e.g. (0 pixels) // downscale).
Common situations: Off-by-one slicing producing T=0; failed upstream resize leaving H or W at 0; conditional pipelines that emit placeholder empty tensors when a branch is skipped.
Related errors
- Wan latents-to-video requires batch size 1; got {latents.sha
- Wan latents-to-video expects a 5D latent tensor [B, C, T, H,
- num_frames must satisfy (num_frames - 1) %% 4 == 0 for the W
- num_frames must satisfy (num_frames - 1) %% 4 == 0 for the W
- last_image (FLF2V) interpolation requires num_frames > 1.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/ed38e4ffd0d3d4af.
Report an issue: GitHub.