invoke-ai/InvokeAI · error · ValueError
Wan reference condition requires batch size 1; got {conditio
Error message
Wan reference condition requires batch size 1; got {condition.shape[0]}. What it means
The reference condition must have batch size exactly 1 (shape[0] == 1). Batched conditioning is not supported by this Wan path, so _validate_ref_condition_shape rejects any tensor whose first dimension is greater than 1.
Source
Thrown at invokeai/app/invocations/wan_denoise.py:106
if variant == WanVariantType.TI2V_5B and (width % 32 or height % 32):
raise ValueError(
f"TI2V-5B requires width and height to be multiples of 32 (got {width}x{height}). "
"Wan 2.2-VAE 16x spatial * transformer patch_size 2 = pixel dims must divide by 32."
)
def _validate_ref_condition_shape(
condition: torch.Tensor,
*,
channels: int,
frames: int,
height: int,
width: int,
) -> None:
if condition.ndim != 5:
raise ValueError(f"Wan reference condition must be a 5D tensor; got shape {tuple(condition.shape)}.")
if condition.shape[0] != 1:
raise ValueError(f"Wan reference condition requires batch size 1; got {condition.shape[0]}.")
if condition.shape[1] != channels:
raise ValueError(f"Wan reference condition requires {channels} channels; got {condition.shape[1]}.")
if condition.shape[2] != frames:
expected = "a single latent frame" if frames == 1 else f"{frames} latent frames"
raise ValueError(f"Wan reference condition requires {expected}; got {condition.shape[2]}.")
if condition.shape[3:] != (height, width):
raise ValueError(
f"Wan reference condition requires {width}x{height} latent spatial dimensions; "
f"got {condition.shape[4]}x{condition.shape[3]}."
)
def _scheduler_path_for_transformer(context: InvocationContext, transformer_field: WanTransformerField) -> Path | None:
"""Return the on-disk ``scheduler/`` directory for the main model, or None."""
config = context.models.get_config(transformer_field.transformer)
model_root = context.models.get_absolute_path(config)
if model_root.is_file():
return NoneView on GitHub (pinned to 0b6a024f2f)
Solutions
- Set batch size to 1 for the conditioning path (condition = condition[:1] or don't batch it)
- Generate each batch item in a separate invocation instead of batching the ref condition
- If multiple reference images are needed, stack along the frames dimension only if the model supports it, otherwise use one ref per run
- Check the upstream latents/condition node's batch setting
Example fix
// before condition = torch.cat([ref1, ref2], dim=0) # batch 2 // after condition = ref1.unsqueeze(0) # batch 1; run a second invocation for ref2
Defensive patterns
Strategy: validation
Validate before calling
if condition.shape[0] != 1:
condition = condition[:1] # keep only the first batch item before invoking Type guard
def is_batch_1(t) -> bool:
import torch
return isinstance(t, torch.Tensor) and t.ndim == 5 and t.shape[0] == 1 Try / catch
try:
result = denoise.invoke(context)
except ValueError as e:
if "requires batch size 1" in str(e):
denoise.ref_condition = denoise.ref_condition[:1]
result = denoise.invoke(context)
else:
raise Prevention
- Keep global batch size at 1 when using reference conditioning
- Generate batch items via separate invocations, not batched conditions
- Never stack multiple reference images along dim 0
- Assert condition.shape[0] == 1 in custom scripts before invoking
When it happens
Trigger: Passing a condition tensor produced with batch size 2+ (e.g. batch-generating latents, duplicating the image latent along dim 0, or a upstream node configured with batch_size > 1) into the Wan ref-condition input.
Common situations: Users setting a global batch size > 1 for speed and expecting ref conditioning to follow, batched img2img pipelines feeding a single-video ref input, scripting that stacks multiple reference images along the batch axis.
Related errors
- Wan reference condition must be a 5D tensor; got shape {tupl
- Wan reference condition requires {channels} channels; got {c
- Wan reference condition requires {expected}; got {condition.
- Wan reference condition requires {width}x{height} latent spa
- Wan latents-to-image requires batch size 1; got {latents.sha
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/ba4b3c4971247273.
Report an issue: GitHub.