Skip to content

Log the correct learning rate #36973

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

Merged
merged 4 commits into from
Mar 26, 2025
Merged

Log the correct learning rate #36973

merged 4 commits into from
Mar 26, 2025

Conversation

SunMarc
Copy link
Member

@SunMarc SunMarc commented Mar 25, 2025

What does this PR do?

The Trainer class steps the learning rate scheduler at the end of each training loop iteration before calling Trainer._maybe_log_save_evaluate(). As a result, the logged learning rate is the learning rate of the next training step, not the one that was just performed. This off-by-one error is usually not much of a problem with monotonic schedulers, but with cycling schedulers such as cosine_with_restarts, it can be the difference between something very close to zero and the max learning rate at cycle boundaries.

Fixes #35942
Similar to #30169

@github-actions github-actions bot marked this pull request as draft March 25, 2025 17:30
Copy link
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers.

@SunMarc SunMarc marked this pull request as ready for review March 25, 2025 17:30
@github-actions github-actions bot requested a review from muellerzr March 25, 2025 17:31
@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
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Looks good on my end, thanks for giving this a go!

@SunMarc SunMarc requested a review from qgallouedec March 26, 2025 15:36
@SunMarc
Copy link
Member Author

SunMarc commented Mar 26, 2025

This might potentially break trl dpo_online trainer I think @qgallouedec

@qgallouedec
Copy link
Member

Thank you! I will check and correct TRL if necessary. But feel free to merge, I can do it once merged.

@SunMarc SunMarc merged commit 79d6f9f into main Mar 26, 2025
26 checks passed
@SunMarc SunMarc deleted the fix-lr-log branch March 26, 2025 15:52
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
* fix learning rate log

* fix lr log

* add lr
soghomon-b pushed a commit to soghomon-b/transformers that referenced this pull request Aug 24, 2025
* fix learning rate log

* fix lr log

* add lr
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.

Learning rate logging off by one training step
4 participants