# How to train LLM only on response

**URL:** <https://discuss.huggingface.co/t/how-to-train-llm-only-on-response/47293>\
**Category:** 🤗Transformers\
**Created:** [July 19, 2023, 7:35am UTC](https://discuss.huggingface.co/t/how-to-train-llm-only-on-response/47293 "2023-07-19T07:35:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sd3ntato](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sd3ntato](https://discuss.huggingface.co/u/sd3ntato)\
**Post date:** [July 19, 2023, 7:35am UTC](https://discuss.huggingface.co/t/how-to-train-llm-only-on-response/47293/1 "2023-07-19T07:35:29Z")

</div>

Hello, how do I train the model only on responses rather than prompt and response?

Is it just a matter of attention masks?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [July 24, 2023, 2:45pm UTC](https://discuss.huggingface.co/t/how-to-train-llm-only-on-response/47293/2 "2023-07-24T14:45:24Z")

</div>

Hi,

The easiest is to use the `SFTTrainer` of [trl](https://huggingface.co/docs/trl/index), combined with the `DataCollatorForCompletionOnlyLM`. The latter allows to only train on responses, and not on the prompts.

It’s brand new, we’re adding docs for it here: [Add `DataCollatorForCompletionOnlyLM` in the docs by younesbelkada · Pull Request #565 · lvwerra/trl · GitHub](https://github.com/lvwerra/trl/pull/565/files)

---

<div class="post-metadata">

**Author:** ![sd3ntato](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sd3ntato](https://discuss.huggingface.co/u/sd3ntato)\
**Post date:** [July 24, 2023, 2:46pm UTC](https://discuss.huggingface.co/t/how-to-train-llm-only-on-response/47293/3 "2023-07-24T14:46:24Z")

</div>

very interesting, thanks!
