{"record":{"id":"56c1c6d30fb4890e","repo":"invoke-ai/InvokeAI","slug":"expected-autoencoderklwan-for-wan-vae-got-type-v-56c1c6","errorCode":null,"errorMessage":"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.","messagePattern":"Expected AutoencoderKLWan for Wan VAE, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_latents_to_video.py","lineNumber":107,"sourceCode":"\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> VideoOutput:\n        latents = context.tensors.load(self.latents.latents_name)\n        _validate_video_latent_batch(latents)\n        if latents.ndim == 4:\n            # Promote 4D (single-frame) to 5D so this node can also serve as a\n            # one-frame \"video\" encode if someone wires it that way.\n            latents = latents.unsqueeze(2)\n        if latents.ndim != 5:\n            raise ValueError(\n                f\"Wan latents-to-video expects a 5D latent tensor [B, C, T, H, W]; got {tuple(latents.shape)}.\"\n            )\n        if any(size == 0 for size in latents.shape[2:]):\n            raise ValueError(\"Wan latents-to-video requires non-empty temporal and spatial dimensions.\")\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        if latents.shape[1] != vae_info.model.config.z_dim:\n            raise ValueError(\n                f\"Latent channel mismatch: these latents have {latents.shape[1]} channels but the \"\n                f\"selected VAE expects {vae_info.model.config.z_dim}. A14B models need the 16-channel Wan 2.1 VAE; \"\n                \"TI2V-5B needs the 48-channel Wan 2.2 VAE.\"\n            )\n\n        _, _, t_lat, h_lat, w_lat = latents.shape\n        spatial_scale = getattr(vae_info.model.config, \"scale_factor_spatial\", None) or 8\n        temporal_scale = getattr(vae_info.model.config, \"scale_factor_temporal\", None) or 4\n        t_pixel = (t_lat - 1) * temporal_scale + 1\n        h_pixel, w_pixel = h_lat * spatial_scale, w_lat * spatial_scale\n        optimize_memory = context.config.get().wan_memory_optimization\n\n        estimated_working_memory = estimate_vae_working_memory_wan(\n            operation=\"decode\",\n            vae=vae_info.model,","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_latents_to_video.py#L89-L125","documentation":"invoke() loads the VAE via context.models.load and asserts it is a diffusers AutoencoderKLWan instance, because the decode path depends on Wan-specific APIs (config.z_dim, Wan decode semantics). Any other VAE class raises this TypeError with the actual class name.","triggerScenarios":"Wiring a non-Wan VAE (e.g. SDXL AutoencoderKL, AutoencoderKLWan wrapped differently, Flux VAE) into the vae field of wan_latents_to_video and calling invoke().","commonSituations":"Reusing a VAE node from an SD/Flux workflow template; a model manager record resolving to the wrong model class; copy-pasting a VAE model ID between workflows.","solutions":["Point the node's vae field at a Wan VAE model (AutoencoderKLWan).","Check the loaded model type in the Model Manager and correct the record if it resolves to the wrong class.","Create a fresh VAE node referencing the Wan 2.1/2.2 VAE instead of reusing an image-model VAE."],"exampleFix":"// before\nvae = sdxl_vae  # AutoencoderKL\nvideo = wan_latents_to_video(latents=latents, vae=vae)  # TypeError\n// after\nvae = wan_vae  # AutoencoderKLWan (Wan 2.1 or 2.2)\nvideo = wan_latents_to_video(latents=latents, vae=vae)","handlingStrategy":"type-guard","validationCode":"vae_info = context.models.load(vae.vae)\nif not isinstance(vae_info.model, AutoencoderKLWan):\n    raise TypeError(f\"Need AutoencoderKLWan, got {type(vae_info.model).__name__}\")","typeGuard":"def is_wan_vae(model) -> bool:\n    return isinstance(model, AutoencoderKLWan)","tryCatchPattern":"try:\n    video = node.invoke(context)\nexcept TypeError as e:\n    if \"Expected AutoencoderKLWan\" in str(e):\n        vae = load_wan_vae_for(transformer_variant)\n        video = replace(node, vae=vae).invoke(context)\n    else:\n        raise","preventionTips":["Verify VAE class in the Model Manager record before wiring.","Never share VAE nodes across SD/Flux/Wan workflows.","Use a fresh VAE node per Wan workflow.","Check model IDs include the 'wan' family."],"tags":["wan","vae","type-mismatch","model-loading"],"backgroundTag":"wrong-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}