invoke-ai/InvokeAI · error · ValueError

Wan reference condition requires {channels} channels; got {c

Error message

Wan reference condition requires {channels} channels; got {condition.shape[1]}.

What it means

The reference condition's channel dimension (shape[1]) must match the channel count the Wan transformer/VAE expects for this variant. A mismatch means the conditioning latent was produced by a different VAE or architecture and would crash the model, so it is validated and rejected.

Source

Thrown at invokeai/app/invocations/wan_denoise.py:108

            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 None
    candidate = model_root / "scheduler"
    if (candidate / "scheduler_config.json").exists():

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Regenerate the reference condition using the Wan VAE / conditioning node matching the selected model variant
  2. Confirm the latent-producing node's channel count equals the expected channels for the variant
  3. Rebuild the workflow so conditioning comes from Wan-native nodes rather than cross-model latents
  4. Update the model/workflow if it was authored for a different Wan version

Example fix

// before
condition = sd_vae_latent  # 4 channels
// after
condition = wan_vae_encode(reference_video)  # Wan-correct channel count
Defensive patterns

Strategy: validation

Validate before calling

expected_channels = 48  # or the value for your Wan variant
if condition.shape[1] != expected_channels:
    raise ValueError(f're-encode condition with the matching Wan VAE; got {condition.shape[1]} channels')

Type guard

def has_expected_channels(t, channels: int) -> bool:
    import torch
    return isinstance(t, torch.Tensor) and t.ndim == 5 and t.shape[1] == channels

Try / catch

try:
    result = denoise.invoke(context)
except ValueError as e:
    if "channels" in str(e) and "Wan reference condition" in str(e):
        # regenerate conditioning with the correct Wan VAE for this variant
        condition = wan_conditioning_node.invoke(context)
        denoise.ref_condition = condition
        result = denoise.invoke(context)
    else:
        raise

Prevention

When it happens

Trigger: Feeding latents from a different model family (SD, FLUX) with e.g. 4 or 16 channels where Wan expects 48/16 for its variant; mixing Wan 2.1 and Wan 2.2 VAEs with different latent channel counts.

Common situations: Reusing an existing latent image node from another model in a Wan graph, switching the Wan variant without regenerating the condition, importing workflows shared online that reference a different model version.

Understand the failure class

Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/71ed91c663660365. Report an issue: GitHub.