-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
DPO trainer supports num_logits_to_keep to save memory #2129
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. |
@xyangk thank you! can you run the |
Sure! |
…ep_necessary_logits
…ep_necessary_logits
…ep_necessary_logits
Implemented the calculation of num_logits_to_keep on the new master code, fixed a bug in the previous calculation, and used more rigorous test code. |
Hi @kashif , I wanted to check in on this PR. Please let me know if there's anything further I can clarify or update. Thank you for your time and review! |
@xyangk can you use the transformers helper |
I've implemented the suggested changes. Thank you for the feedback! |
|
||
# num_logits_to_keep is supported since transformers v4.45.0 | ||
if self.use_num_logits_to_keep: | ||
check_min_version("4.45.0") |
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.
You don't need it
https://github.com/huggingface/trl/blob/main/setup.py#L82
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.
Sorry I missed that the transformers version was already updated. Since the current PR is already merged, I'll create a new PR to remove the version check. Thank you for cathing this!
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.
What does this PR do?
Since transformers v4.45.0 supports
num_logits_to_keep
in the forward pass(check this PR), it can be useful for saving memory and speeding up training by computing logits only for the last completion tokens, especially in scenarios with very long prompts where labels are ignored (-100).I implemented the logic to calculate
num_logits_to_keep
based on the labels and tested this on DPO, resulting in substantial memory savings.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.