AUTOMATIC1111/stable-diffusion-webui · error · ValueError

No codeformer model found

Error message

No codeformer model found

What it means

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.

Source

Thrown at modules/codeformer_model.py:42

class FaceRestorerCodeFormer(face_restoration_utils.CommonFaceRestoration):
    def name(self):
        return "CodeFormer"

    def load_net(self) -> torch.Module:
        for model_path in modelloader.load_models(
            model_path=self.model_path,
            model_url=model_url,
            command_path=self.model_path,
            download_name=model_download_name,
            ext_filter=['.pth'],
        ):
            return modelloader.load_spandrel_model(
                model_path,
                device=devices.device_codeformer,
                expected_architecture='CodeFormer',
            ).model
        raise ValueError("No codeformer model found")

    def get_device(self):
        return devices.device_codeformer

    def restore(self, np_image, w: float | None = None):
        if w is None:
            w = getattr(shared.opts, "code_former_weight", 0.5)

        def restore_face(cropped_face_t):
            assert self.net is not None
            return self.net(cropped_face_t, weight=w, adain=True)[0]

        return self.restore_with_helper(np_image, restore_face)


def setup_model(dirname: str) -> None:
    global codeformer
    try:

View on GitHub (pinned to 82a973c043)

Solutions

  1. Manually download codeformer-0.1.0.pth from the official release, rename to codeformer.pth, and place it in models/Codeformer/
  2. Check network/proxy access to github.com release assets; retry after connectivity is fixed and the directory is writable
  3. Ensure the folder is exactly models/Codeformer (capital F) and the file extension is .pth

Example fix

# before: empty models/Codeformer directory, restore() -> ValueError

# after: provision the file
mkdir -p models/Codeformer
curl -L -o models/Codeformer/codeformer.pth https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth
Defensive patterns

Strategy: validation

Validate before calling

import os
p = os.path.join('models', 'Codeformer', 'codeformer.pth')
if not os.path.isfile(p) or os.path.getsize(p) < 1_000_000:
    raise FileNotFoundError('CodeFormer weights missing; download codeformer.pth into models/Codeformer/')

Type guard

def codeformer_available(model_dir='models/Codeformer') -> bool:
    p = os.path.join(model_dir, 'codeformer.pth')
    return os.path.isfile(p) and os.path.getsize(p) > 1_000_000

Try / catch

try:
    shared.opts.codeformer_modules  # or the face-restore call path
except ValueError as e:
    if 'No codeformer model found' in str(e):
        download_codeformer_weights(); retry_once()
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14). Data as JSON: /api/errors/f339858d94ceb38d. Report an issue: GitHub.