Skip to content
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

🍭 Custom reward function for RLOO #2612

Merged
merged 8 commits into from
Jan 23, 2025

Conversation

August-murr
Copy link
Collaborator

Similar to #2540

Since RLOO doesn't use a value model, it's much simpler.

@HuggingFaceDocBuilderDev

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.

Comment on lines 1207 to 1209
texts = processor.batch_decode(query_responses, skip_special_tokens=True)
rewards = model(texts)
rewards = torch.tensor(rewards, dtype=torch.float).to(query_responses.device)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, since it's only three lines and used once, maybe you can put it directly in RLOO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it could be used in other trainers that use get_reward like ppo or online dpo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.
We can always limit duplication later, once we're sure that the same lines are used in PPO and OnlineDPO. In fact, I'd rather have duplicated code than utilities that you only use once.

@@ -79,7 +80,7 @@ def __init__(
],
policy: nn.Module,
ref_policy: nn.Module,
reward_model: nn.Module,
reward_model: Union[nn.Module, Callable],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reward_model: Union[nn.Module, Callable],
reward_model: Union[nn.Module, Callable[[list[str]], list[float]],

@qgallouedec
Copy link
Member

Nice!

Can be done in a follow-up PR, but it might make sense to rename reward_model to reward_func. See #2606 (comment) for more context.

@qgallouedec
Copy link
Member

Can you add a test in test_rloo_trainer with a naive reward func?

@August-murr
Copy link
Collaborator Author

Nice!

Can be done in a follow-up PR, but it might make sense to rename reward_model to reward_func. See #2606 (comment) for more context.

yea I think it's better to do it for all trainers in a separate PR

Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just need a unit test and we're good to merge

@qgallouedec qgallouedec changed the title RLOO custom reward function 🍭 Custom reward function for RLOO Jan 23, 2025
Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Feel free to merge when the CI is green (ignore dev dep that will fail)

@August-murr August-murr merged commit 0e216f7 into huggingface:main Jan 23, 2025
12 of 13 checks passed
@August-murr August-murr deleted the RLOO_custom_reward_trainer branch January 25, 2025 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants