{"record":{"id":"4f4b8cfa76d66f21","repo":"invoke-ai/InvokeAI","slug":"expected-autoencoderkl-or-fluxautoencoder-for-z-im-4f4b8c","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_latents_to_image.py","lineNumber":50,"sourceCode":"    title=\"Latents to Image - Z-Image\",\n    tags=[\"latents\", \"image\", \"vae\", \"l2i\", \"z-image\"],\n    category=\"latents\",\n    version=\"1.1.0\",\n    classification=Classification.Prototype,\n)\nclass ZImageLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard):\n    \"\"\"Generates an image from latents using Z-Image VAE (supports both Diffusers and FLUX VAE).\"\"\"\n\n    latents: LatentsField = InputField(description=FieldDescriptions.latents, input=Input.Connection)\n    vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)\n\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> ImageOutput:\n        latents = context.tensors.load(self.latents.latents_name)\n\n        vae_info = context.models.load(self.vae.vae)\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        is_flux_vae = isinstance(vae_info.model, FluxAutoEncoder)\n\n        # Estimate working memory needed for VAE decode\n        estimated_working_memory = estimate_vae_working_memory_flux(\n            operation=\"decode\",\n            image_tensor=latents,\n            vae=vae_info.model,\n        )\n\n        # FLUX VAE doesn't support seamless, so only apply for AutoencoderKL\n        seamless_context = (\n            nullcontext() if is_flux_vae else SeamlessExt.static_patch_model(vae_info.model, self.vae.seamless_axes)\n        )\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/z_image_latents_to_image.py#L32-L68","documentation":"In the Z-Image latents-to-image (decode) invocation, the loaded VAE is type-checked before decoding: it must be diffusers AutoencoderKL or FluxAutoEncoder. Any other VAE class means the selected model cannot decode Z-Image latents, so a TypeError is raised instead of producing garbage images. The check also determines the is_flux_vae branch used for decoding context.","triggerScenarios":"Running ZImageLatentsToImage with self.vae referencing a model whose class is neither AutoencoderKL nor FluxAutoEncoder, checked immediately after context.models.load(self.vae.vae).","commonSituations":"Using an SD/SDXL/SD3 VAE in a Z-Image workflow; graph templates reused across model families; VAE model misconfigured in the Model Manager; user manually pointing a decode node at a checkpoint's embedded wrong VAE.","solutions":["Point the VAE field at the Z-Image VAE (AutoencoderKL) or a FLUX VAE (FluxAutoEncoder).","Use ZImageModelLoader with a Diffusers Z-Image source so the correct VAE submodel is resolved automatically.","Correct the model's base/type metadata in the Model Manager if the right file is misregistered.","Update InvokeAI if you believe this VAE should be supported."],"exampleFix":"// before\nvae = ModelField(id='sd3-vae')\n// after\nvae = ModelField(id='flux-vae')  # or z-image AutoencoderKL VAE","handlingStrategy":"type-guard","validationCode":"cfg = context.models.get_config(latents_to_image.vae.vae)\nassert cfg.base in (BaseModelType.ZImage, BaseModelType.Flux), f\"VAE {cfg.name} is {cfg.base}, not usable for Z-Image decode\"","typeGuard":"from diffusers import AutoencoderKL\nfrom invokeai.backend.flux.vae import FluxAutoEncoder\n\ndef can_decode_zimage_latents(vae) -> bool:\n    return isinstance(vae, (AutoencoderKL, FluxAutoEncoder))","tryCatchPattern":"try:\n    out = z_image_l2i.invoke(context)\nexcept TypeError as e:\n    if \"Expected AutoencoderKL or FluxAutoEncoder\" in str(e):\n        context.logger.error(\"Decode VAE is incompatible with Z-Image latents; select the Flux/Z-Image VAE.\")\n    else:\n        raise","preventionTips":["Never reuse SD/SDXL/SD3 VAE nodes in Z-Image graphs.","Resolve all submodels (transformer, VAE, encoder) from one ZImageModelLoader output.","Check the VAE's base in the Model Manager when a workflow is imported from elsewhere."],"tags":["vae","model-type","typeerror","z-image","decode"],"backgroundTag":"incompatible-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}