Skip to content

Accumulate Shampoo mode statistics before preconditioning - #568

Open
Afloat16 wants to merge 1 commit into
jettify:masterfrom
Afloat16:fix/shampoo-unpreconditioned-grams-20261112
Open

Afloat16 wants to merge 1 commit into
jettify:masterfrom
Afloat16:fix/shampoo-unpreconditioned-grams-20261112

Conversation

@Afloat16

Copy link
Copy Markdown

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:

  • New tests: 6 failed / 5 passed before; 11 passed after. Independent tensor contractions compute each raw-gradient Gram matrix; eigendecomposition supplies an update oracle. Cases cover scalar through four-dimensional parameters, two factor-refresh frequencies, several steps, and actual checkpoint continuation.
  • The existing Shampoo neural-network convergence test passes before and after.
  • Changed files pass Black 23.3.0, isort 5.9.3, pycodestyle, pyflakes, and 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.

This branch has not been deployed

No deployments
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