Skip to content

Skip weight decay when the gradient is missing - #69

Open
shaneraphel wants to merge 1 commit into
KellerJordan:masterfrom
shaneraphel:skip-none-grad
Open

shaneraphel wants to merge 1 commit into
KellerJordan:masterfrom
shaneraphel:skip-none-grad

Conversation

@shaneraphel

@shaneraphel shaneraphel commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

step replaced a missing gradient with zeros and then applied weight decay, so a parameter that did not receive a gradient still moved. With SingleDeviceMuon, lr 0.02 and weight decay 0.1, that 4×4 parameter was scaled by 0.998 (max absolute change 0.00436). Its momentum buffer was updated as well.

A missing gradient is now skipped, including the momentum or Adam state. The distributed loops still call all_gather on every rank.

Fixes #54.

Test plan

  • python test_none_grad.py on CPU: SingleDeviceMuon and SingleDeviceMuonWithAuxAdam leave a parameter with no gradient bitwise unchanged, and do not create or update its optimizer state
  • a parameter that does have a gradient still updates
  • the distributed all_gather path was not run here

Prepared with an AI assistant. I reviewed the diff and ran the CPU tests.

A None gradient was replaced with zeros so the step could continue, and
the parameter was then decayed. Leave that parameter and its state
alone. Distributed steps still reach all_gather.
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.

optimizer applies weight decay to parameters even when their gradient is None

1 participant