lllyasviel/Fooocus · error · ValueError

sam model {sam_model} does not exist.

Error message

sam model {sam_model} does not exist.

What it means

download_sam_model in modules/config.py maps a SAM (Segment Anything) variant name to its HuggingFace download via a Python match/case. Only 'vit_b', 'vit_l', and 'vit_h' are matched; any other string falls to case _ and raises ValueError. The function is the single entry point the SAM-based mask/detect annotators use to fetch their checkpoint.

Source

Thrown at modules/config.py:970

def downloading_safety_checker_model():
    load_file_from_url(
        url='https://huggingface.co/mashb1t/misc/resolve/main/stable-diffusion-safety-checker.bin',
        model_dir=path_safety_checker,
        file_name='stable-diffusion-safety-checker.bin'
    )
    return os.path.join(path_safety_checker, 'stable-diffusion-safety-checker.bin')


def download_sam_model(sam_model: str) -> str:
    match sam_model:
        case 'vit_b':
            return downloading_sam_vit_b()
        case 'vit_l':
            return downloading_sam_vit_l()
        case 'vit_h':
            return downloading_sam_vit_h()
        case _:
            raise ValueError(f"sam model {sam_model} does not exist.")


def downloading_sam_vit_b():
    load_file_from_url(
        url='https://huggingface.co/mashb1t/misc/resolve/main/sam_vit_b_01ec64.pth',
        model_dir=path_sam,
        file_name='sam_vit_b_01ec64.pth'
    )
    return os.path.join(path_sam, 'sam_vit_b_01ec64.pth')


def downloading_sam_vit_l():
    load_file_from_url(
        url='https://huggingface.co/mashb1t/misc/resolve/main/sam_vit_l_0b3195.pth',
        model_dir=path_sam,
        file_name='sam_vit_l_0b3195.pth'
    )
    return os.path.join(path_sam, 'sam_vit_l_0b3195.pth')

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Pass exactly 'vit_b', 'vit_l', or 'vit_h'.
  2. If you added a new checkpoint, add a matching case that calls its downloader before the case _ arm.
  3. Validate/normalize user input (strip, lower) against the supported list at the config boundary.

Example fix

# before
path = download_sam_model('SAM vit_h')
# after
path = download_sam_model('vit_h')
Defensive patterns

Strategy: type-guard

Validate before calling

SAM_MODELS = ('vit_b', 'vit_l', 'vit_h')
if sam_model not in SAM_MODELS:
    raise ValueError(f'sam_model must be one of {SAM_MODELS}')

Type guard

def is_sam_model_name(v) -> bool:
    return isinstance(v, str) and v in ('vit_b', 'vit_l', 'vit_h')

Prevention

When it happens

Trigger: Calling download_sam_model('sam_vit_b'), 'ViT-B', 'vit', or '' — anything but the exact lowercase 'vit_b'/'vit_l'/'vit_h'.

Common situations: Adding a new SAM variant (e.g. mobile_sam or sam2) without extending the match, or passing a filename instead of the short model key from a UI dropdown/config.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/f8b10765094b6204. Report an issue: GitHub.