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

Standardise API for WinRateCallback and LogCompletionsCallback #2061

Merged
merged 17 commits into from
Sep 13, 2024

Conversation

lewtun
Copy link
Member

@lewtun lewtun commented Sep 12, 2024

What does this PR do?

This PR unifies the API for the WinRate and LogCompletion callbacks (previously, the latter required the prompts to be passed manually, sampling was tied to the training config etc). The new way to use them is as follows:

judge = PairRMJudge()
generation_config = GenerationConfig(max_new_tokens=256)
win_rate_callback = WinRateCallback(
    judge=judge, trainer=trainer, generation_config=generation_config, num_prompts=32
)
log_callback = LogCompletionsCallback(trainer=trainer, generation_config=generation_config, num_prompts=8)
trainer.add_callback(win_rate_callback)
trainer.add_callback(log_callback)

Doing so allowed me to also fix a bug we had in LogCompletionCallback where ZeRO-3 would hang during generation (the trick is to access and unwrap the model from the trainer with unload_model_for_generation())

Scripts tested

  • DPO (DDP & Z3)
  • GKD
  • XPO
  • Online DPO

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines.
  • Did you write any new necessary tests?

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.

@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.

@@ -17,7 +17,7 @@
python examples/scripts/gkd.py \
--model_name_or_path Qwen/Qwen2-0.5B-Instruct \
--teacher_model_name_or_path Qwen/Qwen2-1.5B-Instruct \
--dataset_name andito/chatbot_arena_completions \
--dataset_name trl-lib/chatbot_arena_conversations \
Copy link
Member Author

Choose a reason for hiding this comment

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

I switched to this dataset since the original doesn't have an eval split

trl/trainer/callbacks.py Outdated Show resolved Hide resolved
@lewtun lewtun changed the title [WIP] Standardise API for WinRateCallback and LogCompletionsCallback Standardise API for WinRateCallback and LogCompletionsCallback Sep 13, 2024
@lewtun lewtun marked this pull request as ready for review September 13, 2024 10:07
@lewtun lewtun requested a review from edbeeching September 13, 2024 10:07
examples/scripts/gkd.py Outdated Show resolved Hide resolved
trl/trainer/callbacks.py Outdated Show resolved Hide resolved
@@ -62,7 +62,7 @@
"ddpo_config": ["DDPOConfig"],
"gkd_trainer": ["GKDTrainer"],
"gkd_config": ["GKDConfig"],
"callbacks": ["RichProgressCallback", "SyncRefModelCallback", "WinRateCallback"],
"callbacks": ["RichProgressCallback", "SyncRefModelCallback", "WinRateCallback", "LogCompletionsCallback"],
Copy link
Member Author

Choose a reason for hiding this comment

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

I unified the import path for the callbacks too

@qgallouedec
Copy link
Member

LGTM, it looks way better now!

@lewtun lewtun merged commit 88bede6 into main Sep 13, 2024
10 checks passed
@lewtun lewtun deleted the fix-completions-cbk branch September 13, 2024 15:38
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