Accelerator .prepare() replaces custom DataLoader Sampler
I want to use a DataLoader that uses a custom sampler you can find atvision/references/classification/sampler.py at main · pytorch/vision · GitHubWhen doing :print(dataset, dataset.sampler)
dataset = accelerator.prepare(dataset)
print(dataset, dataset.sampler)I get the following print:<torch.utils.data.dataloader.DataLoader object at 0x7f987fbc4e50> <utils.imagenet_dataloader.RASampler object at 0x7f987fbc4e20>
<accelerate.data_loader.DataLoaderShard object at 0x7f98518b6da0> <torch.utils.data.sampler.SequentialSampler object at 0x7f98518b6b60>This means that my RASampler got turned into a SequentialSampler.Is this a normal behaviour? Since it seems I can’t manually restore my sampler afterwhile, this is quite a problem.Could you tell me how to solve this problem?
2024-02-03T15:53:24Z
Hi@HTessDid you find a solution to this?
2024-02-03T16:48:58Z
HTess:Is this a normal behaviour? Since it seems I can’t manually restore my sampler afterwhile, this is quite a problem.Yes. The original sampler is still there I think as well? Can you checksampler.sampler? Orsampler.batch_sampler
2024-02-03T17:13:48Z
Hi@muellerzrI wanted to use a custom sampler with my dataloader. Will the sampler behaviour remain the same after passing throughaccelerate.prepare()? Or will it be changed to aSequentialSampler()?
2024-02-03T17:16:18Z
As mentioned, the custom sampler will be used. This new sampler is simply just distributing all of the batch across your GPUs. So it goes old sampler → new sampler to dispatch.To test this, you can try including aprintstatement in your custom sampler and iterate afterprepare