# TRL + PPO + Using Conditioned Reference Model

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrl-ppo-using-conditioned-reference-model%2F136361%3E%5C
**Category:** Intermediate\
**Created:** [January 18, 2025, 7:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrl-ppo-using-conditioned-reference-model%2F136361 "2025-01-18T19:48:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![velezbeltran](https://avatars.discourse-cdn.com/v4/letter/v/3ab097/32.png) [@velezbeltran](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvelezbeltran)%5C
**Post date:** [January 18, 2025, 7:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrl-ppo-using-conditioned-reference-model%2F136361%2F1 "2025-01-18T19:48:56Z")

</div>

Hello!

I am interested in using the TRL implementation of PPO. Normally for a reference model we compare p\_new(x) to p\_old(x) where both are LLMs. I was wondering if there was a straightforward way of comparing p\_new(x) to p\_old(x | c) where c is some conditioning prompt using the PPO class in TRL.

Thank you so much!

---

<div class="post-metadata">

**Author:** ![velezbeltran](https://avatars.discourse-cdn.com/v4/letter/v/3ab097/32.png) [@velezbeltran](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvelezbeltran)%5C
**Post date:** [January 26, 2025, 5:59pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrl-ppo-using-conditioned-reference-model%2F136361%2F2 "2025-01-26T17:59:10Z")

</div>

Update: I don’t think there is a way of doing this. However, it is fairly straightforward to just fork the repo and modify the source code yourself to implement this 🙂. This is what I ended up going for.

---

<div class="post-metadata">

**Author:** ![Alanturner2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alanturner2/32/37542_2.png) [@Alanturner2](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAlanturner2)%5C
**Post date:** [January 26, 2025, 11:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrl-ppo-using-conditioned-reference-model%2F136361%2F3 "2025-01-26T23:48:00Z")

</div>

That’s a great question! Comparing ( p\_{\text{new}}(x) ) to ( p\_{\text{old}}(x | c) ), where ( c ) is a conditioning prompt, is an interesting use case for PPO in TRL.

You’re right that the default implementation of TRL’s PPO is designed for ( p\_{\text{new}}(x) ) vs ( p\_{\text{old}}(x) ), so conditioning on ( c ) isn’t directly supported out of the box. However, your approach of forking the repo and modifying the source code is a solid solution! By introducing the conditioning logic directly into the PPO implementation, you should be able to adapt it to your use case.

If others are curious, one way to approach this might be to modify the way the reference model generates probabilities for the “old” distribution, ensuring that ( c ) is passed as input during evaluation. Specifically:

1. Update the `log_probs` computation to include ( c ) as part of the context.
2. Ensure that the `ref_model` in TRL is called with the same prompt ( c ) that you use for the policy model.

It’s awesome that you’ve already taken the initiative to make these changes. If you’re open to it, consider sharing your fork or a guide on how you implemented this—it could help others looking to do something similar.

Good luck with your work, and let us know how it turns out! 😊

---

<div class="post-metadata">

**Author:** ![velezbeltran](https://avatars.discourse-cdn.com/v4/letter/v/3ab097/32.png) [@velezbeltran](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvelezbeltran)%5C
**Post date:** [January 27, 2025, 5:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrl-ppo-using-conditioned-reference-model%2F136361%2F4 "2025-01-27T17:20:21Z")

</div>

What you are suggesting is exactly what I ended up doing. Thank you for the answer! I am still prototyping a bit so I don’t have stable code right now but if I end up with a working version I’ll make sure to share it. ☺
