{"record":{"id":"860b43e5f0139d3b","repo":"Lightning-AI/pytorch-lightning","slug":"path-str-filename-r-does-not-exist-or-is-not-a","errorCode":null,"errorMessage":"Path {str(filename)!r} does not exist or is not a file.","messagePattern":"Path (.+?) does not exist or is not a file\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/load.py","lineNumber":213,"sourceCode":"            return partial(_NotYetLoadedTensor.rebuild_parameter, archiveinfo=self)\n        return super().find_class(module, name)\n\n    @override\n    def persistent_load(self, pid: tuple) -> \"TypedStorage\":\n        from torch.storage import TypedStorage\n\n        _, cls, _, _, _ = pid\n        with warnings.catch_warnings():\n            # The TypedStorage APIs have heavy deprecations in torch, suppress all these warnings for now\n            warnings.simplefilter(\"ignore\")\n            storage = TypedStorage(dtype=cls().dtype, device=\"meta\")\n        storage.archiveinfo = pid\n        return storage\n\n\ndef _lazy_load(filename: _PATH) -> Any:\n    if not os.path.isfile(filename):\n        raise FileNotFoundError(f\"Path {str(filename)!r} does not exist or is not a file.\")\n    file_reader = torch.PyTorchFileReader(str(filename))\n    with BytesIO(file_reader.get_record(\"data.pkl\")) as pkl:\n        mup = _LazyLoadingUnpickler(pkl, file_reader)\n        return mup.load()\n\n\ndef _materialize_tensors(collection: Any) -> Any:\n    def _load_tensor(t: _NotYetLoadedTensor) -> Tensor:\n        return t._load_tensor()\n\n    return apply_to_collection(collection, dtype=_NotYetLoadedTensor, function=_load_tensor)\n\n\ndef _move_state_into(\n    source: dict[str, Any], destination: dict[str, Union[Any, _Stateful]], keys: Optional[set[str]] = None\n) -> None:\n    \"\"\"Takes the state from the source destination and moves it into the destination dictionary.\n","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/load.py#L195-L231","documentation":"`_lazy_load` opens a checkpoint with `torch.PyTorchFileReader`, which requires an existing regular file. Before touching the file it checks `os.path.isfile` and raises FileNotFoundError with the offending path if it is missing, a directory, or a non-file (e.g. an in-memory object or URL).","triggerScenarios":"Calling `load_checkpoint`/`_lazy_load` with a wrong path, a directory, an `os.PathLike` that doesn't exist, a relative path resolved from the wrong working directory, or an fsspec/URL-style path.","commonSituations":"Typos in checkpoint paths, running the script from a different CWD so relative paths break, passing a directory instead of the checkpoint file, or paths on remote storage that need local download first.","solutions":["Verify the path exists and is a file: `os.path.isfile(path)`; print the absolute path you're actually passing","Use absolute paths or anchor paths to the script/dir (e.g. `Path(__file__).parent`)","Download remote checkpoints to local disk before calling load_checkpoint"],"exampleFix":"// before\nstate = _lazy_load(\"checkpoints/model\")  # directory or missing\n\n// after\nfrom pathlib import Path\nckpt = Path(\"checkpoints/model.ckpt\").resolve()\nassert ckpt.is_file(), f\"missing {ckpt}\"\nstate = _lazy_load(str(ckpt))","handlingStrategy":"validation","validationCode":"import os\nif not os.path.isfile(str(path)):\n    raise FileNotFoundError(f\"checkpoint not found: {os.path.abspath(path)}\")","typeGuard":null,"tryCatchPattern":"try:\n    state = _lazy_load(path)\nexcept FileNotFoundError:\n    logger.error(\"checkpoint missing: %s\", path)\n    raise","preventionTips":["Use absolute, resolved paths for checkpoints","Download remote checkpoints locally before loading"],"tags":["lightning","checkpoints","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}