invoke-ai/InvokeAI · warning · NotAMatchError

hidden size does not match a known Qwen3 variant

Error message

hidden size does not match a known Qwen3 variant

What it means

For Qwen3 text-encoder GGUF files, InvokeAI infers the variant (e.g. 0.6B/1.7B/4B/8B) from the hidden size of the embedding tensor. If the state dict's hidden size matches no known Qwen3 variant, `NotAMatchError` is raised — deliberately, because defaulting to 4B caused unrelated causal-LM GGUFs (Mistral, Llama) sharing llama.cpp naming to be misidentified as Qwen3.

Source

Thrown at invokeai/backend/model_manager/configs/qwen3_encoder.py:226

        cls._validate_does_not_look_like_gguf_quantized(mod)

        # Determine variant from state dict
        variant = cls._get_variant_or_default(mod)

        return cls(variant=variant, **override_fields)

    @classmethod
    def _get_variant_or_default(cls, mod: ModelOnDisk) -> Qwen3VariantType:
        """Get the variant from state dict, raising NotAMatch when the size does not match a known Qwen3 variant.

        We previously defaulted to 4B for unknown sizes, but that swallowed other causal-LM GGUFs
        (Mistral, Llama, ...) which share llama.cpp tensor naming with Qwen3.
        """
        state_dict = mod.load_state_dict()
        variant = _get_qwen3_variant_from_state_dict(state_dict)
        if variant is None:
            raise NotAMatchError("hidden size does not match a known Qwen3 variant")
        return variant

    @classmethod
    def _validate_looks_like_qwen3_model(cls, mod: ModelOnDisk) -> None:
        state_dict = mod.load_state_dict()
        if not _has_qwen3_keys(state_dict):
            raise NotAMatchError("state dict does not look like a Qwen3 model")
        # Reject T5 encoders: they share the token_embd.weight key with Qwen3 GGUFs but use the ``enc.``
        # block prefix, and must be classified as T5Encoder (Qwen3 encoders never have ``enc.blk.*`` keys).
        if _has_t5_encoder_keys(state_dict):
            raise NotAMatchError("state dict looks like a T5 encoder (has 'enc.blk.*' keys), not a Qwen3 encoder")
        # Reject Gemma-2/3 encoders: their GGUFs also carry token_embd.weight + blk.* keys but use
        # post-attention / post-feedforward norms a Qwen3 encoder never has; they must be classified as
        # Gemma2Encoder (otherwise a Gemma GGUF matches both configs and can be re-identified wrongly).
        if _has_gemma2_keys(state_dict):
            raise NotAMatchError(
                "state dict looks like a Gemma-2 encoder (has post_attention_norm/post_ffw_norm keys), "
                "not a Qwen3 encoder"

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Confirm the GGUF is actually a Qwen3 model; if it is Mistral/Llama, it is not a Qwen3 encoder and will not match — install it as the correct model type
  2. Re-download an official Qwen3 GGUF release whose hidden size matches a known variant
  3. Check the file isn't corrupted or partially converted; re-quantize/convert from the original safetensors
  4. Upgrade InvokeAI in case newer Qwen3 variants were added to the recognized-size table

Example fix

// before: mistral-7b.Q4_K_M.gguf offered to qwen3 encoder config -> NotAMatchError
// after: use the correct model type/source for Mistral GGUFs;
// or verify Qwen3:
# hidden size from gguf metadata should match a known Qwen3 variant
Defensive patterns

Strategy: try-catch

Validate before calling

# read gguf hidden size before install
import gguf
r = gguf.GGUFReader(path)
hidden = r.get_tensor('token_embd.weight').shape[-1]
KNOWN_QWEN3_HIDDEN = {1024, 2048, 2560, 4096, 5120}  # variant-dependent
if hidden not in KNOWN_QWEN3_HIDDEN:
    raise SystemExit('Hidden size does not match a known Qwen3 variant; not a Qwen3 GGUF.')

Type guard

def is_qwen3_sized_gguf(hidden_size: int) -> bool:
    return hidden_size in {1024, 2048, 2560, 4096, 5120}

Try / catch

try:
    install_model(path)
except NotAMatchError as e:
    if 'known Qwen3 variant' in str(e):
        logger.error('Not a recognizable Qwen3 GGUF (may be Mistral/Llama): %s', e)
    else:
        raise

Prevention

When it happens

Trigger: `_get_variant_or_default` in `from_model_on_disk` calls `_get_qwen3_variant_from_state_dict`, which returns None because the tensor hidden dimension isn't any Qwen3 size — commonly for non-Qwen3 GGUF LLMs or quantization layouts that change dims.

Common situations: Installing a Mistral/Llama GGUF that the router offered to the Qwen3 encoder config; an unusual Qwen3 fine-tune with modified hidden size; mislabeled GGUF file.

Related errors


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