invoke-ai/InvokeAI · info · NotAMatchError
architecture 'Gemma2ForCausalLM' (2304-dim Gemma-2-2b) is ha
Error message
architecture 'Gemma2ForCausalLM' (2304-dim Gemma-2-2b) is handled by the PiD encoder config, not TextLLM
What it means
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.
Source
Thrown at invokeai/backend/model_manager/configs/text_llm.py:61
# This covers LlamaForCausalLM, PhiForCausalLM, Phi3ForCausalLM, Qwen2ForCausalLM,
# MistralForCausalLM, GemmaForCausalLM, GPTNeoXForCausalLM, etc.
config_dict = get_config_dict_or_raise(common_config_paths(mod.path))
class_name = get_class_name_from_config_dict_or_raise(config_dict)
if not class_name.endswith("ForCausalLM"):
raise NotAMatchError(f"model architecture '{class_name}' is not a causal language model")
# During *automatic* classification, defer to the dedicated PiD Gemma2 encoder config — but only
# for the hidden size that config actually accepts (2304 = Gemma-2-2b). Larger Gemma 2 variants
# (9B=3584, 27B=4608) are rejected by the encoder config, so they must remain classifiable as a
# generic TextLLM here rather than falling through to Unknown. An explicit `type=text_llm` request
# always keeps the model as TextLLM (the generic AutoModelForCausalLM loader supports these).
explicitly_requested_text_llm = override_fields.get("type") == ModelType.TextLLM
if (
not explicitly_requested_text_llm
and class_name == "Gemma2ForCausalLM"
and config_dict.get("hidden_size") == _GEMMA2_2B_HIDDEN_SIZE
):
raise NotAMatchError(
"architecture 'Gemma2ForCausalLM' (2304-dim Gemma-2-2b) is handled by the PiD encoder config, not TextLLM"
)
# Verify tokenizer files exist to avoid runtime failures
tokenizer_files = {"tokenizer.json", "tokenizer.model", "tokenizer_config.json"}
if not any((mod.path / f).exists() for f in tokenizer_files):
raise NotAMatchError(
f"no tokenizer files found in '{mod.path}' "
f"(expected at least one of: {', '.join(sorted(tokenizer_files))})"
)
return cls(**override_fields)
View on GitHub (pinned to 0b6a024f2f)
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
Example fix
// before # auto-scan of gemma-2-2b folder -> rejected // after # explicit registration invokeai-model-install --source gemma-2-2b --type text_llm
Defensive patterns
Strategy: validation
Validate before calling
import json
def is_gemma2_2b(model_dir) -> bool:
cfg = json.loads((model_dir / "config.json").read_text())
return (cfg.get("architectures", [None])[0] == "Gemma2ForCausalLM"
and cfg.get("hidden_size") == 2304) Try / catch
try:
auto_install(path)
except NotAMatchError as e:
if "PiD encoder config" in str(e):
# Gemma-2-2b is reserved for the PiD encoder; pass explicit type if a chat LLM is wanted
install_model(path, type="text_llm") Prevention
- 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
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- missing config.json at {config_path}
- directory looks like a full diffusers pipeline, not a standa
- Gemma2 hidden_size {hidden_size} is incompatible with PiD, w
- Gemma2 GGUF embedding_length {hidden_size} is incompatible w
- transformer is SDNQ-quantized; use Main_SDNQ_Diffusers_FLUX_
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/e830fcf3cf61e30b.
Report an issue: GitHub.