{"record":{"id":"ce46af300d558324","repo":"ultralytics/yolov5","slug":"e-cache-may-be-out-of-date-try-force-reload-t","errorCode":null,"errorMessage":"{e}. Cache may be out of date, try `force_reload=True` or see {help_url} for help.","messagePattern":"(.+?)\\. Cache may be out of date, try `force_reload=True` or see (.+?) for help\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"hubconf.py","lineNumber":103,"sourceCode":"                        model = AutoShape(model)  # for file/URI/PIL/cv2/np inputs and NMS\n            except Exception:\n                model = attempt_load(path, device=device, fuse=False)  # arbitrary model\n        else:\n            cfg = next(iter((Path(__file__).parent / \"models\").rglob(f\"{path.stem}.yaml\")))  # model.yaml path\n            model = DetectionModel(cfg, channels, classes)  # create model\n            if pretrained:\n                ckpt = torch_load(attempt_download(path), map_location=device)  # load\n                csd = ckpt[\"model\"].float().state_dict()  # checkpoint state_dict as FP32\n                csd = intersect_dicts(csd, model.state_dict(), exclude=[\"anchors\"])  # intersect\n                model.load_state_dict(csd, strict=False)  # load\n                if len(ckpt[\"model\"].names) == classes:\n                    model.names = ckpt[\"model\"].names  # set class names attribute\n        return model.to(device)\n\n    except Exception as e:\n        help_url = \"https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading\"\n        s = f\"{e}. Cache may be out of date, try `force_reload=True` or see {help_url} for help.\"\n        raise RuntimeError(s) from e\n\n    finally:\n        LOGGER.setLevel(prev_level)  # restore on both paths, LOGGER is shared with ultralytics\n\n\ndef custom(path=\"path/to/model.pt\", autoshape=True, _verbose=True, device=None):\n    \"\"\"Loads a custom or local YOLOv5 model from a given path with optional autoshaping and device specification.\n\n    Args:\n        path (str): Path to the custom model file (e.g., 'path/to/model.pt').\n        autoshape (bool): Apply YOLOv5 .autoshape() wrapper to model if True, enabling compatibility with various input\n            types (default is True).\n        _verbose (bool): If True, prints all informational messages to the screen; otherwise, operates silently (default\n            is True).\n        device (str | torch.device | None): Device to load the model on, e.g., 'cpu', 'cuda', torch.device('cuda:0'),\n            etc. (default is None, which automatically selects the best available device).\n\n    Returns:","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/hubconf.py#L85-L121","documentation":"hubconf.py wraps every exception raised while downloading or building a torch.hub model into a RuntimeError that suggests force_reload=True. The underlying error {e} can be an HTTP failure, a corrupt cached repo, a KeyError while reading the checkpoint, or an import error inside the hub repo code; the message points at a stale ~/.cache/torch/hub checkout as the most common cause.","triggerScenarios":"Calling torch.hub.load('ultralytics/yolov5', 'yolov5s') when the cached repo in ~/.cache/torch/hub is from an older commit whose code no longer matches the downloaded weights; network interruption mid-download; force_reload=False after the upstream repo changed its API.","commonSituations":"Long-lived Docker images or CI caches holding an old hub checkout; corporate proxies returning HTML error pages instead of weights; running offline after a partial first attempt; switching between yolov5 pip package and hub code paths.","solutions":["Retry with force_reload: torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True).","Clear the hub cache: rm -rf ~/.cache/torch/hub/ultralytics_yolov5* and retry.","Read the original exception in the traceback ({e}) to distinguish network vs. code failure; check connectivity to github.com and the release assets.","For pin-point reproducibility, bypass hub entirely and load the local repo: sys.path.insert(0, repo); import hubconf; hubconf.custom('yolov5s.pt')."],"exampleFix":"# before\nmodel = torch.hub.load('ultralytics/yolov5', 'yolov5s')\n\n# after\nmodel = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)","handlingStrategy":"retry","validationCode":"import torch\n\ndef hub_model_available(repo: str, name: str) -> bool:\n    # cheap network probe before the heavyweight load\n    import requests\n    return requests.head(f\"https://github.com/{repo}\", timeout=10, allow_redirects=True).status_code == 200","typeGuard":null,"tryCatchPattern":"try:\n    model = torch.hub.load('ultralytics/yolov5', 'yolov5s')\nexcept RuntimeError as e:\n    if 'Cache may be out of date' in str(e):\n        model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)  # one retry","preventionTips":["Pin a specific commit: torch.hub.load(repo, model, trust_repo=True) after checkout pinning.","Warm and snapshot ~/.cache/torch/hub in CI images to avoid mid-run downloads.","Read the chained cause (__cause__) to distinguish cache staleness from network failure."],"tags":["torch-hub","cache","model-loading","network"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}