Repository navigation
Conversation
This branch has not been deployed
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.
Problem
Shampoo updates a mode's Gram matrix and immediately applies its inverse factor to the gradient. The next mode then accumulates statistics from an already preconditioned gradient. All mode statistics should instead use the same gradient before any inverse factors are applied.
For gradient [[1, 2], [3, 4]] and epsilon=0.5, the second-mode statistic becomes approximately [[0.968, 0.364], [0.364, 1.227]] instead of [[10.5, 14], [14, 20.5]]. This changes subsequent preconditioning and parameter updates.
Change
Accumulate and refresh all mode factors first, then apply the factors to the gradient. The cached-factor update frequency, momentum/decay preparation, and existing matrix-power exponent are preserved.
Validation
Python 3.12.14, PyTorch 2.15.0+cpu:
git diff --check.The separate open #548 changes the matrix-power exponent. Its full diff was checked; this patch addresses the input statistics and retains the current exponent so the fixes remain separate concerns. CPU validation does not cover CUDA or the full historical CI matrix.