{"record":{"id":"1dc36364362ce722","repo":"invoke-ai/InvokeAI","slug":"wan-image-denoise-expects-initial-latent-dimension","errorCode":null,"errorMessage":"Wan image denoise expects initial latent dimensions {expected_height}x{expected_width}; got {loaded.shape[-2]}x{loaded.shape[-1]}.","messagePattern":"Wan image denoise expects initial latent dimensions (.+?)x(.+?); got (.+?)x(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_denoise.py","lineNumber":553,"sourceCode":"                raise ValueError(\n                    f\"Wan image denoise requires initial latents with batch size 1; got {loaded.shape[0]}.\"\n                )\n            if loaded.ndim == 5 and loaded.shape[2] != 1:\n                raise ValueError(\n                    f\"Wan image denoise requires single-frame initial latents; got {loaded.shape[2]} frames.\"\n                )\n            if loaded.ndim == 4:\n                loaded = loaded.unsqueeze(2)\n            expected_channels = 48 if variant == WanVariantType.TI2V_5B else 16\n            if loaded.shape[1] != expected_channels:\n                raise ValueError(\n                    f\"Wan {variant.value} image denoise expects {expected_channels} channels in initial latents; \"\n                    f\"got {loaded.shape[1]}.\"\n                )\n            expected_height = self.height // spatial_scale\n            expected_width = self.width // spatial_scale\n            if loaded.shape[-2:] != (expected_height, expected_width):\n                raise ValueError(\n                    f\"Wan image denoise expects initial latent dimensions {expected_height}x{expected_width}; \"\n                    f\"got {loaded.shape[-2]}x{loaded.shape[-1]}.\"\n                )\n            init_latents_5d = loaded\n\n        # Determine the latent channel count. Prefer init_latents shape; otherwise\n        # fall back to the variant default. (We avoid loading the transformer just\n        # to read .config.in_channels; the variant gives us the right answer.)\n        latent_channels = (\n            init_latents_5d.shape[1]\n            if init_latents_5d is not None\n            else (48 if variant == WanVariantType.TI2V_5B else 16)\n        )\n\n        noise = make_noise(\n            batch_size=1,\n            latent_channels=latent_channels,\n            height=self.height,","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_denoise.py#L535-L571","documentation":"The Wan image-denoise invocation validates that the provided initial latents tensor matches the latent-space dimensions implied by the requested output width/height. This error means the loaded latents tensor's HxW (last two dims) do not equal height//spatial_scale x width//spatial_scale. It guards against silently diffusing from latents whose spatial geometry mismatches the conditioning/video size.","triggerScenarios":"Passing an ImageToLatents output produced at different pixel dimensions than the WanDenoise node's width/height; using latents from a different VAE scale factor (8x vs 16x VAE) so the latent spatial size differs; resizing the image after encoding but before denoising.","commonSituations":"Mixing Wan 2.1 (8x-VAE) and Wan 2.2 TI2V-5B (16x-VAE) models in one workflow; building img2img workflows where the source image aspect/size differs from the denoise node's width/height fields; editing a workflow and changing width/height without re-encoding the image.","solutions":["Re-encode the source image with Wan Image to Latents using pixel dimensions equal to the WanDenoise node's width/height","Or set the WanDenoise width/height to match the latents: height = latents_H * spatial_scale, width = latents_W * spatial_scale","Verify the VAE scale factor (8 or 16) matches the loaded Wan model; use the matching ideal-dimensions node (multiple=16 vs 32)"],"exampleFix":"// before\nimageToLatents: width=512, height=512\nwanDenoise: width=832, height=480  // mismatch\n// after\nwanDenoise: width=512, height=512  // matches encoded image dims","handlingStrategy":"validation","validationCode":"spatial_scale = getattr(vae.config, 'scale_factor_spatial', None) or 8\nexp_h, exp_w = height // spatial_scale, width // spatial_scale\nif latents.shape[-2:] != (exp_h, exp_w):\n    raise ValueError(f\"latents {latents.shape[-2]}x{latents.shape[-1]} != expected {exp_h}x{exp_w}\")","typeGuard":null,"tryCatchPattern":"try:\n    result = wan_denoise.invoke(context)\nexcept ValueError as e:\n    if 'latent dimensions' in str(e):\n        reencode_image_at(wan_denoise.width, wan_denoise.height)\n    else:\n        raise","preventionTips":["Keep width/height identical across Image to Latents and WanDenoise nodes","Use the matching Wan Ideal Dimensions node for your VAE (8x vs 16x)","Re-encode the image after any dimension change"],"tags":["invokeai","wan","shape-mismatch","latent-dimensions"],"backgroundTag":"latent-shape-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}