{"record":{"id":"e830fcf3cf61e30b","repo":"invoke-ai/InvokeAI","slug":"architecture-gemma2forcausallm-2304-dim-gemma-2","errorCode":null,"errorMessage":"architecture 'Gemma2ForCausalLM' (2304-dim Gemma-2-2b) is handled by the PiD encoder config, not TextLLM","messagePattern":"architecture 'Gemma2ForCausalLM' \\(2304-dim Gemma-2-2b\\) is handled by the PiD encoder config, not TextLLM","errorType":"validation","errorClass":"NotAMatchError","httpStatus":null,"severity":"info","filePath":"invokeai/backend/model_manager/configs/text_llm.py","lineNumber":61,"sourceCode":"        # This covers LlamaForCausalLM, PhiForCausalLM, Phi3ForCausalLM, Qwen2ForCausalLM,\n        # MistralForCausalLM, GemmaForCausalLM, GPTNeoXForCausalLM, etc.\n        config_dict = get_config_dict_or_raise(common_config_paths(mod.path))\n        class_name = get_class_name_from_config_dict_or_raise(config_dict)\n        if not class_name.endswith(\"ForCausalLM\"):\n            raise NotAMatchError(f\"model architecture '{class_name}' is not a causal language model\")\n\n        # During *automatic* classification, defer to the dedicated PiD Gemma2 encoder config — but only\n        # for the hidden size that config actually accepts (2304 = Gemma-2-2b). Larger Gemma 2 variants\n        # (9B=3584, 27B=4608) are rejected by the encoder config, so they must remain classifiable as a\n        # generic TextLLM here rather than falling through to Unknown. An explicit `type=text_llm` request\n        # always keeps the model as TextLLM (the generic AutoModelForCausalLM loader supports these).\n        explicitly_requested_text_llm = override_fields.get(\"type\") == ModelType.TextLLM\n        if (\n            not explicitly_requested_text_llm\n            and class_name == \"Gemma2ForCausalLM\"\n            and config_dict.get(\"hidden_size\") == _GEMMA2_2B_HIDDEN_SIZE\n        ):\n            raise NotAMatchError(\n                \"architecture 'Gemma2ForCausalLM' (2304-dim Gemma-2-2b) is handled by the PiD encoder config, not TextLLM\"\n            )\n\n        # Verify tokenizer files exist to avoid runtime failures\n        tokenizer_files = {\"tokenizer.json\", \"tokenizer.model\", \"tokenizer_config.json\"}\n        if not any((mod.path / f).exists() for f in tokenizer_files):\n            raise NotAMatchError(\n                f\"no tokenizer files found in '{mod.path}' \"\n                f\"(expected at least one of: {', '.join(sorted(tokenizer_files))})\"\n            )\n\n        return cls(**override_fields)\n","sourceCodeStart":43,"sourceCodeEnd":74,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/text_llm.py#L43-L74","documentation":"NotAMatchError from TextLLM from_model_on_disk that deliberately defers Gemma-2-2b to InvokeAI's dedicated PiD Gemma2 encoder config. During automatic classification, a Gemma2ForCausalLM with hidden_size 2304 is rejected here so the PiD encoder config claims it; larger Gemma 2 variants (9B=3584, 27B=4608) remain TextLLM. An explicit type=text_llm request bypasses this rejection.","triggerScenarios":"Automatic model classification of a Gemma2ForCausalLM config.json with hidden_size==2304 (Gemma-2-2b) and no explicit override_fields['type']==ModelType.TextLLM — i.e. a plain folder scan, not a user-initiated 'add as text_llm'.","commonSituations":"Scanning a downloaded Gemma-2-2b repo that InvokeAI intends to use as the PiD (prompt-injection-defense) encoder; users confused why Gemma-2-2b won't register as a generic chat LLM via auto-scan.","solutions":["If you want it as a generic chat LLM, add it explicitly with type=text_llm (the AutoModelForCausalLM loader supports it)","Let the PiD encoder config claim it if it is intended for the prompt-injection-defense feature","Use a larger Gemma 2 variant (9B/27B) if you need an automatically-classified generic TextLLM"],"exampleFix":"// before\n# auto-scan of gemma-2-2b folder -> rejected\n// after\n# explicit registration\ninvokeai-model-install --source gemma-2-2b --type text_llm","handlingStrategy":"validation","validationCode":"import json\ndef is_gemma2_2b(model_dir) -> bool:\n    cfg = json.loads((model_dir / \"config.json\").read_text())\n    return (cfg.get(\"architectures\", [None])[0] == \"Gemma2ForCausalLM\"\n            and cfg.get(\"hidden_size\") == 2304)","typeGuard":null,"tryCatchPattern":"try:\n    auto_install(path)\nexcept NotAMatchError as e:\n    if \"PiD encoder config\" in str(e):\n        # Gemma-2-2b is reserved for the PiD encoder; pass explicit type if a chat LLM is wanted\n        install_model(path, type=\"text_llm\")","preventionTips":["Remember Gemma-2-2b (hidden_size 2304) auto-classifies as the PiD encoder","Pass type=text_llm explicitly to override the PiD deferral","Use Gemma-2-9B/27B for generic TextLLM auto-classification"],"tags":["gemma2","text-llm","model-identification"],"backgroundTag":"unsupported-model-architecture","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}