fix: use closed-form LR calculation to fix polynomial decay formula bug#67
Open
fix: use closed-form LR calculation to fix polynomial decay formula bug#67
Conversation
Problem: The get_lr() method had an incorrect formula for polynomial decay: LR(l) = (1/2 * group['lr']) * (1 + decay_factor) This is mathematically NOT equivalent to polynomial decay. Mathematical proof: - Let d(l) = decay_factor = f(l)/f(l-1) (the correct ratio) - Current formula computes: g(l) = (1 + d(l)) / 2 - For decaying schedule, 0 < d(l) < 1 - Therefore g(l) > d(l) always - Result: LR decays SLOWER than intended polynomial schedule The correct polynomial decay should be: LR(l) = base_lr * (1 - progress)^power Solution: Use the existing _get_closed_form_lr() which correctly computes: base_lr * (1 - (step - warmup) / (total - warmup))^power This also improves numerical stability by computing directly from base_lrs rather than accumulating incremental updates over millions of steps.
3b0d868 to
f7e7781
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
The
get_lr()method had a mathematically incorrect formula:Mathematical Proof
Let
d(l) = decay_factor(the correct ratio between consecutive steps)The code computes:
g(l) = (1 + d(l)) / 2For a decaying schedule where
0 < d(l) < 1:g(l) - d(l) = (1 - d(l)) / 2 > 0g(l) > d(l)alwaysResult: LR decays slower than the intended polynomial schedule.
Visual Impact
Solution
Use the existing
_get_closed_form_lr()which correctly computes:Additional Benefits
base_lrsinstead of accumulating incremental updatesFiles Changed
training/lr_scheduler.py- Replaceget_lr()implementation