About the behavior of dataloader

Hi there,

I am current using the dataloader (torch.utils.data.DataLoader) to get batches for model training.

By default, is each sample selected exactly once in one epoch? A epoch is defined as follows:

for epoch in range(10):
    for j, (inputs, labels, _) in enumerate(dataloader):


By default the DataLoader will use a SequentialSampler, if shuffle=False, otherwise RandomSampler with the default argument replacement=False, which would yield each sample only once in each epoch.

1 Like

Just one more question:

In the follow combinations, each sample is selected exactly once in one epoch, is that correct?

  1. Default DataLoader with SequentialSampler, shuffle=False
  2. Dataloader with RandomSampler, shuffle=True, replacement=False.

Thanks again.

Yes, that’s correct.

1 Like