invoke-ai/InvokeAI · error · TypeError

Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.mo

Error message

Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.

What it means

Same guard as the encode side: Wan Latents to Image needs an AutoencoderKLWan because its decode path, spatial scale factor, and memory estimation are Wan-specific. Any other VAE class loaded in the VAE field triggers this TypeError naming the actual class.

Source

Thrown at invokeai/app/invocations/wan_latents_to_image.py:72

            raise ValueError(
                f"Wan latents-to-image expects a 4D or 5D latent tensor [B, C, (T), H, W]; got {tuple(latents.shape)}."
            )
        if latents.shape[0] != 1:
            raise ValueError(f"Wan latents-to-image requires batch size 1; got {latents.shape[0]}.")

        # This node decodes exactly one image. Multi-frame video latents would otherwise
        # run the full (expensive) multi-frame VAE decode — under a working-memory
        # estimate that assumed one frame — and then die in an opaque einops rank error
        # at the final rearrange. Checked before the VAE is even loaded.
        if latents.ndim == 5 and latents.shape[2] != 1:
            raise ValueError(
                f"These latents hold {latents.shape[2]} frames of video; this node decodes a single "
                "image. Use 'Latents to Video - Wan 2.2' (wan_l2v) for video latents."
            )

        vae_info = context.models.load(self.vae.vae)
        if not isinstance(vae_info.model, AutoencoderKLWan):
            raise TypeError(f"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.")

        spatial_scale = getattr(vae_info.model.config, "scale_factor_spatial", None) or 8
        estimated_working_memory = estimate_vae_working_memory_wan(
            operation="decode",
            vae=vae_info.model,
            pixel_height=latents.shape[-2] * spatial_scale,
            pixel_width=latents.shape[-1] * spatial_scale,
            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()

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Connect the Wan VAE (AutoencoderKLWan) matching your Wan model (8x-VAE or 16x-VAE TI2V-5B)
  2. Check the VAE loader node's selected model is a Wan VAE
  3. Rebuild from a Wan template if stale keys persist

Example fix

// before
vaeModel: "flux-vae" -> wanLatentsToImage.vae
// after
vaeModel: "wan2.2-ti2v-5b-vae" (AutoencoderKLWan) -> wanLatentsToImage.vae
Defensive patterns

Strategy: type-guard

Validate before calling

vae_info = context.models.load(vae_field.vae)
if not isinstance(vae_info.model, AutoencoderKLWan):
    raise TypeError(f"need a Wan VAE, got {type(vae_info.model).__name__}")

Type guard

def is_wan_vae(vae_info: LoadedModel) -> bool:
    return isinstance(vae_info.model, AutoencoderKLWan)

Try / catch

try:
    out = wan_latents_to_image.invoke(context)
except TypeError as e:
    if 'Expected AutoencoderKLWan' in str(e):
        load_correct_wan_vae()
    else:
        raise

Prevention

When it happens

Trigger: Connecting an SD/SDXL/Flux VAE to the Wan Latents to Image vae input; wrong model selected in the model manager; stale workflow referencing a non-Wan VAE key.

Common situations: Reusing VAE loader nodes from image workflows in video workflows; users switching checkpoints without switching the VAE.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/8ba5df3e81b1b142. Report an issue: GitHub.