# New Version of PPOTrainer

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%3E%5C
**Category:** 🤗Transformers\
**Created:** [November 13, 2024, 9:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316 "2024-11-13T09:23:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrin](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mrin](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmrin)%5C
**Post date:** [November 13, 2024, 9:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F1 "2024-11-13T09:23:14Z")

</div>

Hi, I’m trying to create a PPO loop for the Gemma2b model, I have already trained my reward model.

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/7/2/72b5d4181157fc1d07d6e2665b9d50d6dcdf481e.png)

In the new class of PPOTrainer - policy, ref\_policy and reward\_model have type ‘module’ unlike the previous version of PPOTrainer.  
Now when I’m passing the huggingFace model as policy,ref\_policy and my trained reward model, I’m getting the following error -

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/d/0/d07a758563bbe434ac477f34496732c7bd30d0de.png)

what to pass in policy, ref\_policy and reward model ?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [November 13, 2024, 9:42am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F2 "2024-11-13T09:42:52Z")

</div>

This is the only example I could find…

> <https://github.com/huggingface/blog/blob/main/putting_rl_back_in_rlhf_with_rloo.md>

---

<div class="post-metadata">

**Author:** ![mrin](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mrin](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmrin)%5C
**Post date:** [November 14, 2024, 4:24am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F3 "2024-11-14T04:24:44Z")

</div>

but…I can’t understand how to pass huggingface Pretrained wrapper model as module in policy,ref\_policy and reward…could you please help me ?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [November 14, 2024, 5:18am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F4 "2024-11-14T05:18:06Z")

</div>

I have no idea, too. But maybe this?

```py
from transformers import (
    AutoModelForCausalLM,
    AutoModelForSequenceClassification,
    AutoTokenizer,
)

from trl.trainer.rloo_trainer import RLOOConfig, RLOOTrainer
from trl.trainer.utils import SIMPLE_QUERY_CHAT_TEMPLATE

base_model_name = "EleutherAI/pythia-1b-deduped"
tokenizer = AutoTokenizer.from_pretrained(base_model_name, padding_side="left")
tokenizer.add_special_tokens({"pad_token": "[PAD]"})
if tokenizer.chat_template is None:
    tokenizer.chat_template = SIMPLE_QUERY_CHAT_TEMPLATE
reward_model = AutoModelForSequenceClassification.from_pretrained(base_model_name, num_labels=1)
ref_policy = AutoModelForCausalLM.from_pretrained(base_model_name)
policy = AutoModelForCausalLM.from_pretrained(base_model_name)

train_dataset = ... # make sure to have columns "input_ids"
eval_dataset = ...

trainer = RLOOTrainer(
    config=RLOOConfig(
        per_device_train_batch_size=1,
        gradient_accumulation_steps=64,
        total_episodes=30000,
    ),
    tokenizer=tokenizer,
    policy=policy,
    ref_policy=ref_policy,
    reward_model=reward_model,
    train_dataset=train_dataset,
    eval_dataset=eval_dataset,
)
trainer.train()

```

---

<div class="post-metadata">

**Author:** ![mrin](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mrin](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmrin)%5C
**Post date:** [November 14, 2024, 8:07am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F5 "2024-11-14T08:07:29Z")

</div>

is it like DPOTrainer…I mean here we no need to write PPO training loop like we do in DPO ?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [November 14, 2024, 8:26am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F6 "2024-11-14T08:26:47Z")

</div>

You might be able to write it, but unlike DPOTrainer, PPOTrainer has a default value for the reward model path, so it seems to work without specifying any special options.  
However, there is so little documentation that it’s really hard to understand…

> **[PPO Trainer](https://huggingface.co/docs/trl/main/en/ppo_trainer#trl.PPOConfig.reward_model_path)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **reward\_model\_path** (`str`, _optional_, defaults to `"EleutherAI/pythia-160m"`) — Path to the reward model.

---

<div class="post-metadata">

**Author:** ![tuhinatripathi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/tuhinatripathi/32/26915_2.png) [@tuhinatripathi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftuhinatripathi)%5C
**Post date:** [November 24, 2024, 10:06pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fnew-version-of-ppotrainer%2F118316%2F7 "2024-11-24T22:06:45Z")

</div>

Hi! I’m also trying to write my own training loop for the PPOTrainer. The new version doesn’t even seem to have a ‘generate’ function to get the policy rollouts. If anyone has been able to find a workaround, that would be really helpful.
