Skip to content

Add the cautious optimizer to AdamP.#2657

Merged
rwightman merged 3 commits intohuggingface:mainfrom
Yuan-Jinghui:main
Jan 28, 2026
Merged

Add the cautious optimizer to AdamP.#2657
rwightman merged 3 commits intohuggingface:mainfrom
Yuan-Jinghui:main

Conversation

@Yuan-Jinghui
Copy link
Copy Markdown
Contributor

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

  1. We added an optional caution parameter to the adamp file. When set to True, the cautious mask is applied.
  2. We added the optimizer name cadamp to _optim_factory.py.
  3. We added tests for cadamp in test_optim.py.

Test Results
We tested the PR and obtained the following results:

tests/test_optim.py::test_optim_factory[cadamp] PASSED
tests/test_optim.py::test_cadamp[cadamp] PASSED

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

A cautious optimizer is applied to the parameters: spherical parameters use the spherical cautious optimizer, while general parameters use the standard cautious optimizer.
@rwightman
Copy link
Copy Markdown
Collaborator

@Yuan-Jinghui thanks, I'll do a few quick trials myself once CI passes and merge soon if nothing comes up

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@Yuan-Jinghui
Copy link
Copy Markdown
Contributor Author

@Yuan-Jinghui thanks, I'll do a few quick trials myself once CI passes and merge soon if nothing comes up

Thank you for your reply! Please feel free to leave a comment if you have any questions or concerns.

@rwightman rwightman merged commit 17b9764 into huggingface:main Jan 28, 2026
22 checks passed
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.

3 participants