invoke-ai/InvokeAI · error · NotAMatchError
unable to determine class name from config file: {config}
Error message
unable to determine class name from config file: {config} What it means
NotAMatchError raised by get_class_name_from_config_dict_or_raise when extracting the class name from the loaded config dict throws for any reason — most often the missing _class_name/architectures ValueError (1038), but also non-list 'architectures' values, an empty architectures list (IndexError), or a non-subscriptable value. The full config dict is embedded in the message for diagnosis.
Source
Thrown at invokeai/backend/model_manager/configs/identification_utils.py:106
Raises:
NotAMatch if the config file is missing or does not contain a valid class name.
"""
if not isinstance(config, dict):
config = get_config_dict_or_raise(config)
try:
if "_class_name" in config:
# This is a diffusers-style config
config_class_name = config["_class_name"]
elif "architectures" in config:
# This is a transformers-style config
config_class_name = config["architectures"][0]
else:
raise ValueError("missing _class_name or architectures field")
except Exception as e:
raise NotAMatchError(f"unable to determine class name from config file: {config}") from e
if not isinstance(config_class_name, str):
raise NotAMatchError(f"_class_name or architectures field is not a string: {config_class_name}")
return config_class_name
def raise_for_class_name(config: Path | set[Path] | dict[str, Any], class_name: str | set[str]) -> None:
"""Get the class name from the config file and raise NotAMatch if it is not in the expected set.
Args:
config_path: The path to the config file, or a set of paths to try.
class_name: The expected class name, or a set of expected class names.
Raises:
NotAMatch if the class name is not in the expected set.
"""
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Inspect the config printed in the message; fix 'architectures' to be a non-empty list of class-name strings, or add '_class_name'
- Replace the config with the pristine one from the upstream HuggingFace repo
- Validate with python -c "import json;c=json.load(open('config.json'));print(c.get('_class_name') or c.get('architectures'))" before re-importing
Example fix
// before
{ "architectures": [] }
// after
{ "architectures": ["Gemma2ForCausalLM"] } Defensive patterns
Strategy: validation
Validate before calling
import json
from pathlib import Path
def well_formed_architectures(model_dir: str | Path) -> bool:
cfg = json.loads((Path(model_dir) / "config.json").read_text(encoding="utf-8"))
archs = cfg.get("architectures")
return isinstance(archs, list) and len(archs) > 0 and all(isinstance(a, str) for a in archs) Type guard
def has_str_class_name(cfg: dict) -> bool:
v = cfg.get("_class_name")
return isinstance(v, str) Try / catch
try:
import_model(model_dir)
except NotAMatchError as e:
if "unable to determine class name from config file" in str(e):
cfg = json.loads((model_dir / "config.json").read_text())
print(f"Fix architectures/_class_name in: {cfg}") Prevention
- Validate that architectures is a non-empty list of strings before importing
- Re-download config.json after any partial/corrupt download
- Compare your config.json against the upstream repo with diff to catch structural damage
When it happens
Trigger: Called from raise_for_class_name / raise_if_config_doesnt_look_like_clip_vision / from_model_on_disk with a JSON config where '_class_name' or 'architectures[0]' cannot be read: architectures is a string/null, the list is empty, or the dict is missing both keys.
Common situations: Malformed config.json from a partial download or bad edit; architectures written as a single string instead of a list; empty architectures array in a converted model; custom pipeline exports with unexpected structure.
Related errors
- unable to load config file(s): {problems}
- missing _class_name or architectures field
- Gemini response payload was not a JSON object
- Gemma2 hidden_size {hidden_size} is incompatible with PiD, w
- directory does not contain Gemma2 tokenizer files (tokenizer
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/6c5a024e163ca600.
Report an issue: GitHub.