{"record":{"id":"7ffb1a0f671440f3","repo":"invoke-ai/InvokeAI","slug":"state-dict-looks-like-a-t5-encoder-has-enc-blk","errorCode":null,"errorMessage":"state dict looks like a T5 encoder (has 'enc.blk.*' keys), not a Qwen3 encoder","messagePattern":"state dict looks like a T5 encoder \\(has 'enc\\.blk\\.\\*' keys\\), not a Qwen3 encoder","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"info","filePath":"invokeai/backend/model_manager/configs/qwen3_encoder.py","lineNumber":237,"sourceCode":"\n        We previously defaulted to 4B for unknown sizes, but that swallowed other causal-LM GGUFs\n        (Mistral, Llama, ...) which share llama.cpp tensor naming with Qwen3.\n        \"\"\"\n        state_dict = mod.load_state_dict()\n        variant = _get_qwen3_variant_from_state_dict(state_dict)\n        if variant is None:\n            raise NotAMatchError(\"hidden size does not match a known Qwen3 variant\")\n        return variant\n\n    @classmethod\n    def _validate_looks_like_qwen3_model(cls, mod: ModelOnDisk) -> None:\n        state_dict = mod.load_state_dict()\n        if not _has_qwen3_keys(state_dict):\n            raise NotAMatchError(\"state dict does not look like a Qwen3 model\")\n        # Reject T5 encoders: they share the token_embd.weight key with Qwen3 GGUFs but use the ``enc.``\n        # block prefix, and must be classified as T5Encoder (Qwen3 encoders never have ``enc.blk.*`` keys).\n        if _has_t5_encoder_keys(state_dict):\n            raise NotAMatchError(\"state dict looks like a T5 encoder (has 'enc.blk.*' keys), not a Qwen3 encoder\")\n        # Reject Gemma-2/3 encoders: their GGUFs also carry token_embd.weight + blk.* keys but use\n        # post-attention / post-feedforward norms a Qwen3 encoder never has; they must be classified as\n        # Gemma2Encoder (otherwise a Gemma GGUF matches both configs and can be re-identified wrongly).\n        if _has_gemma2_keys(state_dict):\n            raise NotAMatchError(\n                \"state dict looks like a Gemma-2 encoder (has post_attention_norm/post_ffw_norm keys), \"\n                \"not a Qwen3 encoder\"\n            )\n        # Reject Qwen2.5-VL / Qwen2-VL encoders: they carry a visual tower and must be\n        # classified as QwenVLEncoder (text-only Qwen3 encoders never have one).\n        if _has_qwen_vl_visual_tower(state_dict):\n            raise NotAMatchError(\n                \"state dict bundles a Qwen-VL visual tower; this is a Qwen-VL encoder, not a text-only Qwen3 encoder\"\n            )\n\n    @classmethod\n    def _validate_does_not_look_like_gguf_quantized(cls, mod: ModelOnDisk) -> None:\n        has_ggml = _has_ggml_tensors(mod.load_state_dict())","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/qwen3_encoder.py#L219-L255","documentation":"NotAMatchError raised by Qwen3Encoder._validate_looks_like_qwen3_model (qwen3_encoder.py:237). The state dict matches Qwen3's shared keys (token_embd.weight) but also carries 'enc.blk.*' keys, which identify a T5 encoder. Qwen3 encoders never use the enc. prefix, so this config rejects the model so it can be classified as T5Encoder instead.","triggerScenarios":"from_model_on_disk identification of a GGUF whose tensors include enc.blk.* (a T5-family text encoder GGUF) while the Qwen3Encoder config heuristic runs.","commonSituations":"Installing a T5 / FLUX T5-Encoder / UM-T5 GGUF converted with llama.cpp; older T5 GGUFs that predate dedicated T5Encoder config matching; re-identifying a previously mislabeled model so the Qwen3 config probes it first.","solutions":["Nothing is wrong with the file per se — let the scan continue; InvokeAI should classify it as T5Encoder automatically.","If it is misclassified afterward, install it explicitly as a T5Encoder/CLIPEmbedder-style model rather than Qwen3Encoder.","Confirm the GGUF is genuinely T5; if it was converted wrongly from a Qwen3 model, re-convert with a current converter so keys use blk.* without enc.*.","Exclude the T5 encoder from the directory being scanned as a Qwen3 encoder."],"exampleFix":"// before\ninstall(models/, 't5-encoder.gguf')  # scanned as Qwen3Encoder candidate\n// after\ninstall_as(models/, 't5-encoder.gguf', model_type='T5Encoder')","handlingStrategy":"validation","validationCode":"def is_t5_gguf(state_dict: dict) -> bool:\n    return any(k.startswith('enc.blk.') for k in state_dict)  # if True, install as T5Encoder, not Qwen3Encoder","typeGuard":"def is_qwen3_not_t5(state_dict: dict) -> bool:\n    keys = set(state_dict)\n    return ('token_embd.weight' in keys or any(k.startswith('blk.') for k in keys)) and not any(k.startswith('enc.blk.') for k in keys)","tryCatchPattern":"try:\n    register_model(path, model_type='Qwen3Encoder')\nexcept NotAMatchError:\n    register_model(path, model_type='T5Encoder')","preventionTips":["Inspect gguf tensor key prefixes (enc.* means T5) before choosing a model type.","Install T5-family encoders explicitly as T5Encoder models.","Use current converters so tensor naming matches the intended architecture."],"tags":["model-identification","gguf","t5","qwen3"],"backgroundTag":"model-not-a-match","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}