{"record":{"id":"7f956ca38092e859","repo":"invoke-ai/InvokeAI","slug":"expected-main-checkpoint-zimage-config-got-type","errorCode":null,"errorMessage":"Expected Main_Checkpoint_ZImage_Config, got {type(config).__name__}. Model configuration type mismatch.","messagePattern":"Expected Main_Checkpoint_ZImage_Config, got (.+?)\\. Model configuration type mismatch\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/load/model_loaders/z_image.py","lineNumber":392,"sourceCode":"            raise ValueError(\"Only CheckpointConfigBase models are currently supported here.\")\n\n        match submodel_type:\n            case SubModelType.Transformer:\n                return self._load_from_singlefile(config)\n\n        raise ValueError(\n            f\"Only Transformer submodels are currently supported. Received: {submodel_type.value if submodel_type else 'None'}\"\n        )\n\n    def _load_from_singlefile(\n        self,\n        config: AnyModelConfig,\n    ) -> AnyModel:\n        from diffusers import ZImageTransformer2DModel\n        from safetensors.torch import load_file\n\n        if not isinstance(config, Main_Checkpoint_ZImage_Config):\n            raise TypeError(\n                f\"Expected Main_Checkpoint_ZImage_Config, got {type(config).__name__}. \"\n                \"Model configuration type mismatch.\"\n            )\n        model_path = Path(config.path)\n\n        # Load the state dict from safetensors/checkpoint file\n        sd = load_file(model_path)\n\n        # Some Z-Image checkpoint files have keys prefixed with \"diffusion_model.\" or\n        # \"model.diffusion_model.\" (ComfyUI-style format). Check if we need to strip this prefix.\n        prefix_to_strip = None\n        for prefix in [\"model.diffusion_model.\", \"diffusion_model.\"]:\n            if any(k.startswith(prefix) for k in sd.keys() if isinstance(k, str)):\n                prefix_to_strip = prefix\n                break\n\n        if prefix_to_strip:\n            stripped_sd = {}","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/load/model_loaders/z_image.py#L374-L410","documentation":"_load_from_singlefile in the Z-Image single-file loader only accepts Main_Checkpoint_ZImage_Config model configs. Before loading the safetensors checkpoint it asserts the config type with isinstance and throws TypeError if any other config class is passed. This guards against the wrong loader being dispatched for a model, e.g. a GGUF or diffusers-folder config routed to the checkpoint path.","triggerScenarios":"Calling _load_model on the single-file Z-Image loader with a config that is not Main_Checkpoint_ZImage_Config — e.g. a Main_GGUF_ZImage_Config, Main_SDNQ_*_Config, or diffusers-folder config — so the isinstance check at z_image.py:392 fails and TypeError is raised.","commonSituations":"Selecting a GGUF or SDNQ quantized Z-Image checkpoint but the model manager resolves it to the checkpoint-loader class; registering a model with the wrong config type in the model record; a custom installer script instantiating the loader directly with a generic Checkpoint_Config_Base.","solutions":["Re-register/re-convert the model so its config type is Main_Checkpoint_ZImage_Config (checkpoint/safetensors single-file format).","Check the model entry in the InvokeAI model manager UI/API and fix its 'format'/'config' so it matches the actual file type (GGUF vs checkpoint).","If loading a GGUF or SDNQ model, ensure the matching loader class (GGUF or SDNQ loader) handles it, not the checkpoint loader.","Verify no custom code calls ZimageCheckpointLoader._load_model directly with a foreign config."],"exampleFix":"// before\nconfig = Main_GGUF_ZImage_Config(path=model_file)\nmodel = checkpoint_loader._load_model(config, SubModelType.Transformer)\n// after\nif isinstance(model_file, str) and model_file.endswith('.gguf'):\n    config = Main_GGUF_ZImage_Config(path=model_file)\n    model = gguf_loader._load_model(config, SubModelType.Transformer)\nelse:\n    config = Main_Checkpoint_ZImage_Config(path=model_file)\n    model = checkpoint_loader._load_model(config, SubModelType.Transformer)","handlingStrategy":"type-guard","validationCode":"from invokeai.backend.model_manager.load.model_loaders.z_image import Main_Checkpoint_ZImage_Config\nif not isinstance(config, Main_Checkpoint_ZImage_Config):\n    raise TypeError(f\"checkpoint loader requires Main_Checkpoint_ZImage_Config, got {type(config).__name__}\")","typeGuard":"def is_zimage_checkpoint_config(config: AnyModelConfig) -> bool:\n    return isinstance(config, Main_Checkpoint_ZImage_Config)","tryCatchPattern":"try:\n    model = loader._load_model(config, SubModelType.Transformer)\nexcept TypeError as e:\n    if \"Main_Checkpoint_ZImage_Config\" in str(e):\n        config = reclassify_config(config_path)  # fix model record, then retry\n        model = loader._load_model(config, SubModelType.Transformer)\n    else:\n        raise","preventionTips":["Register each model file with the config class matching its on-disk format (safetensors checkpoint vs GGUF vs SDNQ).","Assert the config type before calling loader internals directly.","Keep model-manager records re-scanned after moving/converting model files."],"tags":["python","model-loading","type-mismatch","invokeai"],"backgroundTag":"model-config-type-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}