{"record":{"id":"414c6445fddf399a","repo":"invoke-ai/InvokeAI","slug":"expected-autoencoderklwan-or-fluxautoencoder-got-414c64","errorCode":null,"errorMessage":"Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae).__name__}.","messagePattern":"Expected AutoencoderKLWan or FluxAutoEncoder, got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/anima_latents_to_image.py","lineNumber":144,"sourceCode":"            )\n            use_tiling = self._use_tiled_decode(TorchDevice.choose_torch_device(), full_decode_working_memory)\n            estimated_working_memory = estimate_vae_working_memory_anima(\n                operation=\"decode\",\n                image_tensor=latents,\n                vae=vae_info.model,\n                tile_size=ANIMA_VAE_TILE_SIZE if use_tiling else None,\n            )\n        else:\n            estimated_working_memory = estimate_vae_working_memory_flux(\n                operation=\"decode\",\n                image_tensor=latents,\n                vae=vae_info.model,\n            )\n\n        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):\n            context.util.signal_progress(\"Running Anima VAE decode\")\n            if not isinstance(vae, (AutoencoderKLWan, FluxAutoEncoder)):\n                raise TypeError(f\"Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae).__name__}.\")\n\n            vae_dtype = next(iter(vae.parameters())).dtype\n            # Use the VAE's intended compute device (CUDA/MPS, or CPU if configured cpu_only). Do NOT infer it from\n            # current param residency: partial loading may have temporarily offloaded all weights to RAM, which would\n            # wrongly place the latents (and thus the whole decode) on the CPU (see #9373).\n            latents = latents.to(device=vae_info.compute_device, dtype=vae_dtype)\n\n            TorchDevice.empty_cache()\n\n            with torch.inference_mode():\n                if isinstance(vae, FluxAutoEncoder):\n                    # FLUX VAE handles scaling internally, expects 4D [B, C, H, W]\n                    img = vae.decode(latents)\n                else:\n                    # The cached VAE instance is shared across invocations, so always set\n                    # the tiling state explicitly rather than leaving it as-is.\n                    if use_tiling:\n                        vae.enable_tiling(","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/anima_latents_to_image.py#L126-L162","documentation":"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.","triggerScenarios":"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.","commonSituations":"Long-running generation during which the model was unloaded/reloaded; InvokeAI version mismatch in model residency code; a corrupted on-device cache.","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."],"exampleFix":"# before: VAE offloaded/swapped mid-run causing mismatched on-device object\n# after: restart backend / pin the model in memory (disable eager offload) so model_on_device yields the validated VAE","handlingStrategy":"type-guard","validationCode":"with vae_info.model_on_device() as (_, vae):\n    if not is_anima_vae(vae):\n        raise TypeError(\"on-device VAE type mismatch; reload before decode\")","typeGuard":"def is_anima_vae(vae) -> bool:\n    from diffusers import AutoencoderKLWan\n    from invokeai.backend.flux.model import FluxAutoEncoder\n    return isinstance(vae, (AutoencoderKLWan, FluxAutoEncoder))","tryCatchPattern":"try:\n    latents2img.invoke(context)\nexcept TypeError as e:\n    if \"Expected AutoencoderKLWan or FluxAutoEncoder\" in str(e) and \"got\" in str(e):\n        restart_or_reload_model(vae_key)  # clear residency cache and retry","preventionTips":["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"],"tags":["vae","type-error","device-management"],"backgroundTag":"incompatible-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}