Skip to content

Keep the paper momentum sum available without changing the default - #71

Open
shaneraphel wants to merge 1 commit into
KellerJordan:masterfrom
shaneraphel:momentum-sum
Open

shaneraphel wants to merge 1 commit into
KellerJordan:masterfrom
shaneraphel:momentum-sum

Conversation

@shaneraphel

@shaneraphel shaneraphel commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary

Adds an opt-in momentum_sum flag to muon_update and to the Muon and SingleDeviceMuon constructors. The default is False, and with the flag off the update is bitwise identical to the current code.

The shipped momentum is the exponential moving average buf = β·buf + (1−β)·G, written as momentum.lerp_(grad, 1 - beta). The form in the Muon paper and in the Moonshot reference is the plain sum buf = β·buf + G. The two differ by a constant factor of 1/(1−β) once the buffer has warmed up (about 20× at the default β of 0.95), so swapping the default would silently rescale every existing run. The flag keeps the current behaviour and makes the paper's form available.

With the flag on, Nesterov reads grad + β·buf and the plain case reads buf, matching the reference. MuonWithAuxAdam and SingleDeviceMuonWithAuxAdam read the flag with group.get("momentum_sum", False) and do not grow their asserted group-key set.

Test plan

  • python test_momentum_sum.py — from a zero buffer one step stores G with the flag and 0.05·G without it (β = 0.95); the second step stores β·G + G₂; the default flag is bitwise identical to omitting it.
  • Training comparison on a small CPU network (800 steps, 3 seeds, Apple M4, float32): both the default and momentum_sum=True reach a mean final loss around 1e-10, so the paper's form trains at least as well as the shipped one on this problem. The difference is the scale of the buffer, not whether the run converges.

This change was produced with assistance from an AI coding tool. I wrote the flag, ran the tests and the training comparison locally, and checked that the default path is unchanged.

The shipped update is the running average beta*B+(1-beta)*G. The
write-up uses B <- beta*B+G. momentum_sum selects that recurrence
and leaves the default path unchanged.
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