invoke-ai/InvokeAI · error · TypeError

Expected Qwen3Encoder_Checkpoint_Config, got {type(config)._

Error message

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

What it means

_load_from_singlefile re-validates the config with a strict isinstance check against Qwen3Encoder_Checkpoint_Config and raises TypeError naming the actual received type if it fails. This is a defense-in-depth check: the dispatching _load_model already guards, so hitting this means the loader was invoked through an unusual path or the config type changed between checks.

Source

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

        tokenizer is identical across the 0.6B / 4B / 8B variants, so we load the
        self-contained copy vendored in the package — fully offline, no HuggingFace
        download required.
        """
        return load_bundled_qwen3_tokenizer()

    def _load_from_singlefile(
        self,
        config: AnyModelConfig,
    ) -> AnyModel:
        from safetensors.torch import load_file
        from transformers import Qwen3Config, Qwen3ForCausalLM

        from invokeai.backend.util.logging import InvokeAILogger

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

        if not isinstance(config, Qwen3Encoder_Checkpoint_Config):
            raise TypeError(
                f"Expected Qwen3Encoder_Checkpoint_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()
        model_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)

        # Load the state dict from safetensors file
        sd = load_file(model_path)

        # Handle ComfyUI quantized checkpoints
        # ComfyUI stores quantized weights with accompanying scale factors:
        # - layer.weight: quantized data (FP8)
        # - layer.weight_scale: scale factor (FP32 scalar)
        # Dequantization formula: dequantized = weight.to(dtype) * weight_scale
        # Reference: https://github.com/Comfy-Org/ComfyUI/blob/master/QUANTIZATION.md

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Pass a genuine Qwen3Encoder_Checkpoint_Config instance (read the printed type name in the message to see what you actually passed).
  2. Re-create the model record via the model manager so the correct config class is instantiated.
  3. If calling internals directly, build the config via the same factory the registry uses.
  4. Upgrade/downgrade consistently — do not mix config definitions from different InvokeAI versions.

Example fix

// before
self._load_from_singlefile(config_dict)
// after
from invokeai.backend.model_manager.load.model_loaders.z_image import Qwen3Encoder_Checkpoint_Config
config = Qwen3Encoder_Checkpoint_Config(**config_dict)
self._load_from_singlefile(config)
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(config, Qwen3Encoder_Checkpoint_Config):
    raise TypeError(f"Cannot single-file load with {type(config).__name__}")

Type guard

def is_qwen3_ckpt(c: AnyModelConfig) -> bool:
    return isinstance(c, Qwen3Encoder_Checkpoint_Config)

Try / catch

try:
    model = loader._load_from_singlefile(config)
except TypeError as e:
    if "Expected Qwen3Encoder_Checkpoint_Config" in str(e):
        config = Qwen3Encoder_Checkpoint_Config(**vars(config))
        model = loader._load_from_singlefile(config)
    else:
        raise

Prevention

When it happens

Trigger: Calling _load_from_singlefile directly with a non-Qwen3Encoder_Checkpoint_Config object; a custom subclass or wrapper passes a duck-typed config that fails the exact isinstance check; internal refactors bypass the _load_model guard.

Common situations: Scripting the loader internals instead of using the model manager; config objects deserialized from cache/DB losing their concrete class; mixing config classes across InvokeAI versions after an upgrade.

Related errors


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