{"record":{"id":"70b8e5f6c6260277","repo":"lllyasviel/Fooocus","slug":"checkpoint-url-or-path-is-invalid-70b8e5","errorCode":null,"errorMessage":"checkpoint url or path is invalid","messagePattern":"checkpoint url or path is invalid","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"extras/BLIP/models/blip_nlvr.py","lineNumber":85,"sourceCode":"            return prediction\n    \ndef blip_nlvr(pretrained='',**kwargs):\n    model = BLIP_NLVR(**kwargs)\n    if pretrained:\n        model,msg = load_checkpoint(model,pretrained)\n        print(\"missing keys:\")\n        print(msg.missing_keys)\n    return model  \n\n        \ndef load_checkpoint(model,url_or_filename):\n    if is_url(url_or_filename):\n        cached_file = download_cached_file(url_or_filename, check_hash=False, progress=True)\n        checkpoint = torch.load(cached_file, map_location='cpu', weights_only=True) \n    elif os.path.isfile(url_or_filename):        \n        checkpoint = torch.load(url_or_filename, map_location='cpu', weights_only=True) \n    else:\n        raise RuntimeError('checkpoint url or path is invalid')\n    state_dict = checkpoint['model']\n    \n    state_dict['visual_encoder.pos_embed'] = interpolate_pos_embed(state_dict['visual_encoder.pos_embed'],model.visual_encoder) \n    \n    for key in list(state_dict.keys()):\n        if 'crossattention.self.' in key:\n            new_key0 = key.replace('self','self0')\n            new_key1 = key.replace('self','self1')\n            state_dict[new_key0] = state_dict[key]\n            state_dict[new_key1] = state_dict[key]\n        elif 'crossattention.output.dense.' in key:\n            new_key0 = key.replace('dense','dense0')\n            new_key1 = key.replace('dense','dense1')\n            state_dict[new_key0] = state_dict[key]\n            state_dict[new_key1] = state_dict[key]  \n                \n    msg = model.load_state_dict(state_dict,strict=False)\n    print('load checkpoint from %s'%url_or_filename)  ","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/extras/BLIP/models/blip_nlvr.py#L67-L103","documentation":"Identical guard to BLIP's generic loader, but in the NLVR (visual reasoning) model loader: load_checkpoint in blip_nlvr.py raises RuntimeError when url_or_filename is neither an http/https URL nor an existing local file. It means the NLVR pretrained weights location is invalid before any torch.load happens.","triggerScenarios":"Calling blip_nlvr.load_checkpoint with a wrong/missing path to NLVR weights (e.g. 'checkpoints/model_base_nlvr.pth' not downloaded), a non-http(s) URI, or a relative path resolved from the wrong working directory.","commonSituations":"Running NLVR evaluation without first downloading model_base_nlvr.pth from the BLIP release; moving the repo or running from another directory so relative paths break; config files pointing to stale checkpoint names.","solutions":["Confirm the NLVR checkpoint file exists and pass its absolute path","Or pass the official release URL (https://storage.googleapis.com/salesforce-research-blip/...) so download_cached_file fetches it","Fix the cwd: run scripts from the repository root or make the path absolute","Check scheme of URL values in config — only http/https are accepted"],"exampleFix":"// before\nmodel, _ = load_checkpoint_model(cfg, 'model_base_nlvr.pth')\n\n// after\nimport os\nckpt = os.path.abspath('checkpoints/model_base_nlvr.pth')\nif not os.path.isfile(ckpt):\n    ckpt = 'https://storage.googleapis.com/salesforce-research-blip/models/model_base_nlvr.pth'\nload_checkpoint(model, ckpt)","handlingStrategy":"validation","validationCode":"import os\nfrom urllib.parse import urlparse\n\ndef assert_checkpoint_usable(s):\n    ok = urlparse(s).scheme in ('http', 'https') or os.path.isfile(os.path.expanduser(s))\n    assert ok, f'NLVR checkpoint missing or bad URL: {s!r}'","typeGuard":null,"tryCatchPattern":"try:\n    load_checkpoint(model, ckpt)\nexcept RuntimeError as e:\n    if 'checkpoint url or path is invalid' in str(e):\n        # fall back to official release URL\n        load_checkpoint(model, RELEASE_URL)\n    else:\n        raise","preventionTips":["Download NLVR weights in a documented setup script","Store checkpoint paths in one config location and validate them at startup","Run scripts from the repo root or use absolute paths"],"tags":["blip","nlvr","checkpoint","file-not-found"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}