{"record":{"id":"bff1465fe913b75e","repo":"Comfy-Org/ComfyUI","slug":"error-vae-is-invalid-none-n-nif-the-vae-is-from","errorCode":null,"errorMessage":"ERROR: VAE is invalid: None\\n\\nIf the VAE is from a checkpoint loader node your checkpoint does not contain a valid VAE.","messagePattern":"ERROR: VAE is invalid: None\\\\n\\\\nIf the VAE is from a checkpoint loader node your checkpoint does not contain a valid VAE\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"comfy/sd.py","lineNumber":1085,"sourceCode":"        m, u = self.first_stage_model.load_state_dict(sd, strict=False, assign=self.patcher.is_dynamic())\n        if len(m) > 0:\n            logging.warning(\"Missing VAE keys {}\".format(m))\n\n        if len(u) > 0:\n            logging.debug(\"Leftover VAE keys {}\".format(u))\n\n        logging.info(\"VAE load device: {}, offload device: {}, dtype: {}\".format(self.device, offload_device, self.vae_dtype))\n        self.model_size()\n\n    def model_size(self):\n        if self.size is not None:\n            return self.size\n        self.size = comfy.model_management.module_size(self.first_stage_model)\n        return self.size\n\n    def throw_exception_if_invalid(self):\n        if self.first_stage_model is None:\n            raise RuntimeError(\"ERROR: VAE is invalid: None\\n\\nIf the VAE is from a checkpoint loader node your checkpoint does not contain a valid VAE.\")\n\n    def vae_encode_crop_pixels(self, pixels):\n        if self.crop_input:\n            downscale_ratio = self.spacial_compression_encode()\n\n            dims = pixels.shape[1:-1]\n            for d in range(len(dims)):\n                x = (dims[d] // downscale_ratio) * downscale_ratio\n                x_offset = (dims[d] % downscale_ratio) // 2\n                if x != dims[d]:\n                    pixels = pixels.narrow(d + 1, x_offset, x)\n\n        if pixels.shape[-1] > self.output_channels:\n            pixels = pixels[..., :self.output_channels]\n        elif pixels.shape[-1] < self.output_channels:\n            if self.pad_channel_value is not None:\n                if isinstance(self.pad_channel_value, str):\n                    mode = self.pad_channel_value","sourceCodeStart":1067,"sourceCodeEnd":1103,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/sd.py#L1067-L1103","documentation":"VAE.throw_exception_if_invalid raises when first_stage_model is None, which happens when VAE.__init__ found no recognizable VAE weights in the state dict (it logs 'No VAE weights detected' and returns with first_stage_model = None) or an explicit VAE=None was passed from a checkpoint loader. Any later encode/decode call first validates through this method, so the user gets a clear message instead of an AttributeError.","triggerScenarios":"Loading a checkpoint whose state dict contains no VAE keys (diffusion-model-only files, UNET-only safetensors, CLIP+model without VAE); passing a None VAE from CheckpointLoaderSimple into VAEDecode/VAEEncode; loading a Diffusers-format model split that excludes the VAE.","commonSituations":"Using unet-only or 'diffusion model' checkpoints in a workflow that still has VAEDecode wired; LoRA/pruned checkpoints where the VAE was stripped to save space; forgetting to add a separate VAELoader node.","solutions":["Add a VAELoader node and point it at a standalone VAE file (e.g. sd_xl_vae.safetensors, vae-ft-mse-840000.safetensors) and connect it to the decode node.","Use a full checkpoint that includes VAE weights instead of the pruned/unet-only file.","Check the console for 'No VAE weights detected' to confirm the checkpoint lacks VAE keys."],"exampleFix":"# before\n# workflow: CheckpointLoaderSimple('flux-unet-only.safetensors') -> VAEDecode -> RuntimeError\n\n# after\n# CheckpointLoaderSimple('flux-unet-only.safetensors').MODEL/CLIP -> ...\n# VAELoader('ae.safetensors').VAE -> VAEDecode.vae","handlingStrategy":"validation","validationCode":"vae.throw_exception_if_invalid()  # cheap explicit check\n# or: assert vae.first_stage_model is not None","typeGuard":"def vae_is_valid(vae) -> bool:\n    return getattr(vae, 'first_stage_model', None) is not None","tryCatchPattern":"try:\n    vae.throw_exception_if_invalid()\nexcept RuntimeError as e:\n    if 'VAE is invalid' in str(e):\n        raise SystemExit('Checkpoint has no VAE; connect a VAELoader with a standalone VAE file.')\n    raise","preventionTips":["For unet-only or pruned checkpoints, always add a VAELoader node with a standalone VAE file.","Watch for the 'No VAE weights detected' console warning at load time as an early signal."],"tags":["vae","checkpoint-loading","workflow","missing-weights"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}