Add the cautious optimizer to AdamP.#2657
Merged
rwightman merged 3 commits intohuggingface:mainfrom Jan 28, 2026
Merged
Conversation
A cautious optimizer is applied to the parameters: spherical parameters use the spherical cautious optimizer, while general parameters use the standard cautious optimizer.
Collaborator
|
@Yuan-Jinghui thanks, I'll do a few quick trials myself once CI passes and merge soon if nothing comes up |
|
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. |
Contributor
Author
Thank you for your reply! Please feel free to leave a comment if you have any questions or concerns. |
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.
Hi rwightman,
This PR aims to add a cautious optimizer to AdamP.
Motivation / Principle
You are already familiar with the cautious optimizer and have integrated it into most optimizers. Our goal is to extend this idea to AdamP. AdamP separates parameters into two parts: one part lies on a sphere and is updated along tangent directions, while the other part is updated in the standard way. When applying a cautious optimizer to spherical parameters, the update should preserve the feature-learning direction (i.e., alignment of tangent-direction signs). Other parameters can use the standard cautious mask. This is the core idea behind our modification. We also wrote a short document explaining why this design is reasonable [1].
Changes
cautionparameter to theadampfile. When set toTrue, the cautious mask is applied.cadampto_optim_factory.py.cadampintest_optim.py.Test Results
We tested the PR and obtained the following results:
That is, all tests pass successfully.
Recent work [2,3] has shown that constraining parameters to lie on a sphere can significantly improve performance. We believe that the spherical cautious optimizer can serve as a useful plugin for spherical-constrained optimization. We hope you can review this PR at your convenience.
References:
[1] https://openreview.net/forum?id=4lTJbNpWr3
[2] https://psychedelic-sunstone-851.notion.site/Fantastic-Pretraining-Optimizers-and-Where-to-Find-Them-2-1-Hyperball-Optimization-2e924306e6f280e7a5ffee00eb40a0dd
[3] https://arxiv.org/abs/2601.08393
Best regards,
Jinghui