{"record":{"id":"fbd2bca6fcbaf944","repo":"invoke-ai/InvokeAI","slug":"unable-to-decipher-load-class-based-on-given-confi","errorCode":null,"errorMessage":"Unable to decipher Load Class based on given config.json","messagePattern":"Unable to decipher Load Class based on given config\\.json","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/load/model_loaders/generic_diffusers.py","lineNumber":72,"sourceCode":"    def get_hf_load_class(self, model_path: Path, submodel_type: Optional[SubModelType] = None) -> ModelMixin:\n        \"\"\"Given the model path and submodel, returns the diffusers ModelMixin subclass needed to load.\"\"\"\n        result = None\n        if submodel_type:\n            try:\n                config = self._load_diffusers_config(model_path, config_name=\"model_index.json\")\n                module, class_name = config[submodel_type.value]\n                result = self._hf_definition_to_type(module=module, class_name=class_name)\n            except KeyError as e:\n                raise ValueError(f'The \"{submodel_type}\" submodel is not available for this model.') from e\n        else:\n            try:\n                config = self._load_diffusers_config(model_path, config_name=\"config.json\")\n                if class_name := config.get(\"_class_name\"):\n                    result = self._hf_definition_to_type(module=\"diffusers\", class_name=class_name)\n                elif class_name := config.get(\"architectures\"):\n                    result = self._hf_definition_to_type(module=\"transformers\", class_name=class_name[0])\n                else:\n                    raise RuntimeError(\"Unable to decipher Load Class based on given config.json\")\n            except KeyError as e:\n                raise ValueError(\"An expected config.json file is missing from this model.\") from e\n        assert result is not None\n        return result\n\n    # TO DO: Add exception handling\n    def _hf_definition_to_type(self, module: str, class_name: str) -> ModelMixin:  # fix with correct type\n        if module in [\n            \"diffusers\",\n            \"transformers\",\n            \"invokeai.backend.quantization.fast_quantized_transformers_model\",\n            \"invokeai.backend.quantization.fast_quantized_diffusion_model\",\n        ]:\n            res_type = sys.modules[module]\n        else:\n            res_type = sys.modules[\"diffusers\"].pipelines\n        result: ModelMixin = getattr(res_type, class_name)\n        return result","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/load/model_loaders/generic_diffusers.py#L54-L90","documentation":"get_hf_load_class reads the model's config.json to decide which diffusers or transformers class instantiates the model. If the config has neither a `_class_name` nor an `architectures` key, the loader cannot determine the class and raises this RuntimeError. It is a guard against loading models whose configuration is incomplete or not in a recognizable diffusers/transformers layout.","triggerScenarios":"Calling get_hf_load_class (directly or via diffusers_load_directory/_load_model) on a model directory whose config.json lacks both `_class_name` and `architectures` fields.","commonSituations":"Hand-converted or partially downloaded models with a stub config.json; single-file checkpoints converted with custom scripts that omit metadata keys; non-diffusers model formats that ship a config.json without HuggingFace metadata.","solutions":["Open the model's config.json and add the `_class_name` field (e.g. \"_class_name\": \"UNet2DConditionModel\") matching the actual architecture.","For transformers-based models, add an `architectures` array (e.g. \"architectures\": [\"CLIPTextModel\"]).","Re-download or re-export the model from the original HuggingFace repo so config.json is complete.","Verify you are pointing the loader at the subfolder that actually contains the full config, not a parent directory."],"exampleFix":"// before (config.json fragment)\n{ \"model_type\": \"unet\", \"sample_size\": 64 }\n// after\n{ \"_class_name\": \"UNet2DConditionModel\", \"model_type\": \"unet\", \"sample_size\": 64 }","handlingStrategy":"validation","validationCode":"import json\ncfg = json.loads((model_path / \"config.json\").read_text())\nif \"_class_name\" not in cfg and \"architectures\" not in cfg:\n    raise ValueError(f\"config.json has no _class_name or architectures: {model_path}\")","typeGuard":"def has_load_class(cfg: dict) -> bool:\n    return isinstance(cfg, dict) and bool(cfg.get(\"_class_name\") or cfg.get(\"architectures\"))","tryCatchPattern":"try:\n    cls = loader.get_hf_load_class(model_path)\nexcept RuntimeError as e:\n    if \"Unable to decipher Load Class\" in str(e):\n        fix_config_json(model_path)  # add _class_name/architectures\n    else:\n        raise","preventionTips":["Always download models via diffusers' from_pretrained or official conversion scripts so config.json is complete.","Validate config.json contains `_class_name` or `architectures` after download or conversion.","Never hand-edit config.json without re-checking HuggingFace metadata keys."],"tags":["config","diffusers","model-loading"],"backgroundTag":"missing-config-key","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}