# How to get a Dataloader from a Trainer?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-a-dataloader-from-a-trainer%2F47626%3E%5C
**Category:** Beginners\
**Created:** [July 21, 2023, 2:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-a-dataloader-from-a-trainer%2F47626 "2023-07-21T14:44:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![univanxx](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/univanxx/32/39595_2.png) [@univanxx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Funivanxx)%5C
**Post date:** [July 21, 2023, 2:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-a-dataloader-from-a-trainer%2F47626%2F1 "2023-07-21T14:44:48Z")

</div>

Hello, does anyone know how to get a train Dataloader from a Trainer? I need it to compute some metrics during training process on a training dataset but I don’t want to initialize Dataloader twice due to memory limits.

Or does transformers Trainer us it’s own data storage structures? It would be great to hear some advices!

---

<div class="post-metadata">

**Author:** ![univanxx](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/univanxx/32/39595_2.png) [@univanxx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Funivanxx)%5C
**Post date:** [July 21, 2023, 4:24pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-a-dataloader-from-a-trainer%2F47626%2F2 "2023-07-21T16:24:18Z")

</div>

Well, I found it. I`m using [on\_evaluate()](https://huggingface.co/docs/transformers/main_classes/callback#transformers.TrainerCallback.on_evaluate) callback and train\_dataloader parameter is contained in the [\*\*kwargs argument](https://github.com/huggingface/transformers/blob/e42587f596181396e1c4b63660abf0c736b10dae/src/transformers/trainer_callback.py#L179-L180) of this function.

---

<div class="post-metadata">

**Author:** ![Thytu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/thytu/32/57554_2.png) [@Thytu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FThytu)%5C
**Post date:** [March 5, 2024, 7:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-a-dataloader-from-a-trainer%2F47626%2F3 "2024-03-05T19:19:27Z")

</div>

Answering here as I ask myself the same question few days ago:

`Trainer` does indeed provide a way to retrieve the dataloader(s), actually it even provide three methods:

- `trainer.get_train_dataloader()`
- `trainer.get_eval_dataloader()`
- `trainer.get_test_dataloader()`

By utilizing these methods you can access the dataloaders without needing to initialize new ones.  
I hope this response (even late) proves itself helpful to someone ^^
