{"record":{"id":"ca15cf5d17309553","repo":"invoke-ai/InvokeAI","slug":"expected-main-gguf-zimage-config-got-type-config","errorCode":null,"errorMessage":"Expected Main_GGUF_ZImage_Config, got {type(config).__name__}. Model configuration type mismatch.","messagePattern":"Expected Main_GGUF_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":520,"sourceCode":"        if not isinstance(config, Checkpoint_Config_Base):\n            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\n        if not isinstance(config, Main_GGUF_ZImage_Config):\n            raise TypeError(\n                f\"Expected Main_GGUF_ZImage_Config, got {type(config).__name__}. Model configuration type mismatch.\"\n            )\n        model_path = Path(config.path)\n\n        # Determine safe dtype based on target device capabilities\n        target_device = TorchDevice.choose_torch_device()\n        compute_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)\n\n        # Load the GGUF state dict\n        sd = gguf_sd_loader(model_path, compute_dtype=compute_dtype)\n\n        # Some Z-Image GGUF models 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","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/load/model_loaders/z_image.py#L502-L538","documentation":"The GGUF Z-Image loader's _load_from_singlefile requires the config to be exactly Main_GGUF_ZImage_Config. It checks isinstance before loading the GGUF weights (also choosing a safe dtype for the target device) and raises TypeError naming the actual config class otherwise. This prevents GGUF-specific weight loading from running against non-GGUF configs.","triggerScenarios":"Routing a non-GGUF config (e.g. Main_Checkpoint_ZImage_Config, Main_SDNQ_ZImage_Config, or a diffusers-folder config) into the GGUF Z-Image loader so the isinstance check at z_image.py:520 fails.","commonSituations":"The model file is actually a safetensors checkpoint but was registered as GGUF (or vice versa) so the wrong loader is matched; duplicate model entries with conflicting format metadata; custom scripts constructing the loader directly with the wrong config class.","solutions":["Correct the model's registered format so GGUF models use Main_GGUF_ZImage_Config and checkpoint models use Main_Checkpoint_ZImage_Config.","Re-scan/re-import the model in the model manager so the right loader is selected for the file.","If the file is a regular checkpoint, load it via the checkpoint loader instead of the GGUF loader.","In custom code, assert isinstance(config, Main_GGUF_ZImage_Config) before invoking this loader."],"exampleFix":"// before\nconfig = Main_Checkpoint_ZImage_Config(path=f)\nmodel = gguf_loader._load_model(config, SubModelType.Transformer)  # TypeError\n// after\nconfig = Main_GGUF_ZImage_Config(path=f)  # f is the .gguf file\nmodel = gguf_loader._load_model(config, SubModelType.Transformer)","handlingStrategy":"type-guard","validationCode":"if not isinstance(config, Main_GGUF_ZImage_Config):\n    raise TypeError(f\"GGUF loader requires Main_GGUF_ZImage_Config, got {type(config).__name__}\")","typeGuard":"def is_zimage_gguf_config(config: AnyModelConfig) -> bool:\n    return isinstance(config, Main_GGUF_ZImage_Config)","tryCatchPattern":"try:\n    model = gguf_loader._load_model(config, SubModelType.Transformer)\nexcept TypeError as e:\n    if \"Main_GGUF_ZImage_Config\" in str(e):\n        config = reclassify_as_gguf(config.path)  # file is actually .gguf\n        model = gguf_loader._load_model(config, SubModelType.Transformer)\n    else:\n        raise","preventionTips":["Confirm the file extension/content (.gguf) matches the registered GGUF config before loading.","Re-scan model directories after adding quantized files.","Avoid editing model record format fields by hand."],"tags":["python","gguf","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"}