invoke-ai/InvokeAI · error · ValueError
Wan image denoise expects initial latent dimensions {expecte
Error message
Wan image denoise expects initial latent dimensions {expected_height}x{expected_width}; got {loaded.shape[-2]}x{loaded.shape[-1]}. What it means
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.
Source
Thrown at invokeai/app/invocations/wan_denoise.py:553
raise ValueError(
f"Wan image denoise requires initial latents with batch size 1; got {loaded.shape[0]}."
)
if loaded.ndim == 5 and loaded.shape[2] != 1:
raise ValueError(
f"Wan image denoise requires single-frame initial latents; got {loaded.shape[2]} frames."
)
if loaded.ndim == 4:
loaded = loaded.unsqueeze(2)
expected_channels = 48 if variant == WanVariantType.TI2V_5B else 16
if loaded.shape[1] != expected_channels:
raise ValueError(
f"Wan {variant.value} image denoise expects {expected_channels} channels in initial latents; "
f"got {loaded.shape[1]}."
)
expected_height = self.height // spatial_scale
expected_width = self.width // spatial_scale
if loaded.shape[-2:] != (expected_height, expected_width):
raise ValueError(
f"Wan image denoise expects initial latent dimensions {expected_height}x{expected_width}; "
f"got {loaded.shape[-2]}x{loaded.shape[-1]}."
)
init_latents_5d = loaded
# Determine the latent channel count. Prefer init_latents shape; otherwise
# fall back to the variant default. (We avoid loading the transformer just
# to read .config.in_channels; the variant gives us the right answer.)
latent_channels = (
init_latents_5d.shape[1]
if init_latents_5d is not None
else (48 if variant == WanVariantType.TI2V_5B else 16)
)
noise = make_noise(
batch_size=1,
latent_channels=latent_channels,
height=self.height,View on GitHub (pinned to 0b6a024f2f)
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)
Example fix
// before imageToLatents: width=512, height=512 wanDenoise: width=832, height=480 // mismatch // after wanDenoise: width=512, height=512 // matches encoded image dims
Defensive patterns
Strategy: validation
Validate before calling
spatial_scale = getattr(vae.config, 'scale_factor_spatial', None) or 8
exp_h, exp_w = height // spatial_scale, width // spatial_scale
if latents.shape[-2:] != (exp_h, exp_w):
raise ValueError(f"latents {latents.shape[-2]}x{latents.shape[-1]} != expected {exp_h}x{exp_w}") Try / catch
try:
result = wan_denoise.invoke(context)
except ValueError as e:
if 'latent dimensions' in str(e):
reencode_image_at(wan_denoise.width, wan_denoise.height)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Wan latents-to-image expects a 4D or 5D latent tensor [B, C,
- Krea-2 conditioning mask shape {tuple(mask.shape)} does not
- All Krea-2 conditioning batch items must have the same valid
- denoising_start should be 0 when initial latents are not pro
- Initial latents are required when using an inpaint mask (img
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/1dc36364362ce722.
Report an issue: GitHub.