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

Use wrapped model for reference completions in WinRateCallback and set default freq to eval_steps in LogCompletionsCallback` #2074

Merged
merged 6 commits into from
Sep 18, 2024

Conversation

lewtun
Copy link
Member

@lewtun lewtun commented Sep 16, 2024

What does this PR do?

While training some models with GKDTrainer I ran into an issue with ZeRO-3 and WinRateCallback where the initial model provided by the callback is unwrapped and this incompatible with unwrap_model_for_generation(). I also realised that using eval_steps is far more intuitive for both WinRateCallback and LogCompletionsCallback because we usually reserve logging for fast computations like the loss, and LogCompletionsCallback produces a major bottleneck in the logging if we generate every logging_steps.

This PR fixes both issues

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.

@@ -253,7 +253,8 @@ def on_train_begin(self, args: TrainingArguments, state: TrainerState, control:
tokenizer = kwargs["tokenizer"]
tokenizer.padding_side = "left"
accelerator = self.trainer.accelerator
model = getattr(self.trainer, "ref_model", kwargs["model"]) # get the ref model if any, else use the model
# Use the reference model if available, otherwise use the initial model
model = getattr(self.trainer, "ref_model", self.trainer.model_wrapped)
Copy link
Member

Choose a reason for hiding this comment

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

Does it work in the peft case? ie when ref_model is None?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh good catch - let me see if I can write a unit test for this case

Copy link
Member Author

Choose a reason for hiding this comment

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

Test added here with some minor cleanup to reuse the same expected winrates across tests: 592a088

Copy link
Member Author

Choose a reason for hiding this comment

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

OK to merge @qgallouedec or would you like some final changes?

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

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.

LGTM, just added a suggestion for a comment

lewtun and others added 2 commits September 18, 2024 13:18
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
@lewtun lewtun merged commit 4d82676 into main Sep 18, 2024
10 checks passed
@lewtun lewtun deleted the fix-wr branch September 18, 2024 11:55
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.

4 participants