invoke-ai/InvokeAI · error · TypeError

Reference-image encoder requires AutoencoderKLWan, got {type

Error message

Reference-image encoder requires AutoencoderKLWan, got {type(vae_info.model).__name__}.

What it means

Reference-image encoding for Wan 2.2 requires the loaded VAE to be diffusers' AutoencoderKLWan, because the encoder calls Wan-specific encode paths and config attributes (z_dim). InvokeAI raises TypeError when the model bound to the VAE model-field is any other architecture (SD, SDXL, FLUX VAEs, etc.).

Source

Thrown at invokeai/app/invocations/wan_ref_image_encoder.py:120

        "video interpolates from the reference image (first frame) to this image (final frame). "
        "I2V-A14B video only (num_frames > 1); not supported for TI2V-5B or single-frame I2V.",
        title="End Image (FLF2V)",
    )

    @torch.no_grad()
    def invoke(self, context: InvocationContext) -> WanRefImageOutput:
        if self.num_frames > 1 and (self.num_frames - 1) % 4 != 0:
            raise ValueError(
                f"num_frames must satisfy (num_frames - 1) %% 4 == 0 for the Wan VAE's temporal "
                f"compression (got {self.num_frames}). Try 5, 9, 13, ..., 81, 85, ..."
            )

        pil_image = context.images.get_pil(self.image.image_name, "RGB")
        end_pil_image = context.images.get_pil(self.end_image.image_name, "RGB") if self.end_image is not None else None

        vae_info = context.models.load(self.vae.vae)
        if not isinstance(vae_info.model, AutoencoderKLWan):
            raise TypeError(f"Reference-image encoder requires AutoencoderKLWan, got {type(vae_info.model).__name__}.")

        estimated_working_memory = estimate_vae_working_memory_wan(
            operation="encode",
            vae=vae_info.model,
            pixel_height=self.height,
            pixel_width=self.width,
            pixel_frames=self.num_frames,
        )

        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):
            assert isinstance(vae, AutoencoderKLWan)
            # A cpu_only VAE stays in system RAM even when an accelerator is selected —
            # run the encode where the weights actually live.
            device = get_effective_device(vae)
            target_dtype = TorchDevice.choose_bfloat16_safe_dtype(device)
            context.util.signal_progress(
                ("VAE-encoding FLF2V start+end images" if end_pil_image is not None else "VAE-encoding reference image")
                + (f" ({self.num_frames} frames)" if self.num_frames > 1 else "")

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Load the AutoencoderKLWan VAE shipped with the matching Wan 2.2 checkpoint (I2V-A14B or TI2V-5B) into the vae input.
  2. Verify the model type in Model Manager (should be main / VAE of type AutoencoderKLWan) and re-install the Wan model if it resolved to the wrong class.
  3. Remove any VAE override node so the pipeline uses the Wan checkpoint's own VAE.

Example fix

// before
vae = sdxl_vae_model_key  # AutoencoderKL, wrong type
// after
vae = wan_i2v_a14b_vae_model_key  # AutoencoderKLWan
Defensive patterns

Strategy: type-guard

Validate before calling

from diffusers import AutoencoderKLWan
vae_info = context.models.load(vae_field.vae)
if not isinstance(vae_info.model, AutoencoderKLWan):
    raise TypeError(f"Need AutoencoderKLWan, got {type(vae_info.model).__name__}")

Type guard

def is_wan_vae(model: object) -> bool:
    from diffusers import AutoencoderKLWan
    return isinstance(model, AutoencoderKLWan)

Try / catch

try:
    out = encoder.invoke(context)
except TypeError as e:
    if "requires AutoencoderKLWan" in str(e):
        vae_field.vae = load_wan_checkpoint_vae()  # swap to correct VAE
    else:
        raise

Prevention

When it happens

Trigger: Wiring a non-Wan VAE (e.g. an SDXL or FLUX AutoencoderKL) into the vae input of the wan_ref_image_encoder invocation, or a model-field/loader that resolves to the wrong model type.

Common situations: Selecting the default/global VAE in the workflow instead of the one downloaded with the Wan I2V checkpoint; a stale model-install record pointing a Wan VAE name at a different file.

Related errors


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