{"record":{"id":"c7a20cdc66ddd935","repo":"invoke-ai/InvokeAI","slug":"reference-image-num-frames-self-ref-image-num-fr","errorCode":null,"errorMessage":"Reference-image num_frames ({self.ref_image.num_frames}) must match denoise num_frames ({self.num_frames}). Re-run the Reference Image - Wan 2.2 node with num_frames={self.num_frames}.","messagePattern":"Reference-image num_frames \\((.+?)\\) must match denoise num_frames \\((.+?)\\)\\. Re-run the Reference Image - Wan 2\\.2 node with num_frames=(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_video_denoise.py","lineNumber":222,"sourceCode":"        ref_condition: torch.Tensor | None = None\n        if self.ref_image is not None:\n            if variant not in (WanVariantType.I2V_A14B, WanVariantType.TI2V_5B):\n                raise ValueError(\n                    f\"Reference-image conditioning is only supported by Wan 2.2 I2V variants \"\n                    f\"(I2V-A14B or TI2V-5B). The selected transformer is {variant.value!r}. \"\n                    \"Remove the Reference Image input or load an I2V variant.\"\n                )\n            if self.ref_image.width != self.width or self.ref_image.height != self.height:\n                raise ValueError(\n                    f\"Reference-image dimensions ({self.ref_image.width}x{self.ref_image.height}) must \"\n                    f\"match denoise dimensions ({self.width}x{self.height}).\"\n                )\n            # A14B encodes one condition tensor per pixel-frame count, so the\n            # encoder's num_frames must match. TI2V-5B's condition is always\n            # single-frame regardless of the output length, so the field's\n            # num_frames is informational only and we skip this check.\n            if variant == WanVariantType.I2V_A14B and self.ref_image.num_frames != self.num_frames:\n                raise ValueError(\n                    f\"Reference-image num_frames ({self.ref_image.num_frames}) must match denoise \"\n                    f\"num_frames ({self.num_frames}). Re-run the Reference Image - Wan 2.2 node with \"\n                    f\"num_frames={self.num_frames}.\"\n                )\n            ref_condition = context.tensors.load(self.ref_image.condition_tensor_name).to(\n                device=device, dtype=inference_dtype\n            )\n            _validate_ref_condition_shape(\n                ref_condition,\n                channels=48 if variant == WanVariantType.TI2V_5B else 20,\n                frames=1 if variant == WanVariantType.TI2V_5B else num_latent_frames_for(self.num_frames),\n                height=self.height // spatial_scale,\n                width=self.width // spatial_scale,\n            )\n\n        scheduler.set_timesteps(num_inference_steps=self.steps, device=device)\n        timesteps = scheduler.timesteps\n        total_steps = len(timesteps)","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_video_denoise.py#L204-L240","documentation":"For I2V-A14B, the reference condition tensor is encoded per pixel-frame count, so the encoder's num_frames must equal the denoise node's num_frames or the time-axis shapes won't match. InvokeAI raises ValueError telling the user exactly which num_frames to re-encode with. TI2V-5B is exempt because its condition is always single-frame.","triggerScenarios":"Running the Reference Image node with num_frames=81 but the Wan Video Denoise (I2V-A14B variant) with num_frames=61, then wiring the condition into denoise.","commonSituations":"Iterating on clip length in the denoise node without re-running the encoder; different num_frames defaults in the two nodes when assembling a workflow.","solutions":["Re-run the Reference Image - Wan 2.2 node with num_frames equal to the denoise node's num_frames (the error message states the exact value).","Keep both nodes' num_frames linked to the same source (e.g. a single integer primitive feeding both).","Use TI2V-5B if you need output length to vary independently of the encoded reference."],"exampleFix":"// before\nref_encoder.num_frames = 81\ndenoise.num_frames = 61\n// after\nref_encoder.num_frames = 61\ndenoise.num_frames = 61","handlingStrategy":"validation","validationCode":"if variant == WanVariantType.I2V_A14B and ref_image.num_frames != num_frames:\n    ref_condition = re_encode_reference(num_frames=num_frames)  # re-run encoder with denoise's num_frames","typeGuard":null,"tryCatchPattern":"try:\n    tensor = denoise._run_diffusion(context)\nexcept ValueError as e:\n    if \"must match denoise\" in str(e) and \"num_frames\" in str(e):\n        ref_condition = re_encode_reference(num_frames=num_frames)\n    else:\n        raise","preventionTips":["Feed num_frames from one primitive into both reference encoder and denoise nodes.","Re-encode the reference image after any clip-length change.","On TI2V-5B this check is skipped (single-frame condition), so mismatches only bite A14B."],"tags":["validation","num-frames","reference-image","wan"],"backgroundTag":"dimension-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}