Repository navigation
Improve shampoo update scale - #306
Conversation
|
8835476 to
4fdc833
Compare
| trace_exp = 1 / p_root_inv - (0.5 if kl_corrected else 0.25) | ||
| scale: float | torch.Tensor = (size_out * size_in) ** (0.5 - 1 / p_root_inv) | ||
| if trace_exp != 0: | ||
| scale = scale * (L.trace().clamp_min(eps) ** trace_exp) * (R.trace().clamp_min(eps) ** trace_exp) |
There was a problem hiding this comment.
Unbalanced KL factors change scaling If
KlShampoo(p_root_inv=4) has one factor trace below eps while the product of the traces remains finite, clamping each trace separately changes the update scale. KL factors can represent the same gradient statistics with different left/right splits, so this can make an otherwise equivalent update substantially smaller than the intended normalization.
Knowledge Base Used: Second-order preconditioning systems
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
@greptile It is valid but too rare of a case, ignore.
There was a problem hiding this comment.
Understood — I’ll treat this as an acceptable edge case and won’t pursue the finding further for this PR.
|
/ok to test 4fdc833 |
@skyw, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 4fdc833 |
@skyw, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
4fdc833 to
15aa571
Compare
|
/ok to test 15aa571 |
@skyw, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 9952428 |
@skyw, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
| kl_corrected: bool = False, | ||
| eps: float, | ||
| ) -> float | torch.Tensor: | ||
| """Get the scale for the Shampoo update. |
There was a problem hiding this comment.
Scaling guidance removed The deleted explanation was the only guidance that the default spectral scale targets unit RMS for AdamW-like learning rates and that trace dependence disappears at root order 4 for Shampoo or 2 for KL-Shampoo. The remaining docstring names the modes but does not explain this behavior, making it harder to choose a mode or root order without unintentionally changing update magnitude. Please retain the practical selection guidance, even if the full derivation is too long.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
/ok to test 9952428 |
Test Results 99 files ± 0 200 suites +2 2m 21s ⏱️ +11s Results for commit 9952428. ± Comparison against base commit 8b775b5. This pull request removes 1 and adds 84 tests. Note that renamed tests count towards both. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Signed-off-by: Hao Wu <skyw@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Hao Wu <skyw@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com>
56729f9 to
5501414
Compare
|
/ok to test 5501414 |
@skyw, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
Support different scaling method to match RMS of AdamW and other optimizer.