Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use property in connector for sampler #5913

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytorch_lightning/accelerators/accelerator_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def use_ddp2(self):
def use_horovod(self):
return self._distrib_type == DistributedType.HOROVOD

@property
def is_distributed(self):
return self.use_ddp or self.use_ddp2 or self.use_horovod or self.on_tpu

@property
def num_gpus(self) -> int:
gpus = self.parallel_device_ids
Expand Down
6 changes: 3 additions & 3 deletions pytorch_lightning/trainer/data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def auto_add_sampler(self, dataloader: DataLoader, shuffle: bool) -> DataLoader:
if not is_dataloader or is_iterable_ds:
return dataloader

is_in_dist = self.use_ddp or self.use_ddp2 or self.use_horovod or self.use_tpu

need_dist_sampler = is_in_dist and not isinstance(dataloader.sampler, DistributedSampler)
need_dist_sampler = self.accelerator_connector.is_distributed and not isinstance(
dataloader.sampler, DistributedSampler
)
if self.accelerator_connector.replace_sampler_ddp and need_dist_sampler:
if not isinstance(dataloader.sampler, (SequentialSampler, RandomSampler)):
raise MisconfigurationException(
Expand Down