Skip to content

Commit b8a96fe

Browse files
Fix fsspec local file protocol checks for new fsspec version (#19023)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4e72dcc commit b8a96fe

File tree

9 files changed

+20
-13
lines changed

9 files changed

+20
-13
lines changed

requirements/app/app.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ packaging
33
typing-extensions >=4.4.0, <4.8.0
44
deepdiff >=5.7.0, <6.6.0
55
starsessions >=1.2.1, <2.0 # strict
6-
fsspec >=2022.5.0, <2023.10.0
6+
fsspec >=2022.5.0, <2023.11.0
77
croniter >=1.3.0, <1.5.0 # strict; TODO: for now until we find something more robust.
88
traitlets >=5.3.0, <5.10.0
99
arrow >=1.2.0, <1.3.0

requirements/data/cloud.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: the upper bound for the package version is only set for CI stability, and it is dropped while installing this package
22
# in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment
33

4-
fsspec[http] >2021.06.0, <2023.10.0
4+
fsspec[http] >2021.06.0, <2023.11.0
55
s3fs >=2022.5.0, <2023.7.0

requirements/fabric/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
numpy >=1.17.2, <1.27.0
55
torch >=1.12.0, <2.2.0
6-
fsspec[http]>2021.06.0, <2023.10.0
6+
fsspec[http]>2021.06.0, <2023.11.0
77
packaging >=20.0, <=23.1
88
typing-extensions >=4.4.0, <4.8.0
99
lightning-utilities >=0.8.0, <0.10.0

requirements/pytorch/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ numpy >=1.17.2, <1.27.0
55
torch >=1.12.0, <2.2.0
66
tqdm >=4.57.0, <4.67.0
77
PyYAML >=5.4, <6.1.0
8-
fsspec[http] >2021.06.0, <2023.10.0
8+
fsspec[http] >2021.06.0, <2023.11.0
99
torchmetrics >=0.7.0, <1.3.0 # needed for using fixed compare_version
1010
packaging >=20.0, <=23.1
1111
typing-extensions >=4.4.0, <4.8.0

src/lightning/fabric/utilities/cloud_io.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import IO, Any, Dict, Union
1919

2020
import fsspec
21+
import fsspec.utils
2122
import torch
2223
from fsspec.core import url_to_fs
2324
from fsspec.implementations.local import AbstractFileSystem
@@ -128,3 +129,7 @@ def _is_dir(fs: AbstractFileSystem, path: Union[str, Path], strict: bool = False
128129
return not fs.isfile(path)
129130

130131
return fs.isdir(path)
132+
133+
134+
def _is_local_file_protocol(path: _PATH) -> bool:
135+
return fsspec.utils.get_protocol(str(path)) == "file"

src/lightning/fabric/utilities/distributed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from pathlib import Path
77
from typing import TYPE_CHECKING, Any, Iterable, Iterator, List, Optional, Sized, Union
88

9-
import fsspec.utils
109
import torch
1110
import torch.nn.functional as F
1211
from lightning_utilities.core.imports import package_available
1312
from torch import Tensor
1413
from torch.utils.data import Dataset, DistributedSampler, Sampler
1514

15+
from lightning.fabric.utilities.cloud_io import _is_local_file_protocol
1616
from lightning.fabric.utilities.data import _num_cpus_available
1717
from lightning.fabric.utilities.rank_zero import rank_zero_info
1818
from lightning.fabric.utilities.types import _PATH, ReduceOp
@@ -48,7 +48,7 @@ def is_shared_filesystem(strategy: "Strategy", path: Optional[_PATH] = None, tim
4848
4949
"""
5050
# Fast path: Any non-local filesystem is considered shared (e.g., S3)
51-
if path is not None and fsspec.utils.get_protocol(str(path)) != "file":
51+
if path is not None and not _is_local_file_protocol(path):
5252
return True
5353

5454
path = Path(Path.cwd() if path is None else path).resolve()

src/lightning/pytorch/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
4141

4242
### Fixed
4343

44-
-
44+
- Fixed checks for local file protocol due to fsspec changes in 2023.10.0 ([#19023](https://github.com/Lightning-AI/lightning/pull/19023))
45+
4546

4647

4748
## [2.1.2] - 2023-11-15
@@ -52,6 +53,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5253
- Fixed an issue where Metric instances from `torchmetrics` wouldn't get moved to the device when using FSDP ([#18954](https://github.com/Lightning-AI/lightning/issues/18954))
5354
- Fixed an issue preventing the user to `Trainer.save_checkpoint()` an FSDP model when `Trainer.test/validate/predict()` ran after `Trainer.fit()` ([#18992](https://github.com/Lightning-AI/lightning/issues/18992))
5455

56+
5557
## [2.1.1] - 2023-11-06
5658

5759
### Fixed

src/lightning/pytorch/callbacks/model_checkpoint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from torch import Tensor
3535

3636
import lightning.pytorch as pl
37-
from lightning.fabric.utilities.cloud_io import _is_dir, get_filesystem
37+
from lightning.fabric.utilities.cloud_io import _is_dir, _is_local_file_protocol, get_filesystem
3838
from lightning.fabric.utilities.types import _PATH
3939
from lightning.pytorch.callbacks import Checkpoint
4040
from lightning.pytorch.utilities.exceptions import MisconfigurationException
@@ -457,7 +457,7 @@ def __validate_init_configuration(self) -> None:
457457
def __init_ckpt_dir(self, dirpath: Optional[_PATH], filename: Optional[str]) -> None:
458458
self._fs = get_filesystem(dirpath if dirpath else "")
459459

460-
if dirpath and self._fs.protocol == "file":
460+
if dirpath and _is_local_file_protocol(dirpath if dirpath else ""):
461461
dirpath = os.path.realpath(dirpath)
462462

463463
self.dirpath = dirpath
@@ -675,7 +675,7 @@ def _save_last_checkpoint(self, trainer: "pl.Trainer", monitor_candidates: Dict[
675675

676676
# set the last model path before saving because it will be part of the state.
677677
previous, self.last_model_path = self.last_model_path, filepath
678-
if self._fs.protocol == "file" and self._last_checkpoint_saved and self.save_top_k != 0:
678+
if _is_local_file_protocol(filepath) and self._last_checkpoint_saved and self.save_top_k != 0:
679679
self._link_checkpoint(trainer, self._last_checkpoint_saved, filepath)
680680
else:
681681
self._save_checkpoint(trainer, filepath)
@@ -771,7 +771,7 @@ def _should_remove_checkpoint(self, trainer: "pl.Trainer", previous: str, curren
771771
"""
772772
if previous == current:
773773
return False
774-
if self._fs.protocol != "file":
774+
if not _is_local_file_protocol(previous):
775775
return True
776776
previous = Path(previous).absolute()
777777
resume_path = Path(trainer.ckpt_path).absolute() if trainer.ckpt_path is not None else None

src/lightning/pytorch/trainer/trainer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import lightning.pytorch as pl
3535
from lightning.fabric.utilities.apply_func import convert_tensors_to_scalars
36-
from lightning.fabric.utilities.cloud_io import get_filesystem
36+
from lightning.fabric.utilities.cloud_io import _is_local_file_protocol
3737
from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
3838
from lightning.fabric.utilities.types import _PATH
3939
from lightning.pytorch.accelerators import Accelerator
@@ -1285,7 +1285,7 @@ def default_root_dir(self) -> str:
12851285
It is used as a fallback if logger or checkpoint callback do not define specific save paths.
12861286
12871287
"""
1288-
if get_filesystem(self._default_root_dir).protocol == "file":
1288+
if _is_local_file_protocol(self._default_root_dir):
12891289
return os.path.normpath(self._default_root_dir)
12901290
return self._default_root_dir
12911291

0 commit comments

Comments
 (0)