# Can accelerator handle the distributed sampler?

**URL:** <https://discuss.huggingface.co/t/can-accelerator-handle-the-distributed-sampler/12943>\
**Category:** 🤗Accelerate\
**Created:** [December 18, 2021, 10:25am UTC](https://discuss.huggingface.co/t/can-accelerator-handle-the-distributed-sampler/12943 "2021-12-18T10:25:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezio98](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@ezio98](https://discuss.huggingface.co/u/ezio98)\
**Post date:** [December 18, 2021, 10:25am UTC](https://discuss.huggingface.co/t/can-accelerator-handle-the-distributed-sampler/12943/1 "2021-12-18T10:25:20Z")

</div>

As far as I know, for Pytorch, RandomSampler can not be directly used in the distributed data parallel training since `DistributedSampler` is desired (this [link](https://discuss.pytorch.org/t/how-to-use-my-own-sampler-when-i-already-use-distributedsampler/62143) discusses the problem). I am wondering whether `accelerator.prepare(dataloader)` handles the data split for multiple GPUs if I use the `RandomSampler`, so that the sub-dataset on each device are exclusive.

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [December 20, 2021, 1:53pm UTC](https://discuss.huggingface.co/t/can-accelerator-handle-the-distributed-sampler/12943/2 "2021-12-20T13:53:49Z")

</div>

You don’t have to worry about using a distributed sampler with Accelerate. Whatever your sampler is, Accelerate will automatically shard it for all processes.

---

<div class="post-metadata">

**Author:** ![ezio98](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@ezio98](https://discuss.huggingface.co/u/ezio98)\
**Post date:** [December 21, 2021, 1:47am UTC](https://discuss.huggingface.co/t/can-accelerator-handle-the-distributed-sampler/12943/3 "2021-12-21T01:47:44Z")

</div>

That’s great! Thanks!
