{"record":{"id":"f8b10765094b6204","repo":"lllyasviel/Fooocus","slug":"sam-model-sam-model-does-not-exist","errorCode":null,"errorMessage":"sam model {sam_model} does not exist.","messagePattern":"sam model (.+?) does not exist\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/config.py","lineNumber":970,"sourceCode":"def downloading_safety_checker_model():\n    load_file_from_url(\n        url='https://huggingface.co/mashb1t/misc/resolve/main/stable-diffusion-safety-checker.bin',\n        model_dir=path_safety_checker,\n        file_name='stable-diffusion-safety-checker.bin'\n    )\n    return os.path.join(path_safety_checker, 'stable-diffusion-safety-checker.bin')\n\n\ndef download_sam_model(sam_model: str) -> str:\n    match sam_model:\n        case 'vit_b':\n            return downloading_sam_vit_b()\n        case 'vit_l':\n            return downloading_sam_vit_l()\n        case 'vit_h':\n            return downloading_sam_vit_h()\n        case _:\n            raise ValueError(f\"sam model {sam_model} does not exist.\")\n\n\ndef downloading_sam_vit_b():\n    load_file_from_url(\n        url='https://huggingface.co/mashb1t/misc/resolve/main/sam_vit_b_01ec64.pth',\n        model_dir=path_sam,\n        file_name='sam_vit_b_01ec64.pth'\n    )\n    return os.path.join(path_sam, 'sam_vit_b_01ec64.pth')\n\n\ndef downloading_sam_vit_l():\n    load_file_from_url(\n        url='https://huggingface.co/mashb1t/misc/resolve/main/sam_vit_l_0b3195.pth',\n        model_dir=path_sam,\n        file_name='sam_vit_l_0b3195.pth'\n    )\n    return os.path.join(path_sam, 'sam_vit_l_0b3195.pth')","sourceCodeStart":952,"sourceCodeEnd":988,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/config.py#L952-L988","documentation":"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.","triggerScenarios":"Calling download_sam_model('sam_vit_b'), 'ViT-B', 'vit', or '' — anything but the exact lowercase 'vit_b'/'vit_l'/'vit_h'.","commonSituations":"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.","solutions":["Pass exactly 'vit_b', 'vit_l', or 'vit_h'.","If you added a new checkpoint, add a matching case that calls its downloader before the case _ arm.","Validate/normalize user input (strip, lower) against the supported list at the config boundary."],"exampleFix":"# before\npath = download_sam_model('SAM vit_h')\n# after\npath = download_sam_model('vit_h')","handlingStrategy":"type-guard","validationCode":"SAM_MODELS = ('vit_b', 'vit_l', 'vit_h')\nif sam_model not in SAM_MODELS:\n    raise ValueError(f'sam_model must be one of {SAM_MODELS}')","typeGuard":"def is_sam_model_name(v) -> bool:\n    return isinstance(v, str) and v in ('vit_b', 'vit_l', 'vit_h')","tryCatchPattern":null,"preventionTips":["Drive UI dropdowns from the literal tuple ('vit_b','vit_l','vit_h') so invalid values cannot be submitted.","Normalize input early: sam_model = sam_model.strip().lower()."],"tags":["segment-anything","model-download","config","match-statement","validation"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}