invoke-ai/InvokeAI · error · ValueError
Wan latents-to-image requires batch size 1; got {latents.sha
Error message
Wan latents-to-image requires batch size 1; got {latents.shape[0]}. What it means
The node decodes exactly one image, so the latents batch dimension must be 1. Batched latents (>1) are rejected explicitly rather than decoding only the first frame silently, which would hide data loss.
Source
Thrown at invokeai/app/invocations/wan_latents_to_image.py:58
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__}.")
spatial_scale = getattr(vae_info.model.config, "scale_factor_spatial", None) or 8
estimated_working_memory = estimate_vae_working_memory_wan(
operation="decode",View on GitHub (pinned to 0b6a024f2f)
Solutions
- Slice off a single batch item: latents[0:1] before decoding
- Run the node once per batch element instead of batching
- If downstream expects images, add a per-item loop or use a batch-capable node
Example fix
// before latents.shape == (4, C, H, W) -> error // after latents = latents[:1] # or latents[i:i+1] per item
Defensive patterns
Strategy: validation
Validate before calling
if latents.shape[0] != 1:
latents = latents[:1] # or loop over batch items Type guard
def is_single_batch(t: torch.Tensor) -> bool:
return t.shape[0] == 1 Try / catch
try:
out = wan_latents_to_image.invoke(context)
except ValueError as e:
if 'batch size 1' in str(e):
out = [decode_one(latents[i:i+1]) for i in range(latents.shape[0])]
else:
raise Prevention
- Avoid batching with Wan image decode; iterate instead
- Slice latents[:1] when only one output is needed
- Keep per-item processing loops for batch workflows
When it happens
Trigger: Feeding latents with shape[0] > 1 (e.g., from a batched generation or a manual torch.stack of multiple latent tensors) into Wan Latents to Image.
Common situations: Batch workflows built for txt2img SD pipelines reused for Wan; users stacking multiple encoded images into one tensor.
Related errors
- Source longer side ({long_side}px) is smaller than the Wan p
- Wan latents-to-video requires batch size 1; got {latents.sha
- denoising_start ({self.denoising_start}) must be less than d
- LoRA "{lora_key}" already applied to transformer.
- A saved workflow must be selected before executing call_save
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/4eecd02dfa75f0b2.
Report an issue: GitHub.