{"record":{"id":"08cd89c975869fef","repo":"invoke-ai/InvokeAI","slug":"wan-reference-condition-must-be-a-5d-tensor-got-s","errorCode":null,"errorMessage":"Wan reference condition must be a 5D tensor; got shape {tuple(condition.shape)}.","messagePattern":"Wan reference condition must be a 5D tensor; got shape (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_denoise.py","lineNumber":104,"sourceCode":"\ndef _validate_spatial_dimensions(variant: WanVariantType, width: int, height: int) -> None:\n    if variant == WanVariantType.TI2V_5B and (width % 32 or height % 32):\n        raise ValueError(\n            f\"TI2V-5B requires width and height to be multiples of 32 (got {width}x{height}). \"\n            \"Wan 2.2-VAE 16x spatial * transformer patch_size 2 = pixel dims must divide by 32.\"\n        )\n\n\ndef _validate_ref_condition_shape(\n    condition: torch.Tensor,\n    *,\n    channels: int,\n    frames: int,\n    height: int,\n    width: int,\n) -> None:\n    if condition.ndim != 5:\n        raise ValueError(f\"Wan reference condition must be a 5D tensor; got shape {tuple(condition.shape)}.\")\n    if condition.shape[0] != 1:\n        raise ValueError(f\"Wan reference condition requires batch size 1; got {condition.shape[0]}.\")\n    if condition.shape[1] != channels:\n        raise ValueError(f\"Wan reference condition requires {channels} channels; got {condition.shape[1]}.\")\n    if condition.shape[2] != frames:\n        expected = \"a single latent frame\" if frames == 1 else f\"{frames} latent frames\"\n        raise ValueError(f\"Wan reference condition requires {expected}; got {condition.shape[2]}.\")\n    if condition.shape[3:] != (height, width):\n        raise ValueError(\n            f\"Wan reference condition requires {width}x{height} latent spatial dimensions; \"\n            f\"got {condition.shape[4]}x{condition.shape[3]}.\"\n        )\n\n\ndef _scheduler_path_for_transformer(context: InvocationContext, transformer_field: WanTransformerField) -> Path | None:\n    \"\"\"Return the on-disk ``scheduler/`` directory for the main model, or None.\"\"\"\n    config = context.models.get_config(transformer_field.transformer)\n    model_root = context.models.get_absolute_path(config)","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_denoise.py#L86-L122","documentation":"_validate_ref_condition_shape checks that the reference condition tensor is a 5D tensor with layout (batch, channels, frames, height, width). Any tensor of rank other than 5 (e.g. a 4D latent or a 3D image tensor) cannot be a Wan video reference condition and is rejected immediately.","triggerScenarios":"Passing a 4D (B,C,H,W) image latent or a 3D tensor into the reference-condition input of the Wan denoise invocation; wiring an image encoder output directly where a video-shaped latent is expected.","commonSituations":"Connecting an SD/FLUX-style image latent node to Wan's ref condition input, forgetting the extra frame dimension for video latents, custom scripts building condition tensors with wrong rank.","solutions":["Insert unsqueeze(2) (or the appropriate reshape) to add the frames dimension and make the tensor 5D","Use the proper Wan reference-image/conditioning node that outputs a 5D latent","Verify the connected node's output shape is (1, C, T, H, W) before the denoise call","If conditioning a single image, route it through the Wan-specific image conditioning path, not the raw latent"],"exampleFix":"// before\ncondition = image_latent            # shape (1, C, H, W)\n// after\ncondition = image_latent.unsqueeze(2)  # shape (1, C, 1, H, W)","handlingStrategy":"type-guard","validationCode":"if condition.dim() != 5:\n    raise ValueError(f'ref condition must be 5D (B,C,T,H,W); got {tuple(condition.shape)}')","typeGuard":"def is_5d_condition(t) -> bool:\n    import torch\n    return isinstance(t, torch.Tensor) and t.ndim == 5","tryCatchPattern":"try:\n    result = denoise.invoke(context)\nexcept ValueError as e:\n    if \"must be a 5D tensor\" in str(e):\n        condition = condition.unsqueeze(2)  # add frame dim if 4D\n        result = denoise.invoke(context)\n    else:\n        raise","preventionTips":["Always shape ref conditions as (1, C, T, H, W)","Never wire image-only latent nodes directly into Wan video inputs","Log tensor shapes at each graph edge during workflow debugging","Use Wan-specific conditioning nodes that guarantee the 5D layout"],"tags":["wan","tensor-shape","validation"],"backgroundTag":"tensor-rank-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}