invoke-ai/InvokeAI · error · TypeError

Expected Main_Checkpoint_QwenImage_Config, got {type(config)

Error message

Expected Main_Checkpoint_QwenImage_Config, got {type(config).__name__}.

What it means

The safetensors single-file loader path expects Main_Checkpoint_QwenImage_Config specifically. A GGUF config or any other config type reaching this _load_from_singlefile raises this TypeError naming the actual received type, because safetensors load_file() cannot read GGUF files.

Source

Thrown at invokeai/backend/model_manager/load/model_loaders/qwen_image.py:258

        match submodel_type:
            case SubModelType.Transformer:
                model = self._load_from_singlefile(config)
                return self._apply_fp8_layerwise_casting(model, config, submodel_type)

        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 QwenImageTransformer2DModel
        from safetensors.torch import load_file

        from invokeai.backend.util.logging import InvokeAILogger

        logger = InvokeAILogger.get_logger(self.__class__.__name__)

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

        target_device = TorchDevice.choose_torch_device()
        model_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)

        sd = load_file(str(model_path))
        sd = _strip_comfyui_prefix(sd)

        dequantized = _dequantize_comfyui_fp8(sd, model_dtype)
        if dequantized > 0:
            logger.info(f"Dequantized {dequantized} ComfyUI-quantized weights")
        _strip_quantization_metadata(sd)

        is_edit = getattr(config, "variant", None) == QwenImageVariantType.Edit
        model_config = _build_qwen_image_transformer_config(sd, is_edit=is_edit)

        with accelerate.init_empty_weights():
            model = QwenImageTransformer2DModel(**model_config)

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Register the model with ModelFormat.GGUFQuantized so it gets Main_GGUF_QwenImage_Config and the GGUF loader.
  2. Convert the GGUF file to safetensors if you intend to use the safetensors path.
  3. Re-scan the models directory so format detection runs again on the file.

Example fix

// before
config = Main_GGUF_QwenImage_Config(path="model.gguf")
model = safetensors_loader._load_from_singlefile(config)
// after
config = Main_Checkpoint_QwenImage_Config(path="model.safetensors")
model = safetensors_loader._load_from_singlefile(config)
Defensive patterns

Strategy: type-guard

Validate before calling

from invokeai.backend.model_manager.config import Main_Checkpoint_QwenImage_Config
if not isinstance(config, Main_Checkpoint_QwenImage_Config):
    raise TypeError(f"Safetensors loader needs Main_Checkpoint_QwenImage_Config, got {type(config).__name__}")
if not str(config.path).endswith((".safetensors", ".ckpt")):
    raise ValueError("Path does not look like a single-file checkpoint")

Type guard

def is_safetensors_qwen_config(config: AnyModelConfig) -> bool:
    return isinstance(config, Main_Checkpoint_QwenImage_Config)

Try / catch

try:
    model = loader._load_from_singlefile(config)
except TypeError as e:
    if "Main_Checkpoint_QwenImage_Config" in str(e):
        config = reregister_model(path, ModelFormat.Checkpoint)
        model = loader._load_from_singlefile(config)
    else:
        raise

Prevention

When it happens

Trigger: A GGUF-quantized Qwen Image model registered with the plain checkpoint format, routed into this loader's single-file path.

Common situations: Model format misdetection during import; user manually editing model records; older InvokeAI versions predating GGUF Qwen Image support where GGUF files fell into the safetensors path.

Related errors


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