-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use any reward model for online methods #2276
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
completions = self.processing_class.batch_decode( | ||
prompt_completion_ids[:, context_length:], skip_special_tokens=True | ||
) | ||
completions = [completion.strip() for completion in completions] # remove the leading space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need strip
Results for a gemma reward model
https://wandb.ai/huggingface/huggingface/runs/520cnnjl For ref, with Pair RM judge instead:
https://wandb.ai/huggingface/huggingface/runs/ffd4u5wa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR @qgallouedec - this will unlock so many combinations of policy with models on RewardBench 🔥 !
Have you done a test run of e.g. trying to optimise Qwen2.5-0.5B-Instruct with the 7B ArmoRM model?
|
||
trainer = OnlineDPOTrainer( | ||
... | ||
- judge=judge, | ||
+ reward_model=reward_model, | ||
+ reward_processing_class=reward_tokenizer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the reason to use a processing class in case we want to support other modalities beyond text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. And since the tokenizer
is now called processing_class
within trainers, I'd recommend always aligning with it (even if only the textual modality is supported). Unless you have a good reason not to.
@@ -93,8 +93,13 @@ | |||
trust_remote_code=model_config.trust_remote_code, | |||
**model_kwargs, | |||
) | |||
reward_tokenizer = AutoTokenizer.from_pretrained( | |||
training_args.reward_model_path, | |||
trust_remote_code=model_config.trust_remote_code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also set truncation=True
along with truncation_side="left"
to ensure the labels aren't lost on long inputs? We might also need to allow people to set max_length
since the context window of the tokenizer might be different from the policy - would that be best stored in the ScriptArguments
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for truncation, and truncation side. Not sure what's the best way to let the user set the max_length. Ok for doing this in a follow-up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to follow up in separate PR - it should generally be safe for RMs that define the max length implicitly in their config anyway
) | ||
# The reward model may not have the same chat template or tokenizer as the model, so we need to use the | ||
# raw data (string), apply the chat template (if needed), and tokenize it with the reward processing class. | ||
prompts = 2 * prompts # repeat the prompt: [prompt0, prompt1] -> [prompt0, prompt1, prompt0, prompt1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do this? Is it to align a prompt with chosen/rejected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, we have:
prompts = ["What color is the sky?", "What's the capital of France?"]
completions = ["Blue", "Lyon", "Green", "Paris"]
and later, we need to concat the prompts and the completions to compute the reward
prompt_completion_ids = torch.cat((prompts_ids, completions_ids), dim=1)
_, scores, _ = get_reward(
self.reward_model, prompt_completion_ids, self.reward_processing_class.pad_token_id, context_length
)
so we need to repeat the prompt.
ArmoRM is a custom classifier (its code for using it is not standard). So our https://wandb.ai/huggingface/huggingface/runs/merlfqgx (screenshot to come)
|
What does this PR do?
This PR allows any reward model to be used with Online DPO, i.e. it removes the requirement to have the same chat template and tokenizer.
The user must now provide
reward_processing_class
.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.