{"record":{"id":"702fb24a1560d6d2","repo":"invoke-ai/InvokeAI","slug":"expected-autoencoderkl-or-fluxautoencoder-for-z-im","errorCode":null,"errorMessage":"Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, got {type(vae_info.model).__name__}. Ensure you are using a compatible VAE model.","messagePattern":"Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, got (.+?)\\. Ensure you are using a compatible VAE model\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/z_image_image_to_latents.py","lineNumber":46,"sourceCode":"\n@invocation(\n    \"z_image_i2l\",\n    title=\"Image to Latents - Z-Image\",\n    tags=[\"image\", \"latents\", \"vae\", \"i2l\", \"z-image\"],\n    category=\"latents\",\n    version=\"1.1.0\",\n    classification=Classification.Prototype,\n)\nclass ZImageImageToLatentsInvocation(BaseInvocation, WithMetadata, WithBoard):\n    \"\"\"Generates latents from an image using Z-Image VAE (supports both Diffusers and FLUX VAE).\"\"\"\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, (AutoencoderKL, FluxAutoEncoder)):\n            raise TypeError(\n                f\"Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, got {type(vae_info.model).__name__}. \"\n                \"Ensure you are using a compatible VAE model.\"\n            )\n\n        # Estimate working memory needed for VAE encode\n        estimated_working_memory = estimate_vae_working_memory_flux(\n            operation=\"encode\",\n            image_tensor=image_tensor,\n            vae=vae_info.model,\n        )\n\n        with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):\n            if not isinstance(vae, (AutoencoderKL, FluxAutoEncoder)):\n                raise TypeError(\n                    f\"Expected AutoencoderKL or FluxAutoEncoder, got {type(vae).__name__}. \"\n                    \"VAE model type changed unexpectedly after loading.\"\n                )\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/z_image_image_to_latents.py#L28-L64","documentation":"Z-Image image-to-latents encodes images with a VAE that must be an AutoencoderKL or FluxAutoEncoder instance. vae_encode is a static method that validates the loaded model type before encoding; anything else (wrong architecture's VAE) raises TypeError so encoding proceeds only with a compatible VAE.","triggerScenarios":"Calling invoke() on the Z-Image image-to-latents invocation where the VAE referenced by the VAEField loads to a model that is neither AutoencoderKL nor FluxAutoEncoder — e.g. an SDXL/SD-1 VAE or other architecture's autoencoder.","commonSituations":"Wiring a VAE from a different model family into a Z-Image workflow; a model-manager entry pointing at the wrong VAE file; using an old workflow whose VAE key refers to a now-different model.","solutions":["Connect a Z-Image-compatible VAE (AutoencoderKL or FluxAutoEncoder) to the invocation's 'vae' input","Check the model manager that the VAE entry points at the correct architecture's file","Replace the VAE node in the workflow with one matching the Z-Image base model"],"exampleFix":"// before\nimg2latents = ZImageImageToLatentsInvocation(image=img, vae=sdxl_vae_field)\n// after\nimg2latents = ZImageImageToLatentsInvocation(image=img, vae=z_image_vae_field)","handlingStrategy":"type-guard","validationCode":"vae_info = context.models.load(vae_field.vae)\nif not isinstance(vae_info.model, (AutoencoderKL, FluxAutoEncoder)):\n    raise TypeError(f\"Incompatible VAE: {type(vae_info.model).__name__}\")","typeGuard":"def is_zimage_vae(model) -> bool:\n    return isinstance(model, (AutoencoderKL, FluxAutoEncoder))","tryCatchPattern":"try:\n    latents = img2latents.invoke(context)\nexcept TypeError as e:\n    if \"Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE\" in str(e):\n        raise ModelCompatibilityError(\"swap in a Z-Image-compatible VAE\") from e\n    raise","preventionTips":["Pair VAE nodes with the matching base model architecture","Verify the VAE model-manager entry points at the right file after model updates","Never reuse Flux/SD VAE nodes across architectures without checking the class"],"tags":["vae","type-error","model-compatibility"],"backgroundTag":"incompatible-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}