{"record":{"id":"6c5a024e163ca600","repo":"invoke-ai/InvokeAI","slug":"unable-to-determine-class-name-from-config-file","errorCode":null,"errorMessage":"unable to determine class name from config file: {config}","messagePattern":"unable to determine class name from config file: (.+?)","errorType":"validation","errorClass":"NotAMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/identification_utils.py","lineNumber":106,"sourceCode":"\n    Raises:\n        NotAMatch if the config file is missing or does not contain a valid class name.\n    \"\"\"\n\n    if not isinstance(config, dict):\n        config = get_config_dict_or_raise(config)\n\n    try:\n        if \"_class_name\" in config:\n            # This is a diffusers-style config\n            config_class_name = config[\"_class_name\"]\n        elif \"architectures\" in config:\n            # This is a transformers-style config\n            config_class_name = config[\"architectures\"][0]\n        else:\n            raise ValueError(\"missing _class_name or architectures field\")\n    except Exception as e:\n        raise NotAMatchError(f\"unable to determine class name from config file: {config}\") from e\n\n    if not isinstance(config_class_name, str):\n        raise NotAMatchError(f\"_class_name or architectures field is not a string: {config_class_name}\")\n\n    return config_class_name\n\n\ndef raise_for_class_name(config: Path | set[Path] | dict[str, Any], class_name: str | set[str]) -> None:\n    \"\"\"Get the class name from the config file and raise NotAMatch if it is not in the expected set.\n\n    Args:\n        config_path: The path to the config file, or a set of paths to try.\n        class_name: The expected class name, or a set of expected class names.\n\n    Raises:\n        NotAMatch if the class name is not in the expected set.\n    \"\"\"\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/identification_utils.py#L88-L124","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n{ \"architectures\": [] }\n// after\n{ \"architectures\": [\"Gemma2ForCausalLM\"] }","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndef well_formed_architectures(model_dir: str | Path) -> bool:\n    cfg = json.loads((Path(model_dir) / \"config.json\").read_text(encoding=\"utf-8\"))\n    archs = cfg.get(\"architectures\")\n    return isinstance(archs, list) and len(archs) > 0 and all(isinstance(a, str) for a in archs)","typeGuard":"def has_str_class_name(cfg: dict) -> bool:\n    v = cfg.get(\"_class_name\")\n    return isinstance(v, str)","tryCatchPattern":"try:\n    import_model(model_dir)\nexcept NotAMatchError as e:\n    if \"unable to determine class name from config file\" in str(e):\n        cfg = json.loads((model_dir / \"config.json\").read_text())\n        print(f\"Fix architectures/_class_name in: {cfg}\")","preventionTips":["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"],"tags":["config-file","json","model-import"],"backgroundTag":"malformed-config-json","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}