Toggling off 'shuffle' of a dataloader

I’d like to toggle off the shuffle attribute of a dataloader after certain point in my code. Can I do so without creating the dataloader again?

The shuffle argument determined which sampler will be created (RandomSampler or SequentialSampler as seen here) and is not directly used as an attribute in the DataLoader. For this reason I would not recommend to try to replace the internal sampler, but to recreate the DataLoader instead. If you are lazily loading the data in your Dataset, the initialization of the DataLoader should also be cheap.

1 Like

just faced this problem… very outdated, but I hope help someone like me now… hehehhe
In my case, I was working in a function that receive only the dataloader. In fact, you can retrieve the dataset with “dataloader.dataset” and with this you can reset the dataloader,as @ptrblck proposed, without access dataset directly, … see the example below:

import torch

my_dataloader =torch.utils.data.DataLoader(my_dataloader.datasaset,
batch_size=my_dataloader.batch_size,shuffle=False)