{"record":{"id":"0b23ef6de27d66ee","repo":"Stability-AI/generative-models","slug":"notimplementederror-0b23ef","errorCode":null,"errorMessage":"NotImplementedError","messagePattern":"NotImplementedError","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sgm/util.py","lineNumber":212,"sourceCode":"    dims_to_append = target_dims - x.ndim\n    if dims_to_append < 0:\n        raise ValueError(\n            f\"input has {x.ndim} dims but target_dims is {target_dims}, which is less\"\n        )\n    return x[(...,) + (None,) * dims_to_append]\n\n\ndef load_model_from_config(config, ckpt, verbose=True, freeze=True):\n    print(f\"Loading model from {ckpt}\")\n    if ckpt.endswith(\"ckpt\"):\n        pl_sd = torch.load(ckpt, map_location=\"cpu\")\n        if \"global_step\" in pl_sd:\n            print(f\"Global Step: {pl_sd['global_step']}\")\n        sd = pl_sd[\"state_dict\"]\n    elif ckpt.endswith(\"safetensors\"):\n        sd = load_safetensors(ckpt)\n    else:\n        raise NotImplementedError\n\n    model = instantiate_from_config(config.model)\n\n    m, u = model.load_state_dict(sd, strict=False)\n\n    if len(m) > 0 and verbose:\n        print(\"missing keys:\")\n        print(m)\n    if len(u) > 0 and verbose:\n        print(\"unexpected keys:\")\n        print(u)\n\n    if freeze:\n        for param in model.parameters():\n            param.requires_grad = False\n\n    model.eval()\n    return model","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/util.py#L194-L230","documentation":"load_model_from_config only knows two checkpoint formats: legacy .ckpt files (torch pickles with a 'state_dict' key) and .safetensors files. Anything else (or an unsupported file type) hits the else branch and raises a bare NotImplementedError instead of a descriptive error.","triggerScenarios":"Calling sgm.util.load_model_from_config(config, ckpt) where ckpt does not end with '.ckpt'-style torch-saved files handled above and does not end with 'safetensors' — e.g. a .pt/.pth/.bin file, a .safetensors path with wrong case, or a directory/URL path.","commonSituations":"Users downloading weights in .safetensors but passing a path with a different extension (e.g. '.safetensors.tmp'), passing HuggingFace .bin shards, or pointing at a diffusers-format folder rather than a single checkpoint file.","solutions":["Convert/rename the checkpoint so the path ends with '.safetensors' and load it with safetensors.torch.load_file","If it's a plain state_dict (.pt/.pth), load it yourself with torch.load and pass model.load_state_dict(sd, strict=False) manually","Verify the file path/extension is correct and the file exists"],"exampleFix":"// before\nmodel = load_model_from_config(config, \"model.bin\")  # NotImplementedError\n// after\nfrom safetensors.torch import load_file\nsd = load_file(\"model.safetensors\")\nmodel = instantiate_from_config(config.model)\nmodel.load_state_dict(sd, strict=False)","handlingStrategy":"validation","validationCode":"import os\np = \"model.safetensors\"\nassert os.path.isfile(p), f\"checkpoint not found: {p}\"\nassert p.endswith(\"safetensors\"), \"only safetensors supported\"","typeGuard":"def is_supported_ckpt(path: str) -> bool:\n    return os.path.isfile(path) and (path.endswith(\"safetensors\") or is_torch_ckpt(path))","tryCatchPattern":"try:\n    model = load_model_from_config(config, ckpt)\nexcept NotImplementedError:\n    sd = safetensors.torch.load_file(ckpt)  # manual fallback\n    model = instantiate_from_config(config.model)\n    model.load_state_dict(sd, strict=False)","preventionTips":["Standardize on .safetensors checkpoints","Validate file extensions before calling loader","Do not pass directories or HF .bin shards to this loader"],"tags":["python","checkpoint","model-loading","notimplementederror"],"backgroundTag":"unsupported-checkpoint-format","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}