{"record":{"id":"f339858d94ceb38d","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"no-codeformer-model-found","errorCode":null,"errorMessage":"No codeformer model found","messagePattern":"No codeformer model found","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/codeformer_model.py","lineNumber":42,"sourceCode":"\r\nclass FaceRestorerCodeFormer(face_restoration_utils.CommonFaceRestoration):\r\n    def name(self):\r\n        return \"CodeFormer\"\r\n\r\n    def load_net(self) -> torch.Module:\r\n        for model_path in modelloader.load_models(\r\n            model_path=self.model_path,\r\n            model_url=model_url,\r\n            command_path=self.model_path,\r\n            download_name=model_download_name,\r\n            ext_filter=['.pth'],\r\n        ):\r\n            return modelloader.load_spandrel_model(\r\n                model_path,\r\n                device=devices.device_codeformer,\r\n                expected_architecture='CodeFormer',\r\n            ).model\r\n        raise ValueError(\"No codeformer model found\")\r\n\r\n    def get_device(self):\r\n        return devices.device_codeformer\r\n\r\n    def restore(self, np_image, w: float | None = None):\r\n        if w is None:\r\n            w = getattr(shared.opts, \"code_former_weight\", 0.5)\r\n\r\n        def restore_face(cropped_face_t):\r\n            assert self.net is not None\r\n            return self.net(cropped_face_t, weight=w, adain=True)[0]\r\n\r\n        return self.restore_with_helper(np_image, restore_face)\r\n\r\n\r\ndef setup_model(dirname: str) -> None:\r\n    global codeformer\r\n    try:\r","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/codeformer_model.py#L24-L60","documentation":"ValueError raised by CodeFormer's setup/load path when modelloader.load_models yields no candidate .pth file for CodeFormer under the models/Codeformer directory and the configured model_url. That loader normally downloads codeformer.pth from the remote URL on first use; if the download is skipped (offline, blocked URL) and no local file exists, iteration completes empty and this error is thrown to the caller.","triggerScenarios":"Enabling CodeFormer in Extras -> Face restore or API face_restore_options while models/Codeformer/codeformer.pth is absent and the automatic download from GitHub releases fails (no network, proxy blocking github raw/release hosts); also misconfigured model_path pointing elsewhere.","commonSituations":"Air-gapped or firewalled deployments where release-assets.githubusercontent.com is blocked; a failed/interrupted first download that left no file (or a 0-byte file filtered out); directory moved or CODEFORMER model path changed.","solutions":["Manually download codeformer-0.1.0.pth from the official release, rename to codeformer.pth, and place it in models/Codeformer/","Check network/proxy access to github.com release assets; retry after connectivity is fixed and the directory is writable","Ensure the folder is exactly models/Codeformer (capital F) and the file extension is .pth"],"exampleFix":"# before: empty models/Codeformer directory, restore() -> ValueError\n\n# after: provision the file\nmkdir -p models/Codeformer\ncurl -L -o models/Codeformer/codeformer.pth https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth","handlingStrategy":"validation","validationCode":"import os\np = os.path.join('models', 'Codeformer', 'codeformer.pth')\nif not os.path.isfile(p) or os.path.getsize(p) < 1_000_000:\n    raise FileNotFoundError('CodeFormer weights missing; download codeformer.pth into models/Codeformer/')","typeGuard":"def codeformer_available(model_dir='models/Codeformer') -> bool:\n    p = os.path.join(model_dir, 'codeformer.pth')\n    return os.path.isfile(p) and os.path.getsize(p) > 1_000_000","tryCatchPattern":"try:\n    shared.opts.codeformer_modules  # or the face-restore call path\nexcept ValueError as e:\n    if 'No codeformer model found' in str(e):\n        download_codeformer_weights(); retry_once()\n    else:\n        raise","preventionTips":["Pre-provision restore-model weights in deployment images","Whitelist github release domains in firewalled environments","Skip enabling CodeFormer when the weight file is absent"],"tags":["codeformer","face-restoration","model-download","offline","stable-diffusion-webui"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}