From 98f7842970fd593c21bebfdba5da8aa311d50730 Mon Sep 17 00:00:00 2001 From: Maxim Grechkin Date: Wed, 20 May 2020 13:57:12 -0700 Subject: [PATCH] Allow dataloaders without sampler field present (#1907) * Allow dataloaders without sampler field present Sometimes we have a custom dataloader that doesn't have a sampler, better to check that the field is there before reading it. * chlog Co-authored-by: Jirka --- CHANGELOG.md | 4 +++- pytorch_lightning/trainer/training_loop.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff2c124eafd63..12be131ac8e59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Add Metric Base Classes ([#1326](https://github.com/PyTorchLightning/pytorch-lightning/pull/1326), [#1877](https://github.com/PyTorchLightning/pytorch-lightning/pull/1877)) -- Added type hints in `Trainer.fit()` and `Trainer.test()` to reflect that also a list of dataloaders can be passed in ([#1723](https://github.com/PyTorchLightning/pytorch-lightning/pull/1723)). +- Added type hints in `Trainer.fit()` and `Trainer.test()` to reflect that also a list of dataloaders can be passed in ([#1723](https://github.com/PyTorchLightning/pytorch-lightning/pull/1723)) + +- Allow dataloaders without sampler field present ([#1907](https://github.com/PyTorchLightning/pytorch-lightning/pull/1907)) ### Changed diff --git a/pytorch_lightning/trainer/training_loop.py b/pytorch_lightning/trainer/training_loop.py index 576ecfb5973b5..61358731f796f 100644 --- a/pytorch_lightning/trainer/training_loop.py +++ b/pytorch_lightning/trainer/training_loop.py @@ -327,6 +327,7 @@ def train(self): self.reset_train_dataloader(model) # set seed for distributed sampler (enables shuffling for each epoch) if (self.use_ddp or self.use_horovod) \ + and hasattr(self.train_dataloader, 'sampler') \ and hasattr(self.train_dataloader.sampler, 'set_epoch'): self.train_dataloader.sampler.set_epoch(epoch)