invoke-ai/InvokeAI · error · TypeError
Expected AutoencoderKL or FluxAutoEncoder, got {type(vae).__
Error message
Expected AutoencoderKL or FluxAutoEncoder, got {type(vae).__name__}. VAE model type changed unexpectedly after loading. What it means
Inside the device-context manager (model_on_device), the VAE object handed back is re-checked: it must still be AutoencoderKL or FluxAutoEncoder. This is a defensive invariant check - the type was already validated at load time, so failure here means the model wrapper returned a different object than expected (e.g. a swapped, re-loaded, or partially-converted model). The message says 'changed unexpectedly after loading'.
Source
Thrown at invokeai/app/invocations/z_image_latents_to_image.py:72
is_flux_vae = isinstance(vae_info.model, FluxAutoEncoder)
# Estimate working memory needed for VAE decode
estimated_working_memory = estimate_vae_working_memory_flux(
operation="decode",
image_tensor=latents,
vae=vae_info.model,
)
# FLUX VAE doesn't support seamless, so only apply for AutoencoderKL
seamless_context = (
nullcontext() if is_flux_vae else SeamlessExt.static_patch_model(vae_info.model, self.vae.seamless_axes)
)
with seamless_context, vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):
context.util.signal_progress("Running VAE")
if not isinstance(vae, (AutoencoderKL, FluxAutoEncoder)):
raise TypeError(
f"Expected AutoencoderKL or FluxAutoEncoder, got {type(vae).__name__}. "
"VAE model type changed unexpectedly after loading."
)
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)
# Disable tiling for AutoencoderKL
if isinstance(vae, AutoencoderKL):
vae.disable_tiling()
# Clear memory as VAE decode can request a lot
TorchDevice.empty_cache()
with torch.inference_mode():View on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-run the invocation; transient model-cache swaps are the usual cause.
- Verify the VAE field still points at a Z-Image/Flux compatible VAE and re-open the workflow.
- Clear/restart the model RAM cache or restart InvokeAI to flush stale loaded models.
- Check for multiple concurrent workflows sharing the VAE and serialize them; update InvokeAI if reproducible.
Defensive patterns
Strategy: try-catch
Type guard
def vae_stable_after_load(vae) -> bool:
from diffusers import AutoencoderKL
from invokeai.backend.flux.vae import FluxAutoEncoder
return isinstance(vae, (AutoencoderKL, FluxAutoEncoder)) Try / catch
try:
out = z_image_l2i.invoke(context)
except TypeError as e:
if "changed unexpectedly" in str(e):
context.logger.warning("Model cache swapped VAE mid-run; retrying once.")
out = retry(z_image_l2i.invoke, context)
else:
raise Prevention
- Avoid running many concurrent workflows that compete for the same VAE in RAM cache.
- Restart InvokeAI / clear model cache if this error recurs after model changes.
- Re-run the invocation first - transient swaps often resolve on retry.
When it happens
Trigger: Within invoke() of ZImageLatentsToImage, entering `with ... vae_info.model_on_device(...) as (_, vae)` and the yielded object fails isinstance(vae, (AutoencoderKL, FluxAutoEncoder)).
Common situations: Concurrency/memory pressure causing the model to be unloaded and swapped mid-session; a patched loader returning a wrapper or converted dtype object; race with another invocation replacing the model; exotic SeamlessVae wrapper logic interacting with a non-standard VAE.
Related errors
- Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, g
- Expected AutoencoderKL or FluxAutoEncoder, got {type(vae).__
- No VAE source provided. Either set 'VAE' to a FLUX VAE model
- Expected Qwen3Encoder_Checkpoint_Config, got {type(config)._
- Expected Qwen3Encoder_GGUF_Config, got {type(config).__name_
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/54244273492530d9.
Report an issue: GitHub.