# DataLoader implicitly using CPU?

**URL:** <https://discuss.pytorch.org/t/dataloader-implicitly-using-cpu/86923>\
**Category:** Uncategorized\
**Created:** [June 25, 2020, 4:53pm UTC](https://discuss.pytorch.org/t/dataloader-implicitly-using-cpu/86923 "2020-06-25T16:53:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [June 26, 2020, 9:42am UTC](https://discuss.pytorch.org/t/dataloader-implicitly-using-cpu/86923/2 "2020-06-26T09:42:43Z")

</div>

> [@pband1256](#):
>
> So I’m wondering if `DataLoader` is doing some implicit calls moving data from CPU to GPU or vice versa.

No, the `DataLoader` will load each sample from `Dataset. __getitem__ ` and use the `collate_fn` to create a batch out of these samples. It has no knowledge, if these tensors are on the CPU or GPU.

Your current approach of moving the data to the GPU in your `collate_fn` should have the same effect as moving the data to the device inside the training loop, since each batch will be pushed to the device, not the complete dataset.

For general information about data loading bottlenecks, I would recommend to have a look at [this post](https://discuss.pytorch.org/t/how-to-prefetch-data-when-processing-with-gpu/548/19).

---

_[View the full topic](https://discuss.pytorch.org/t/dataloader-implicitly-using-cpu/86923)._
