{"record":{"id":"b523094e8618b310","repo":"Stability-AI/generative-models","slug":"model-self-model-id-could-not-be-loaded","errorCode":null,"errorMessage":"Model {self.model_id} could not be loaded","messagePattern":"Model (.+?) could not be loaded","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sgm/inference/api.py","lineNumber":155,"sourceCode":"        model_path=\"checkpoints\",\r\n        config_path=\"configs/inference\",\r\n        device=\"cuda\",\r\n        use_fp16=True,\r\n    ) -> None:\r\n        if model_id not in model_specs:\r\n            raise ValueError(f\"Model {model_id} not supported\")\r\n        self.model_id = model_id\r\n        self.specs = model_specs[self.model_id]\r\n        self.config = str(pathlib.Path(config_path, self.specs.config))\r\n        self.ckpt = str(pathlib.Path(model_path, self.specs.ckpt))\r\n        self.device = device\r\n        self.model = self._load_model(device=device, use_fp16=use_fp16)\r\n\r\n    def _load_model(self, device=\"cuda\", use_fp16=True):\r\n        config = OmegaConf.load(self.config)\r\n        model = load_model_from_config(config, self.ckpt)\r\n        if model is None:\r\n            raise ValueError(f\"Model {self.model_id} could not be loaded\")\r\n        model.to(device)\r\n        if use_fp16:\r\n            model.conditioner.half()\r\n            model.model.half()\r\n        return model\r\n\r\n    def text_to_image(\r\n        self,\r\n        params: SamplingParams,\r\n        prompt: str,\r\n        negative_prompt: str = \"\",\r\n        samples: int = 1,\r\n        return_latents: bool = False,\r\n    ):\r\n        sampler = get_sampler_config(params)\r\n        value_dict = asdict(params)\r\n        value_dict[\"prompt\"] = prompt\r\n        value_dict[\"negative_prompt\"] = negative_prompt\r","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/inference/api.py#L137-L173","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the checkpoint file exists and has the expected size (`ls -lh <model_path>/<specs.ckpt>`); re-download it if truncated.","Point model_path at the directory that actually contains the checkpoint for the chosen model_id.","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."],"exampleFix":"// before\nmodel = SGMWrapper(model_id=\"sd-template-2.2\")  # checkpoints/ file missing\n// after\nmodel = SGMWrapper(model_id=\"sd-template-2.2\", model_path=\"/data/sgm_checkpoints\")  # dir with the real .ckpt","handlingStrategy":"validation","validationCode":"import pathlib, os\nfrom sgm.inference.api import model_specs\nspec = model_specs[model_id]\nckpt = pathlib.Path(model_path, spec.ckpt)\nassert ckpt.is_file() and ckpt.stat().st_size > 0, f\"Missing/empty checkpoint: {ckpt}\"","typeGuard":null,"tryCatchPattern":"try:\n    model = SGMWrapper(model_id=model_id, model_path=model_path)\nexcept ValueError as e:\n    print(f\"{e}; check checkpoint at {model_path} — re-download if corrupt\")","preventionTips":["Verify checkpoint file size/checksum after downloading.","Point model_path at the directory containing the exact spec.ckpt filename.","Re-download truncated files instead of retrying loads."],"tags":["model-loading","checkpoint","corrupt-file"],"backgroundTag":"checkpoint-load-failed","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}