{"record":{"id":"71ed91c663660365","repo":"invoke-ai/InvokeAI","slug":"wan-reference-condition-requires-channels-channe","errorCode":null,"errorMessage":"Wan reference condition requires {channels} channels; got {condition.shape[1]}.","messagePattern":"Wan reference condition requires (.+?) channels; got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_denoise.py","lineNumber":108,"sourceCode":"            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)\n    if model_root.is_file():\n        return None\n    candidate = model_root / \"scheduler\"\n    if (candidate / \"scheduler_config.json\").exists():","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_denoise.py#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Regenerate the reference condition using the Wan VAE / conditioning node matching the selected model variant","Confirm the latent-producing node's channel count equals the expected channels for the variant","Rebuild the workflow so conditioning comes from Wan-native nodes rather than cross-model latents","Update the model/workflow if it was authored for a different Wan version"],"exampleFix":"// before\ncondition = sd_vae_latent  # 4 channels\n// after\ncondition = wan_vae_encode(reference_video)  # Wan-correct channel count","handlingStrategy":"validation","validationCode":"expected_channels = 48  # or the value for your Wan variant\nif condition.shape[1] != expected_channels:\n    raise ValueError(f're-encode condition with the matching Wan VAE; got {condition.shape[1]} channels')","typeGuard":"def has_expected_channels(t, channels: int) -> bool:\n    import torch\n    return isinstance(t, torch.Tensor) and t.ndim == 5 and t.shape[1] == channels","tryCatchPattern":"try:\n    result = denoise.invoke(context)\nexcept ValueError as e:\n    if \"channels\" in str(e) and \"Wan reference condition\" in str(e):\n        # regenerate conditioning with the correct Wan VAE for this variant\n        condition = wan_conditioning_node.invoke(context)\n        denoise.ref_condition = condition\n        result = denoise.invoke(context)\n    else:\n        raise","preventionTips":["Only feed latents produced by the same Wan VAE/variant as the transformer","Don't cross-wire SD/FLUX latents into Wan graphs","Re-generate conditions after switching Wan versions/variants","Check latent channel counts when importing shared workflows"],"tags":["wan","tensor-shape","channels"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}