Stability-AI/generative-models · error · ValueError

Model {self.model_id} could not be loaded

Error message

Model {self.model_id} could not be loaded

What it means

In SGMWrapper._load_model, the config is loaded and load_model_from_config builds the model from the checkpoint; if that call returns None the wrapper raises this ValueError. It means the checkpoint/config pair could not produce a model — the wrapper can't proceed without a valid model object.

Source

Thrown at sgm/inference/api.py:155

        model_path="checkpoints",
        config_path="configs/inference",
        device="cuda",
        use_fp16=True,
    ) -> None:
        if model_id not in model_specs:
            raise ValueError(f"Model {model_id} not supported")
        self.model_id = model_id
        self.specs = model_specs[self.model_id]
        self.config = str(pathlib.Path(config_path, self.specs.config))
        self.ckpt = str(pathlib.Path(model_path, self.specs.ckpt))
        self.device = device
        self.model = self._load_model(device=device, use_fp16=use_fp16)

    def _load_model(self, device="cuda", use_fp16=True):
        config = OmegaConf.load(self.config)
        model = load_model_from_config(config, self.ckpt)
        if model is None:
            raise ValueError(f"Model {self.model_id} could not be loaded")
        model.to(device)
        if use_fp16:
            model.conditioner.half()
            model.model.half()
        return model

    def text_to_image(
        self,
        params: SamplingParams,
        prompt: str,
        negative_prompt: str = "",
        samples: int = 1,
        return_latents: bool = False,
    ):
        sampler = get_sampler_config(params)
        value_dict = asdict(params)
        value_dict["prompt"] = prompt
        value_dict["negative_prompt"] = negative_prompt

View on GitHub (pinned to e8cd657656)

Solutions

  1. Verify the checkpoint file exists and has the expected size (`ls -lh <model_path>/<specs.ckpt>`); re-download it if truncated.
  2. Point model_path at the directory that actually contains the checkpoint for the chosen model_id.
  3. If the file is corrupt, delete it and re-download, checking checksums; then confirm load_model_from_config returns a model by loading it manually.

Example fix

// before
model = SGMWrapper(model_id="sd-template-2.2")  # checkpoints/ file missing
// after
model = SGMWrapper(model_id="sd-template-2.2", model_path="/data/sgm_checkpoints")  # dir with the real .ckpt
Defensive patterns

Strategy: validation

Validate before calling

import pathlib, os
from sgm.inference.api import model_specs
spec = model_specs[model_id]
ckpt = pathlib.Path(model_path, spec.ckpt)
assert ckpt.is_file() and ckpt.stat().st_size > 0, f"Missing/empty checkpoint: {ckpt}"

Try / catch

try:
    model = SGMWrapper(model_id=model_id, model_path=model_path)
except ValueError as e:
    print(f"{e}; check checkpoint at {model_path} — re-download if corrupt")

Prevention

When it happens

Trigger: Calling `SGMWrapper(model_id=<valid id>)` where the resolved checkpoint file `model_path/<specs.ckpt>` is missing, empty, corrupt, or a failed download, causing load_model_from_config to return None instead of a model.

Common situations: Checkpoint download interrupted or truncated; wrong checkpoints directory (default "checkpoints") so the path silently resolves wrong; disk full during download; version mismatch between the config in configs/inference and an old checkpoint file.

Related errors


AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29). Data as JSON: /api/errors/b523094e8618b310. Report an issue: GitHub.