Skip to content

Apply polyak_sgd's scaling after the Polyak step - #1796

Open
vineethsaivs wants to merge 1 commit into
google-deepmind:mainfrom
vineethsaivs:fix-polyak-sgd-scaling
Open

vineethsaivs wants to merge 1 commit into
google-deepmind:mainfrom
vineethsaivs:fix-polyak-sgd-scaling

Conversation

@vineethsaivs

Copy link
Copy Markdown

polyak_sgd(scaling=s) divides the step by s instead of multiplying. It chains sgd(learning_rate=scaling) before scale_by_polyak, so the Polyak step is computed from the already scaled gradient: gap / (s * ||g||^2) instead of the documented s * min(gap / ||g||^2, max_learning_rate).

On f(x) = sum(x**2) at [1, 2, 3] with scaling=0.1, the update is [-2, -4, -6] instead of [-0.05, -0.1, -0.15]. scaling=1 is unaffected.

Fix: run scale_by_polyak on the raw gradient, then apply scaling. This swaps the two entries in the chained state.

Test: test_polyak_sgd_scaling checks 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.

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

1 participant