Apply polyak_sgd's scaling after the Polyak step - #1796
Open
vineethsaivs wants to merge 1 commit into
Open
vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
polyak_sgd chained sgd(learning_rate=scaling) before scale_by_polyak, so the Polyak step was computed from the already scaled gradient. The step became gap / (scaling * ||g||^2) instead of the documented scaling * gap / ||g||^2, so a smaller scaling gave a larger step. Compute the Polyak step on the raw gradient first, then apply scaling.
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.
polyak_sgd(scaling=s)divides the step bysinstead of multiplying. It chainssgd(learning_rate=scaling)beforescale_by_polyak, so the Polyak step is computed from the already scaled gradient:gap / (s * ||g||^2)instead of the documenteds * min(gap / ||g||^2, max_learning_rate).On
f(x) = sum(x**2)at[1, 2, 3]withscaling=0.1, the update is[-2, -4, -6]instead of[-0.05, -0.1, -0.15].scaling=1is unaffected.Fix: run
scale_by_polyakon the raw gradient, then applyscaling. This swaps the two entries in the chained state.Test:
test_polyak_sgd_scalingchecks the update against the docstring formula. It fails on main for 0.5 and 0.1 and passes with the fix; alias, transform and contrib common tests pass.