{"record":{"id":"af718908c1e59f8b","repo":"invoke-ai/InvokeAI","slug":"reference-image-encoder-requires-autoencoderklwan","errorCode":null,"errorMessage":"Reference-image encoder requires AutoencoderKLWan, got {type(vae_info.model).__name__}.","messagePattern":"Reference-image encoder requires AutoencoderKLWan, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_ref_image_encoder.py","lineNumber":120,"sourceCode":"        \"video interpolates from the reference image (first frame) to this image (final frame). \"\n        \"I2V-A14B video only (num_frames > 1); not supported for TI2V-5B or single-frame I2V.\",\n        title=\"End Image (FLF2V)\",\n    )\n\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> WanRefImageOutput:\n        if self.num_frames > 1 and (self.num_frames - 1) % 4 != 0:\n            raise ValueError(\n                f\"num_frames must satisfy (num_frames - 1) %% 4 == 0 for the Wan VAE's temporal \"\n                f\"compression (got {self.num_frames}). Try 5, 9, 13, ..., 81, 85, ...\"\n            )\n\n        pil_image = context.images.get_pil(self.image.image_name, \"RGB\")\n        end_pil_image = context.images.get_pil(self.end_image.image_name, \"RGB\") if self.end_image is not None else None\n\n        vae_info = context.models.load(self.vae.vae)\n        if not isinstance(vae_info.model, AutoencoderKLWan):\n            raise TypeError(f\"Reference-image encoder requires AutoencoderKLWan, 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=self.height,\n            pixel_width=self.width,\n            pixel_frames=self.num_frames,\n        )\n\n        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):\n            assert isinstance(vae, AutoencoderKLWan)\n            # A cpu_only VAE stays in system RAM even when an accelerator is selected —\n            # run the encode where the weights actually live.\n            device = get_effective_device(vae)\n            target_dtype = TorchDevice.choose_bfloat16_safe_dtype(device)\n            context.util.signal_progress(\n                (\"VAE-encoding FLF2V start+end images\" if end_pil_image is not None else \"VAE-encoding reference image\")\n                + (f\" ({self.num_frames} frames)\" if self.num_frames > 1 else \"\")","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_ref_image_encoder.py#L102-L138","documentation":"Reference-image encoding for Wan 2.2 requires the loaded VAE to be diffusers' AutoencoderKLWan, because the encoder calls Wan-specific encode paths and config attributes (z_dim). InvokeAI raises TypeError when the model bound to the VAE model-field is any other architecture (SD, SDXL, FLUX VAEs, etc.).","triggerScenarios":"Wiring a non-Wan VAE (e.g. an SDXL or FLUX AutoencoderKL) into the vae input of the wan_ref_image_encoder invocation, or a model-field/loader that resolves to the wrong model type.","commonSituations":"Selecting the default/global VAE in the workflow instead of the one downloaded with the Wan I2V checkpoint; a stale model-install record pointing a Wan VAE name at a different file.","solutions":["Load the AutoencoderKLWan VAE shipped with the matching Wan 2.2 checkpoint (I2V-A14B or TI2V-5B) into the vae input.","Verify the model type in Model Manager (should be main / VAE of type AutoencoderKLWan) and re-install the Wan model if it resolved to the wrong class.","Remove any VAE override node so the pipeline uses the Wan checkpoint's own VAE."],"exampleFix":"// before\nvae = sdxl_vae_model_key  # AutoencoderKL, wrong type\n// after\nvae = wan_i2v_a14b_vae_model_key  # AutoencoderKLWan","handlingStrategy":"type-guard","validationCode":"from diffusers import AutoencoderKLWan\nvae_info = context.models.load(vae_field.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: object) -> bool:\n    from diffusers import AutoencoderKLWan\n    return isinstance(model, AutoencoderKLWan)","tryCatchPattern":"try:\n    out = encoder.invoke(context)\nexcept TypeError as e:\n    if \"requires AutoencoderKLWan\" in str(e):\n        vae_field.vae = load_wan_checkpoint_vae()  # swap to correct VAE\n    else:\n        raise","preventionTips":["Always pair the VAE with its matching Wan checkpoint rather than using a global VAE.","Check model type in the Model Manager before wiring workflows.","Don't override the VAE input on Wan I2V workflows unless you know the type."],"tags":["type-error","vae","wan","model-mismatch"],"backgroundTag":"incompatible-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}