diff --git a/CHANGELOG.md b/CHANGELOG.md index 4015fc1829..6bfcbaff45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Changed +- Does not interfere with a default sampler ([#1318](https://github.com/PyTorchLightning/pytorch-lightning/pull/1318)) - Enhanced load_from_checkpoint to also forward params to the model ([#1307](https://github.com/PyTorchLightning/pytorch-lightning/pull/1307)) - Made `evalaute` method private >> `Trainer._evaluate(...)`. ([#1260](https://github.com/PyTorchLightning/pytorch-lightning/pull/1260)) diff --git a/pytorch_lightning/trainer/data_loading.py b/pytorch_lightning/trainer/data_loading.py index 83b59d21a7..7715d5e270 100644 --- a/pytorch_lightning/trainer/data_loading.py +++ b/pytorch_lightning/trainer/data_loading.py @@ -74,6 +74,15 @@ class TrainerDataLoadingMixin(ABC): raise ValueError(msg) def auto_add_sampler(self, dataloader: DataLoader, train: bool) -> DataLoader: + + # don't do anything if it's not a dataloader + if not isinstance(dataloader, DataLoader): + return dataloader + + # don't add sampler when user gives one + if dataloader.sampler is not None: + return dataloader + if self.use_ddp or self.use_ddp2 or self.use_tpu: dl_args = { 'dataset': dataloader.dataset, diff --git a/pytorch_lightning/trainer/distrib_parts.py b/pytorch_lightning/trainer/distrib_parts.py index 57e460feb6..f48b919bc2 100644 --- a/pytorch_lightning/trainer/distrib_parts.py +++ b/pytorch_lightning/trainer/distrib_parts.py @@ -250,8 +250,11 @@ You must configure your job submission script correctly for the trainer to work. .. note:: When running in DDP mode, any errors in your code will show up as an NCCL issue. Set the `NCCL_DEBUG=INFO` flag to see the ACTUAL error. -Finally, make sure to add a distributed sampler to your dataset. The distributed sampler copies a - portion of your dataset onto each GPU. (World_size = gpus_per_node * nb_nodes). +Normally now you would need to add a distributed sampler to your dataset, however +Lightning automates this for you. But if you still need to set a sampler Lightning will +not interfere nor automate it. + +Here's an example of how to add your own sampler (again no need with Lightning). .. code-block:: python