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

The Wan Image to Latents node's vae_encode static method requires the loaded VAE model to be an AutoencoderKLWan, since its encode path and memory estimation are Wan-specific. A different VAE class (e.g., SD/SDXL/Flux AutoencoderKL) cannot encode Wan latents, so a TypeError is raised naming the actual class found.

Source

Thrown at invokeai/app/invocations/wan_image_to_latents.py:55

    category="image",
    version="1.0.0",
    classification=Classification.Prototype,
)
class WanImageToLatentsInvocation(BaseInvocation, WithMetadata, WithBoard):
    """Encodes an image with the Wan VAE (AutoencoderKLWan).

    The output latents have the temporal dimension squeezed out, so downstream
    nodes see 4D ``[B, C, H, W]``. The denoise loop re-adds ``T=1`` before
    feeding the transformer.
    """

    image: ImageField = InputField(description="The image to encode.")
    vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)

    @staticmethod
    def vae_encode(vae_info: LoadedModel, image_tensor: torch.Tensor) -> torch.Tensor:
        if not isinstance(vae_info.model, AutoencoderKLWan):
            raise TypeError(f"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.")

        estimated_working_memory = estimate_vae_working_memory_wan(
            operation="encode",
            vae=vae_info.model,
            pixel_height=image_tensor.shape[-2],
            pixel_width=image_tensor.shape[-1],
            pixel_frames=image_tensor.shape[2] if image_tensor.ndim == 5 else 1,
        )

        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):
            assert isinstance(vae, AutoencoderKLWan)

            vae_dtype = next(iter(vae.parameters())).dtype
            image_tensor = image_tensor.to(device=get_effective_device(vae), dtype=vae_dtype)

            with torch.inference_mode():
                # Wan VAE expects 5D [B, C, T, H, W].
                if image_tensor.ndim == 4:

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Connect a Wan VAE (AutoencoderKLWan) to the vae input — use the VAE shipped with your Wan checkpoint
  2. Verify the model selected in the VAE loader is a Wan 2.1/2.2 VAE
  3. Rebuild the workflow from a Wan template if stale model keys persist

Example fix

// before
vaeModel: "sdxl-vae" -> wanImageToLatents.vae
// after
vaeModel: "wan2.1-t2v-vae" (AutoencoderKLWan) -> wanImageToLatents.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:
    latents = wan_image_to_latents.invoke(context)
except TypeError as e:
    if 'Expected AutoencoderKLWan' in str(e):
        load_correct_wan_vae()
    else:
        raise

Prevention

When it happens

Trigger: Connecting a non-Wan VAE (SD1.5, SDXL, Flux VAE) to the Wan Image to Latents node's vae input; a model-manager misconfiguration where the wrong model was loaded under the VAE field.

Common situations: Copying a VAE connection from an SDXL workflow into a Wan video workflow; selecting the wrong model in the model dropdown; stale workflow JSON referencing an old VAE model key.

Related errors


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