# Change training data in Trainer with callback

**URL:** <https://discuss.huggingface.co/t/change-training-data-in-trainer-with-callback/26610>\
**Category:** 🤗Transformers\
**Created:** [November 23, 2022, 10:13pm UTC](https://discuss.huggingface.co/t/change-training-data-in-trainer-with-callback/26610 "2022-11-23T22:13:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpcorb20](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jpcorb20](https://discuss.huggingface.co/u/jpcorb20)\
**Post date:** [November 23, 2022, 10:13pm UTC](https://discuss.huggingface.co/t/change-training-data-in-trainer-with-callback/26610/1 "2022-11-23T22:13:34Z")

</div>

Can we change the train\_dataset during training using a custom Trainer callback?

Thanks,

---

<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:** [November 28, 2022, 6:30pm UTC](https://discuss.huggingface.co/t/change-training-data-in-trainer-with-callback/26610/2 "2022-11-28T18:30:36Z")

</div>

I don’t think that’s possible no. To customize your own training loop, we really recommend using Accelerate.

---

<div class="post-metadata">

**Author:** ![Indramal](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/indramal/32/61744_2.png) [@Indramal](https://discuss.huggingface.co/u/Indramal)\
**Post date:** [November 29, 2022, 2:57am UTC](https://discuss.huggingface.co/t/change-training-data-in-trainer-with-callback/26610/3 "2022-11-29T02:57:03Z")

</div>

Use a function for the dataset to insert data without a callback.

NOTE: I did not check but can be possible.

Also can combine multiple datasets.

---

<div class="post-metadata">

**Author:** ![jpcorb20](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jpcorb20](https://discuss.huggingface.co/u/jpcorb20)\
**Post date:** [November 29, 2022, 10:39pm UTC](https://discuss.huggingface.co/t/change-training-data-in-trainer-with-callback/26610/4 "2022-11-29T22:39:00Z")

</div>

Thanks for the replies!

Actually, I came up with a hack to stop the training based on a criteria using a custom callback. Then, I computed what I needed to change the training data and I overwrote it in the trainer after. Finally, I expanded the training epochs in the arguments to continue the training afterwards.
