invoke-ai/InvokeAI · error · ValueError
Latent channel mismatch: these latents have {latents.shape[1
Error message
Latent channel mismatch: these latents have {latents.shape[1]} channels but the selected VAE expects {vae.config.z_dim}. A14B models need the 16-channel Wan 2.1 VAE; TI2V-5B needs the 48-channel Wan 2.2 VAE. What it means
This ValueError is thrown by the Wan latents-to-image invocation when the latent tensor's channel count does not match the z_dim configured on the selected Wan VAE. InvokeAI enforces this because Wan 2.1 A14B models use a 16-channel latent space while the Wan 2.2 TI2V-5B model uses a 48-channel latent space, and decoding latents through a mismatched VAE would silently produce garbage.
Source
Thrown at invokeai/app/invocations/wan_latents_to_image.py:98
pixel_frames=1,
)
with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):
context.util.signal_progress("Running Wan VAE decode")
assert isinstance(vae, AutoencoderKLWan)
vae_dtype = next(iter(vae.parameters())).dtype
latents = latents.to(device=get_effective_device(vae), dtype=vae_dtype)
TorchDevice.empty_cache()
with torch.inference_mode():
# Re-add the temporal dim if upstream squeezed it out.
if latents.ndim == 4:
latents = latents.unsqueeze(2)
if latents.shape[1] != vae.config.z_dim:
raise ValueError(
f"Latent channel mismatch: these latents have {latents.shape[1]} channels but the "
f"selected VAE expects {vae.config.z_dim}. A14B models need the 16-channel Wan 2.1 "
"VAE; TI2V-5B needs the 48-channel Wan 2.2 VAE."
)
# Denormalise from denoiser space back to raw VAE space.
latents_mean = torch.tensor(vae.config.latents_mean).view(1, -1, 1, 1, 1).to(latents)
latents_std = torch.tensor(vae.config.latents_std).view(1, -1, 1, 1, 1).to(latents)
latents = latents * latents_std + latents_mean
decoded = vae.decode(latents, return_dict=False)[0]
if decoded.ndim == 5:
decoded = decoded.squeeze(2)
img = decoded.clamp(-1, 1)
img = rearrange(img[0], "c h w -> h w c")
img_pil = Image.fromarray((127.5 * (img + 1.0)).byte().cpu().numpy())View on GitHub (pinned to 0b6a024f2f)
Solutions
- Select the VAE matching the latents' origin: 16-channel Wan 2.1 VAE for A14B latents, 48-channel Wan 2.2 VAE for TI2V-5B latents.
- Check latents.shape[1] before invoking and route to the correct VAE node.
- Regenerate the latents with a denoiser whose latent space matches the chosen VAE.
- Update stale workflow templates that hardcode the wrong VAE model ID.
Example fix
// before
latents = wan21_denoiser_output # 16 channels
vae = load_vae("wan2.2-ti2v-5b-vae") # z_dim = 48
image = wan_latents_to_image(latents=latents, vae=vae) # ValueError
// after
assert latents.shape[1] == 16
vae = load_vae("wan2.1-a14b-vae") # z_dim = 16
image = wan_latents_to_image(latents=latents, vae=vae) Defensive patterns
Strategy: validation
Validate before calling
def validate_latent_channels(latents, vae):
z_dim = vae.config.z_dim
if latents.shape[1] != z_dim:
raise ValueError(
f"Latents have {latents.shape[1]} channels; VAE expects {z_dim}. "
"A14B -> 16ch Wan 2.1 VAE; TI2V-5B -> 48ch Wan 2.2 VAE."
) Type guard
def is_wan_latent_compatible(latents, vae) -> bool:
return latents.ndim in (4, 5) and latents.shape[1] == vae.config.z_dim Try / catch
try:
result = node.invoke(context)
except ValueError as e:
if "Latent channel mismatch" in str(e):
vae = pick_vae_for_channels(latents.shape[1])
result = replace(node, vae=vae).invoke(context)
else:
raise Prevention
- Pin one VAE per Wan model lineage in your workflow (2.1 A14B vs 2.2 5B).
- Assert latents.shape[1] == vae.config.z_dim before every invoke.
- Never reuse VAE nodes across Wan 2.1/2.2 workflows.
- Name model IDs with the variant to avoid mis-selection.
When it happens
Trigger: Calling invoke() on wan_latents_to_image with a latents tensor whose shape[1] differs from vae.config.z_dim after the 4D->5D promotion (unsqueeze of the temporal dim). Typically latents produced by a Wan 2.1 denoiser (16ch) paired with the 48-channel Wan 2.2 VAE, or vice versa.
Common situations: Mixing Wan 2.1 and Wan 2.2 checkpoints in one workflow; switching a TI2V-5B pipeline to A14B without swapping the VAE node; an older workflow template referencing the wrong VAE model after an upgrade.
Related errors
- Latent channel mismatch: these latents have {latents.shape[1
- Wan image denoise expects initial latent dimensions {expecte
- Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.mo
- Wan latents-to-image expects a 4D or 5D latent tensor [B, C,
- Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.mo
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/df634ce22ee95ef7.
Report an issue: GitHub.