invoke-ai/InvokeAI · error · TypeError
Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae)
Error message
Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae).__name__}. What it means
A post-device-residency re-check in the decode path: after model_on_device yields the VAE, the code re-validates it is AutoencoderKLWan or FluxAutoEncoder and raises this TypeError otherwise. The initial invoke() check passed, so this usually indicates the on-device object changed between checks.
Source
Thrown at invokeai/app/invocations/anima_latents_to_image.py:144
)
use_tiling = self._use_tiled_decode(TorchDevice.choose_torch_device(), full_decode_working_memory)
estimated_working_memory = estimate_vae_working_memory_anima(
operation="decode",
image_tensor=latents,
vae=vae_info.model,
tile_size=ANIMA_VAE_TILE_SIZE if use_tiling else None,
)
else:
estimated_working_memory = estimate_vae_working_memory_flux(
operation="decode",
image_tensor=latents,
vae=vae_info.model,
)
with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):
context.util.signal_progress("Running Anima VAE decode")
if not isinstance(vae, (AutoencoderKLWan, FluxAutoEncoder)):
raise TypeError(f"Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae).__name__}.")
vae_dtype = next(iter(vae.parameters())).dtype
# Use the VAE's intended compute device (CUDA/MPS, or CPU if configured cpu_only). Do NOT infer it from
# current param residency: partial loading may have temporarily offloaded all weights to RAM, which would
# wrongly place the latents (and thus the whole decode) on the CPU (see #9373).
latents = latents.to(device=vae_info.compute_device, dtype=vae_dtype)
TorchDevice.empty_cache()
with torch.inference_mode():
if isinstance(vae, FluxAutoEncoder):
# FLUX VAE handles scaling internally, expects 4D [B, C, H, W]
img = vae.decode(latents)
else:
# The cached VAE instance is shared across invocations, so always set
# the tiling state explicitly rather than leaving it as-is.
if use_tiling:
vae.enable_tiling(View on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-run the generation so the model loads freshly and consistently.
- Update InvokeAI; on-device yield behavior should match the validated type.
- Avoid concurrent edits to the model list while a workflow runs; restart the app to clear residency state.
Example fix
# before: VAE offloaded/swapped mid-run causing mismatched on-device object # after: restart backend / pin the model in memory (disable eager offload) so model_on_device yields the validated VAE
Defensive patterns
Strategy: type-guard
Validate before calling
with vae_info.model_on_device() as (_, vae):
if not is_anima_vae(vae):
raise TypeError("on-device VAE type mismatch; reload before decode") Type guard
def is_anima_vae(vae) -> bool:
from diffusers import AutoencoderKLWan
from invokeai.backend.flux.model import FluxAutoEncoder
return isinstance(vae, (AutoencoderKLWan, FluxAutoEncoder)) Try / catch
try:
latents2img.invoke(context)
except TypeError as e:
if "Expected AutoencoderKLWan or FluxAutoEncoder" in str(e) and "got" in str(e):
restart_or_reload_model(vae_key) # clear residency cache and retry Prevention
- Do not unload/swap models during a running generation
- Keep InvokeAI current; on-device yield behavior changed across versions
- Pin frequently used VAEs in memory to avoid offload churn
When it happens
Trigger: The object yielded by model_on_device during decode is not the expected VAE instance — e.g. model record swapped/offloaded concurrently or an incompatibility between the loaded wrapper and current InvokeAI internals.
Common situations: Long-running generation during which the model was unloaded/reloaded; InvokeAI version mismatch in model residency code; a corrupted on-device cache.
Related errors
- Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae)
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.mo
- 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/414c6445fddf399a.
Report an issue: GitHub.