{"record":{"id":"8ba5df3e81b1b142","repo":"invoke-ai/InvokeAI","slug":"expected-autoencoderklwan-for-wan-vae-got-type-v-8ba5df","errorCode":null,"errorMessage":"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.","messagePattern":"Expected AutoencoderKLWan for Wan VAE, got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_latents_to_image.py","lineNumber":72,"sourceCode":"            raise ValueError(\n                f\"Wan latents-to-image expects a 4D or 5D latent tensor [B, C, (T), H, W]; got {tuple(latents.shape)}.\"\n            )\n        if latents.shape[0] != 1:\n            raise ValueError(f\"Wan latents-to-image requires batch size 1; got {latents.shape[0]}.\")\n\n        # This node decodes exactly one image. Multi-frame video latents would otherwise\n        # run the full (expensive) multi-frame VAE decode — under a working-memory\n        # estimate that assumed one frame — and then die in an opaque einops rank error\n        # at the final rearrange. Checked before the VAE is even loaded.\n        if latents.ndim == 5 and latents.shape[2] != 1:\n            raise ValueError(\n                f\"These latents hold {latents.shape[2]} frames of video; this node decodes a single \"\n                \"image. Use 'Latents to Video - Wan 2.2' (wan_l2v) for video latents.\"\n            )\n\n        vae_info = context.models.load(self.vae.vae)\n        if not isinstance(vae_info.model, AutoencoderKLWan):\n            raise TypeError(f\"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.\")\n\n        spatial_scale = getattr(vae_info.model.config, \"scale_factor_spatial\", None) or 8\n        estimated_working_memory = estimate_vae_working_memory_wan(\n            operation=\"decode\",\n            vae=vae_info.model,\n            pixel_height=latents.shape[-2] * spatial_scale,\n            pixel_width=latents.shape[-1] * spatial_scale,\n            pixel_frames=1,\n        )\n\n        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):\n            context.util.signal_progress(\"Running Wan VAE decode\")\n            assert isinstance(vae, AutoencoderKLWan)\n\n            vae_dtype = next(iter(vae.parameters())).dtype\n            latents = latents.to(device=get_effective_device(vae), dtype=vae_dtype)\n\n            TorchDevice.empty_cache()","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_latents_to_image.py#L54-L90","documentation":"Same guard as the encode side: Wan Latents to Image needs an AutoencoderKLWan because its decode path, spatial scale factor, and memory estimation are Wan-specific. Any other VAE class loaded in the VAE field triggers this TypeError naming the actual class.","triggerScenarios":"Connecting an SD/SDXL/Flux VAE to the Wan Latents to Image vae input; wrong model selected in the model manager; stale workflow referencing a non-Wan VAE key.","commonSituations":"Reusing VAE loader nodes from image workflows in video workflows; users switching checkpoints without switching the VAE.","solutions":["Connect the Wan VAE (AutoencoderKLWan) matching your Wan model (8x-VAE or 16x-VAE TI2V-5B)","Check the VAE loader node's selected model is a Wan VAE","Rebuild from a Wan template if stale keys persist"],"exampleFix":"// before\nvaeModel: \"flux-vae\" -> wanLatentsToImage.vae\n// after\nvaeModel: \"wan2.2-ti2v-5b-vae\" (AutoencoderKLWan) -> wanLatentsToImage.vae","handlingStrategy":"type-guard","validationCode":"vae_info = context.models.load(vae_field.vae)\nif not isinstance(vae_info.model, AutoencoderKLWan):\n    raise TypeError(f\"need a Wan VAE, got {type(vae_info.model).__name__}\")","typeGuard":"def is_wan_vae(vae_info: LoadedModel) -> bool:\n    return isinstance(vae_info.model, AutoencoderKLWan)","tryCatchPattern":"try:\n    out = wan_latents_to_image.invoke(context)\nexcept TypeError as e:\n    if 'Expected AutoencoderKLWan' in str(e):\n        load_correct_wan_vae()\n    else:\n        raise","preventionTips":["Match the VAE to the Wan model family (8x vs 16x VAE)","Keep VAE loader nodes dedicated to the Wan pipeline","Confirm model class in the model manager before connecting"],"tags":["invokeai","wan","type-error","vae","wrong-model"],"backgroundTag":"wrong-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}