invoke-ai/InvokeAI · error · TypeError

Expected Main_GGUF_ZImage_Config, got {type(config).__name__

Error message

Expected Main_GGUF_ZImage_Config, got {type(config).__name__}. Model configuration type mismatch.

What it means

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.

Source

Thrown at invokeai/backend/model_manager/load/model_loaders/z_image.py:520

        if not isinstance(config, Checkpoint_Config_Base):
            raise ValueError("Only CheckpointConfigBase models are currently supported here.")

        match submodel_type:
            case SubModelType.Transformer:
                return self._load_from_singlefile(config)

        raise ValueError(
            f"Only Transformer submodels are currently supported. Received: {submodel_type.value if submodel_type else 'None'}"
        )

    def _load_from_singlefile(
        self,
        config: AnyModelConfig,
    ) -> AnyModel:
        from diffusers import ZImageTransformer2DModel

        if not isinstance(config, Main_GGUF_ZImage_Config):
            raise TypeError(
                f"Expected Main_GGUF_ZImage_Config, got {type(config).__name__}. Model configuration type mismatch."
            )
        model_path = Path(config.path)

        # Determine safe dtype based on target device capabilities
        target_device = TorchDevice.choose_torch_device()
        compute_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)

        # Load the GGUF state dict
        sd = gguf_sd_loader(model_path, compute_dtype=compute_dtype)

        # Some Z-Image GGUF models have keys prefixed with "diffusion_model." or
        # "model.diffusion_model." (ComfyUI-style format). Check if we need to strip this prefix.
        prefix_to_strip = None
        for prefix in ["model.diffusion_model.", "diffusion_model."]:
            if any(k.startswith(prefix) for k in sd.keys() if isinstance(k, str)):
                prefix_to_strip = prefix
                break

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Correct the model's registered format so GGUF models use Main_GGUF_ZImage_Config and checkpoint models use Main_Checkpoint_ZImage_Config.
  2. Re-scan/re-import the model in the model manager so the right loader is selected for the file.
  3. If the file is a regular checkpoint, load it via the checkpoint loader instead of the GGUF loader.
  4. In custom code, assert isinstance(config, Main_GGUF_ZImage_Config) before invoking this loader.

Example fix

// before
config = Main_Checkpoint_ZImage_Config(path=f)
model = gguf_loader._load_model(config, SubModelType.Transformer)  # TypeError
// after
config = Main_GGUF_ZImage_Config(path=f)  # f is the .gguf file
model = gguf_loader._load_model(config, SubModelType.Transformer)
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(config, Main_GGUF_ZImage_Config):
    raise TypeError(f"GGUF loader requires Main_GGUF_ZImage_Config, got {type(config).__name__}")

Type guard

def is_zimage_gguf_config(config: AnyModelConfig) -> bool:
    return isinstance(config, Main_GGUF_ZImage_Config)

Try / catch

try:
    model = gguf_loader._load_model(config, SubModelType.Transformer)
except TypeError as e:
    if "Main_GGUF_ZImage_Config" in str(e):
        config = reclassify_as_gguf(config.path)  # file is actually .gguf
        model = gguf_loader._load_model(config, SubModelType.Transformer)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/ca15cf5d17309553. Report an issue: GitHub.