Error while using custom DistributedSampler #7573
-
|
I wanted to set shuffle to False. So, i tried I am getting an error Please anyone tell me how to use custom sampler. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
You should set Regarding the error, can you provide a script to reproduce it? You can adapt https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/bug_report_model.py |
Beta Was this translation helpful? Give feedback.
-
|
Adding on to the existing answer:
When using DDP, Lightning takes your dataloader and replaces it with the following So OP can do the following: def train_dataloader(self):
return DataLoader(sampler=DistributedSampler(shuffle=False), ...)`returning their own sampler. Note this needs to be done in a place where the distributed group is already initialized, so basically in any hook after (including) Because they probably did the following: dataloader = DataLoader(sampler=DistributedSampler(shuffle=False), ...) # fails here, because distributed not init yet
trainer = Trainer()
trainer.fit(dataloader) |
Beta Was this translation helpful? Give feedback.
Adding on to the existing answer:
DataLoader(shuffle, sampler)are mutually exclusive, i.e., if you setshuffle=Trueyou will get aRandomSamplerand if it is set to False you get aSequentialSampler.When using DDP, Lightning takes your dataloader and replaces it with the following
DataLoader(sampler=DistributedDampler(shuffle=True), ...), however ONLY if the sampler is not already a distributed sampler. If it is, no changes are done.So OP can do the following:
returning their own sampler. Note this needs to be done in a place where the distributed group is already initialized, so basicall…