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

[Judges] rlhflow pairwise judges #2548

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kashif
Copy link
Collaborator

@kashif kashif commented Jan 7, 2025

What does this PR do?

add support for RLHFlow based pairwise judge

@kashif kashif requested a review from qgallouedec January 7, 2025 17:02
@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.

for prompt, completion_pair in zip(batch_prompts, batch_completions):
# Convert prompt to chat format
instruction = [{"role": "user", "content": prompt}]
context = self.tokenizer_plain.apply_chat_template(instruction, tokenize=False)
Copy link
Member

Choose a reason for hiding this comment

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

I recommend using trl.apply_chat_template from the trl data utils here. We've encountered several issues in the past when applying chat templates to partial sequences, and this approach would be more robust.

While one could argue that we control the chat template in this context, using trl.apply_chat_template ensures that any future modifications to the chat template won't introduce unexpected issues here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so both this and the below changes are how the RLHF model recommends to do the scoring... I can check if it works using the chat template


self.tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
self.tokenizer_plain = AutoTokenizer.from_pretrained(model_name, use_fast=True)
self.tokenizer_plain.chat_template = "\n{% for message in messages %}{% if loop.index0 % 2 == 0 %}\n\n<turn> user\n {{ message['content'] }}{% endif %}{% endfor %}"
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to override the chat template btw?

@qgallouedec
Copy link
Member

From their demo code, this is what I get as input for the model:

<|start_header_id|>user<|end_header_id|>

[CONTEXT] 

<turn> user
 Ellipsis
<turn> assistant
 Ellipsis
<turn> user
 Ellipsis
 [RESPONSE A] BBBB [RESPONSE B] CCCC<|eot_id|>

doesn't make much sense to me:

  • numerous unnecessary whitespaces
  • Why <|start_header_id|>user<|end_header_id|>?
  • Why responses aren't surrounded by \n as well?
  • Why <eot_id> if you want to further generate?

Why not something like this instead:

[CONTEXT]
<turn> user
Ellipsis
<turn> assistant
Ellipsis
<turn> user
Ellipsis

[RESPONSE A]
BBBB

[RESPONSE B]
CCCC

[BEST REPONSE]

@kashif
Copy link
Collaborator Author

kashif commented Jan 7, 2025

you are using the instructions from here: https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B right?

@qgallouedec
Copy link
Member

you are using the instructions from here: https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B right?

precisely

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