Skip to content

Commit 7de51f7

Browse files
Sampler (#1318)
* sampler * sampler * sampler * check for dataloader type * check for dataloader type
1 parent aca8c7e commit 7de51f7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2424

2525
### Changed
2626

27+
- Does not interfere with a default sampler ([#1318](https://github.com/PyTorchLightning/pytorch-lightning/pull/1318))
2728
- Enhanced load_from_checkpoint to also forward params to the model ([#1307](https://github.com/PyTorchLightning/pytorch-lightning/pull/1307))
2829
- Made `evalaute` method private >> `Trainer._evaluate(...)`. ([#1260](https://github.com/PyTorchLightning/pytorch-lightning/pull/1260))
2930

pytorch_lightning/trainer/data_loading.py

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def _percent_range_check(self, name: str) -> None:
7474
raise ValueError(msg)
7575

7676
def auto_add_sampler(self, dataloader: DataLoader, train: bool) -> DataLoader:
77+
78+
# don't do anything if it's not a dataloader
79+
if not isinstance(dataloader, DataLoader):
80+
return dataloader
81+
82+
# don't add sampler when user gives one
83+
if dataloader.sampler is not None:
84+
return dataloader
85+
7786
if self.use_ddp or self.use_ddp2 or self.use_tpu:
7887
dl_args = {
7988
'dataset': dataloader.dataset,

pytorch_lightning/trainer/distrib_parts.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,11 @@
250250
.. note:: When running in DDP mode, any errors in your code will show up as an NCCL issue.
251251
Set the `NCCL_DEBUG=INFO` flag to see the ACTUAL error.
252252
253-
Finally, make sure to add a distributed sampler to your dataset. The distributed sampler copies a
254-
portion of your dataset onto each GPU. (World_size = gpus_per_node * nb_nodes).
253+
Normally now you would need to add a distributed sampler to your dataset, however
254+
Lightning automates this for you. But if you still need to set a sampler Lightning will
255+
not interfere nor automate it.
256+
257+
Here's an example of how to add your own sampler (again no need with Lightning).
255258
256259
.. code-block:: python
257260

0 commit comments

Comments
 (0)