{"record":{"id":"0d40f810cf8ad7d2","repo":"invoke-ai/InvokeAI","slug":"wan-reference-condition-requires-width-x-height","errorCode":null,"errorMessage":"Wan reference condition requires {width}x{height} latent spatial dimensions; got {condition.shape[4]}x{condition.shape[3]}.","messagePattern":"Wan reference condition requires (.+?)x(.+?) latent spatial dimensions; got (.+?)x(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_denoise.py","lineNumber":113,"sourceCode":"def _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():\n        return candidate\n    return None\n\n\ndef _default_scheduler_for_variant(variant: WanVariantType):","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_denoise.py#L95-L131","documentation":"The spatial dimensions of the reference condition (shape[3]/shape[4] = latent height/width) must equal the latent-space height/width derived from the run's width/height after VAE downsampling. The message reports expected width x height latent dims and the observed ones (note the swapped print order: shape[4]xshape[3]).","triggerScenarios":"Condition latent encoded at a different resolution than the denoise run's width/height (e.g. ref image 512x512 but generation at 832x480), rounding differences between the run's latent size and the encoded condition.","commonSituations":"Changing output resolution in the workflow after encoding the reference condition, cropping/resizing the reference image without re-encoding, sharing workflows whose ref image size differs from the target size.","solutions":["Resize/crop the reference image/video so that (dims / vae_spatial_scale) equals the run's latent height/width, then re-encode the condition","Set the denoise invocation's width/height to match the existing condition's latent spatial size (latent_w*32-style back-calculation per variant)","Re-run the conditioning node after any resolution change","Check the swapped print order (got shape[4]xshape[3]) when comparing reported vs expected values"],"exampleFix":"// before\nref = encode(image_512x512)   # latent 32x32\nrun.width, run.height = 832, 480  # latent 52x30\n// after\nref = encode(resize(image, 832, 480))  # latent dims now match the run","handlingStrategy":"validation","validationCode":"latent_scale = 16  # Wan 2.2 VAE spatial scale (adjust per variant)\nexpected_hw = (height // latent_scale, width // latent_scale)\nif tuple(condition.shape[3:]) != expected_hw:\n    ref_input = resize(ref_input, width, height)  # re-encode at matching size","typeGuard":"def spatial_dims_match(t, latent_h: int, latent_w: int) -> bool:\n    import torch\n    return isinstance(t, torch.Tensor) and t.ndim == 5 and t.shape[3:] == (latent_h, latent_w)","tryCatchPattern":"try:\n    result = denoise.invoke(context)\nexcept ValueError as e:\n    if \"latent spatial dimensions\" in str(e):\n        # re-encode the reference at the run's resolution, then retry\n        condition = wan_conditioning_node.invoke(context)\n        denoise.ref_condition = condition\n        result = denoise.invoke(context)\n    else:\n        raise","preventionTips":["Resize the reference image/video to the exact output width/height before encoding","Re-encode conditions after any resolution change in the graph","Derive latent dims as pixel dims / VAE spatial scale and compare before invoking","Note the error prints got shape[4]xshape[3] (width x height) when comparing values"],"tags":["wan","tensor-shape","spatial-dimensions"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}