Skip to content

Commit

Permalink
Allow a batchsampler to not have a sampler attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
lantiga committed Dec 20, 2024
1 parent 52460d3 commit 683c351
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lightning/pytorch/utilities/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ def _is_dataloader_shuffled(dataloader: object) -> bool:
# shuffling is enabled via a sampler. No sampler, no shuffling
return False
batch_sampler = dataloader.batch_sampler
sampler = batch_sampler.sampler if batch_sampler is not None else dataloader.sampler
if batch_sampler is not None:
# custom batch samplers may not have an internal .sampler
sampler = batch_sampler.sampler if hasattr(batch_sampler, "sampler") else batch_sampler
else:
sampler = dataloader.sampler
if isinstance(sampler, SequentialSampler):
return False
return isinstance(sampler, RandomSampler)

0 comments on commit 683c351

Please sign in to comment.