Skip to content

Commit 58a749a

Browse files
authored
Allow batch sampler to not have a .sampler attribute (#20514)
Allow a batchsampler to not have a sampler attribute
1 parent 52460d3 commit 58a749a

File tree

1 file changed

+5
-1
lines changed
  • src/lightning/pytorch/utilities

1 file changed

+5
-1
lines changed

src/lightning/pytorch/utilities/data.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ def _is_dataloader_shuffled(dataloader: object) -> bool:
351351
# shuffling is enabled via a sampler. No sampler, no shuffling
352352
return False
353353
batch_sampler = dataloader.batch_sampler
354-
sampler = batch_sampler.sampler if batch_sampler is not None else dataloader.sampler
354+
if batch_sampler is not None:
355+
# custom batch samplers may not have an internal .sampler
356+
sampler = batch_sampler.sampler if hasattr(batch_sampler, "sampler") else batch_sampler
357+
else:
358+
sampler = dataloader.sampler
355359
if isinstance(sampler, SequentialSampler):
356360
return False
357361
return isinstance(sampler, RandomSampler)

0 commit comments

Comments
 (0)