Skip to content

Commit aae797f

Browse files
awaelchlitchaton
andcommitted
[Fault Tolerance] Don't check the len of a dataset, but its instance. (#10432)
Co-authored-by: Thomas Chaton <[email protected]>
1 parent 295f62f commit aae797f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1717
- Fixed the logging with `on_step=True` in epoch-level hooks causing unintended side-effects. Logging with `on_step=True` in epoch-level hooks will now correctly raise an error ([#10409](https://github.com/PyTorchLightning/pytorch-lightning/pull/10409))
1818
- Fixed deadlocks for distributed training with `RichProgressBar` ([#10428](https://github.com/PyTorchLightning/pytorch-lightning/pull/10428))
1919
- Fixed an issue where the model wrapper in Lite converted non-floating point tensors to float ([#10429](https://github.com/PyTorchLightning/pytorch-lightning/pull/10429))
20+
- Fixed an issue with inferring the dataset type in fault-tolerant training ([#10432](https://github.com/PyTorchLightning/pytorch-lightning/pull/10432))
2021

2122

2223
## [1.5.0] - 2021-11-02

pytorch_lightning/trainer/data_loading.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
CaptureMapDataset,
3838
FastForwardSampler,
3939
)
40-
from pytorch_lightning.utilities.data import has_iterable_dataset, has_len_all_ranks
40+
from pytorch_lightning.utilities.data import get_len, has_iterable_dataset, has_len_all_ranks
4141
from pytorch_lightning.utilities.enums import DistributedType
4242
from pytorch_lightning.utilities.exceptions import MisconfigurationException
4343
from pytorch_lightning.utilities.imports import _fault_tolerant_training
@@ -282,10 +282,11 @@ def _get_dataloader_init_kwargs(
282282
dl_kwargs["sampler"] = None
283283

284284
if _fault_tolerant_training():
285-
if isinstance(dl_kwargs["dataset"], IterableDataset):
285+
dataset = dl_kwargs["dataset"]
286+
if isinstance(dataset, IterableDataset):
286287
# wrap the `IterableDataset` into a `CaptureIterableDataset` to record sampler states.
287288
dl_kwargs["dataset"] = CaptureIterableDataset(dataset=dl_kwargs["dataset"])
288-
elif len(dl_kwargs["dataset"]):
289+
elif get_len(dataset) != float("inf"):
289290
dl_kwargs["dataset"] = CaptureMapDataset(dataset=dl_kwargs["dataset"])
290291
else:
291292
raise MisconfigurationException(

0 commit comments

Comments
 (0)