{"record":{"id":"a4e125c0b7d93fca","repo":"invoke-ai/InvokeAI","slug":"expected-autoencoderklwan-for-wan-vae-got-type-v","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_image_to_latents.py","lineNumber":55,"sourceCode":"    category=\"image\",\n    version=\"1.0.0\",\n    classification=Classification.Prototype,\n)\nclass WanImageToLatentsInvocation(BaseInvocation, WithMetadata, WithBoard):\n    \"\"\"Encodes an image with the Wan VAE (AutoencoderKLWan).\n\n    The output latents have the temporal dimension squeezed out, so downstream\n    nodes see 4D ``[B, C, H, W]``. The denoise loop re-adds ``T=1`` before\n    feeding the transformer.\n    \"\"\"\n\n    image: ImageField = InputField(description=\"The image to encode.\")\n    vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)\n\n    @staticmethod\n    def vae_encode(vae_info: LoadedModel, image_tensor: torch.Tensor) -> torch.Tensor:\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        estimated_working_memory = estimate_vae_working_memory_wan(\n            operation=\"encode\",\n            vae=vae_info.model,\n            pixel_height=image_tensor.shape[-2],\n            pixel_width=image_tensor.shape[-1],\n            pixel_frames=image_tensor.shape[2] if image_tensor.ndim == 5 else 1,\n        )\n\n        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):\n            assert isinstance(vae, AutoencoderKLWan)\n\n            vae_dtype = next(iter(vae.parameters())).dtype\n            image_tensor = image_tensor.to(device=get_effective_device(vae), dtype=vae_dtype)\n\n            with torch.inference_mode():\n                # Wan VAE expects 5D [B, C, T, H, W].\n                if image_tensor.ndim == 4:","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_image_to_latents.py#L37-L73","documentation":"The Wan Image to Latents node's vae_encode static method requires the loaded VAE model to be an AutoencoderKLWan, since its encode path and memory estimation are Wan-specific. A different VAE class (e.g., SD/SDXL/Flux AutoencoderKL) cannot encode Wan latents, so a TypeError is raised naming the actual class found.","triggerScenarios":"Connecting a non-Wan VAE (SD1.5, SDXL, Flux VAE) to the Wan Image to Latents node's vae input; a model-manager misconfiguration where the wrong model was loaded under the VAE field.","commonSituations":"Copying a VAE connection from an SDXL workflow into a Wan video workflow; selecting the wrong model in the model dropdown; stale workflow JSON referencing an old VAE model key.","solutions":["Connect a Wan VAE (AutoencoderKLWan) to the vae input — use the VAE shipped with your Wan checkpoint","Verify the model selected in the VAE loader is a Wan 2.1/2.2 VAE","Rebuild the workflow from a Wan template if stale model keys persist"],"exampleFix":"// before\nvaeModel: \"sdxl-vae\" -> wanImageToLatents.vae\n// after\nvaeModel: \"wan2.1-t2v-vae\" (AutoencoderKLWan) -> wanImageToLatents.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    latents = wan_image_to_latents.invoke(context)\nexcept TypeError as e:\n    if 'Expected AutoencoderKLWan' in str(e):\n        load_correct_wan_vae()\n    else:\n        raise","preventionTips":["Only connect VAEs from Wan checkpoints to Wan nodes","Label VAE loader nodes per pipeline family (SD vs Wan)","Verify model type in the model manager before wiring"],"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"}