invoke-ai/InvokeAI · error · NotAMatchError
model architecture '{class_name}' is not a causal language m
Error message
model architecture '{class_name}' is not a causal language model What it means
NotAMatchError from TextLLM from_model_on_disk. The generic text-LLM config only accepts causal language model architectures: the config dict's architecture class name must end with 'ForCausalLM' (LlamaForCausalLM, Phi3ForCausalLM, Qwen2ForCausalLM, etc.). Anything else (encoders, seq2seq, vision models) is rejected as not a supported causal LM.
Source
Thrown at invokeai/backend/model_manager/configs/text_llm.py:48
"""Model config for text-only causal language models (e.g. Llama, Phi, Qwen, Mistral)."""
type: Literal[ModelType.TextLLM] = Field(default=ModelType.TextLLM)
base: Literal[BaseModelType.Any] = Field(default=BaseModelType.Any)
cpu_only: bool | None = Field(default=None, description="Whether this model should run on CPU only")
@classmethod
def from_model_on_disk(cls, mod: ModelOnDisk, override_fields: dict[str, Any]) -> Self:
raise_if_not_dir(mod)
raise_for_override_fields(cls, override_fields)
# Check that the model's architecture is a causal language model.
# 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"}View on GitHub (pinned to 0b6a024f2f)
Solutions
- Use a model with a *ForCausalLM architecture (Llama, Qwen2, Phi3, Mistral, Gemma, GPTNeoX families)
- Fix config.json 'architectures' if it was corrupted, using the value from the upstream repo
- Register encoder/seq2seq models under their appropriate InvokeAI model type instead of text_llm
Example fix
// before
{"architectures": ["T5EncoderModel"], ...}
// after
{"architectures": ["Qwen2ForCausalLM"], ...} # or use a causal-LM model Defensive patterns
Strategy: validation
Validate before calling
import json
def is_causal_lm(model_dir) -> bool:
cfg = json.loads((model_dir / "config.json").read_text())
archs = cfg.get("architectures", [])
return bool(archs) and archs[0].endswith("ForCausalLM") Try / catch
try:
install_model(path, type="text_llm")
except NotAMatchError as e:
if "causal language model" in str(e):
logger.error("Architecture is not *ForCausalLM; choose an encoder/seq2seq-appropriate type") Prevention
- Check config.json 'architectures' before adding a model as text_llm
- Only use *ForCausalLM models (Llama/Qwen2/Phi3/Mistral/Gemma) as text LLMs
- Don't hand-edit config.json architectures
When it happens
Trigger: from_model_on_disk on a model whose config.json 'architectures' class does not end with 'ForCausalLM' — e.g. T5ForConditionalGeneration, BertModel, CLIPTextModel, or a malformed config.json missing 'architectures'.
Common situations: Trying to load encoder-only or encoder-decoder models (T5, BERT, CLIP) as chat LLMs, embedding models, or configs whose architectures entry was edited/stripped.
Related errors
- str(e)
- Multiuser mode is disabled. Authentication is not required i
- Multiuser mode is disabled. Admin setup is not required in s
- Invalid regex: {e}
- Invalid generation_devices value '{v}'. Use 'auto' or a list
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/211ad0fb95a38755.
Report an issue: GitHub.