invoke-ai/InvokeAI · error · ValueError

An expected config.json file is missing from this model.

Error message

An expected config.json file is missing from this model.

What it means

When get_hf_load_class resolves the diffusers/transformers class, it looks up the class name in the library's module maps. A KeyError means the referenced class or expected config entry does not exist; this except clause converts it to a ValueError stating that the model's config.json (or a key within it expected by the maps) is missing from the model. It signals the model directory is incomplete relative to what the loader expects.

Solutions

  1. Check the model directory actually contains config.json and re-download it if missing.
  2. Add a complete diffusers-style config.json (with `_class_name`) to the model directory.
  3. If the class name in config is non-standard, rename it to the canonical diffusers/transformers class name.
  4. Re-export the model using the official diffusers conversion script so all metadata files are produced.

Example fix

// before: model dir contains only model.safetensors
// after: ensure model dir contains config.json
// model/config.json
{ "_class_name": "UNet2DConditionModel", "in_channels": 4 }
Defensive patterns

Strategy: validation

Validate before calling

cfg_path = model_path / "config.json"
if not cfg_path.is_file():
    raise FileNotFoundError(f"Model directory missing config.json: {model_path}")

Type guard

def config_json_present(model_path) -> bool:
    import json
    p = model_path / "config.json"
    return p.is_file() and bool(json.loads(p.read_text()))

Try / catch

try:
    cls = loader.get_hf_load_class(model_path)
except ValueError as e:
    if "config.json" in str(e):
        re_download_model(model_path)  # restore missing metadata files
    else:
        raise

Prevention

When it happens

Trigger: get_hf_load_class hits a KeyError while resolving class names from config.json — e.g. the config file itself is absent (lookup raised KeyError) or `_class_name`/`architectures` values point to entries missing from the loader's expected structure.

Common situations: Interrupted downloads leaving models without config.json; models converted with tools that drop metadata files; users pointing the loader at a checkpoint root that only contains weights.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/59427aa046ca2b64. Report an issue: GitHub.

Appendix: source

Thrown at invokeai/backend/model_manager/load/model_loaders/generic_diffusers.py:74

        result = None
        if submodel_type:
            try:
                config = self._load_diffusers_config(model_path, config_name="model_index.json")
                module, class_name = config[submodel_type.value]
                result = self._hf_definition_to_type(module=module, class_name=class_name)
            except KeyError as e:
                raise ValueError(f'The "{submodel_type}" submodel is not available for this model.') from e
        else:
            try:
                config = self._load_diffusers_config(model_path, config_name="config.json")
                if class_name := config.get("_class_name"):
                    result = self._hf_definition_to_type(module="diffusers", class_name=class_name)
                elif class_name := config.get("architectures"):
                    result = self._hf_definition_to_type(module="transformers", class_name=class_name[0])
                else:
                    raise RuntimeError("Unable to decipher Load Class based on given config.json")
            except KeyError as e:
                raise ValueError("An expected config.json file is missing from this model.") from e
        assert result is not None
        return result

    # TO DO: Add exception handling
    def _hf_definition_to_type(self, module: str, class_name: str) -> ModelMixin:  # fix with correct type
        if module in [
            "diffusers",
            "transformers",
            "invokeai.backend.quantization.fast_quantized_transformers_model",
            "invokeai.backend.quantization.fast_quantized_diffusion_model",
        ]:
            res_type = sys.modules[module]
        else:
            res_type = sys.modules["diffusers"].pipelines
        result: ModelMixin = getattr(res_type, class_name)
        return result

    def _load_diffusers_config(self, model_path: Path, config_name: str = "config.json") -> dict[str, Any]:

View on GitHub (pinned to 0b6a024f2f)