8000 GradSNR: count a missing grad as zeros instead of dropping it by dreddnafious · Pull Request #20 · volotat/mini-AGI · GitHub
[go: up one dir, main page]

Skip to content

GradSNR: count a missing grad as zeros instead of dropping it - #20

Open
dreddnafious wants to merge 1 commit into
volotat:mainfrom
dreddnafious:fix/gradsnr-none-grad
Open

dreddnafious wants to merge 1 commit into
volotat:mainfrom
dreddnafious:fix/gradsnr-none-grad

Conversation

@dreddnafious
Copy link
Copy Markdown

Fixes #19 (reported by @nekomario28).

GradSNR.observe concatenated only the parameters that had a gradient, so the flattened vector changed length whenever one sat a step out, and the running mean no longer matched it. Recurrence-depth sampling makes this routine: a depth-1 step forces the halt, and the halting head (d_model + 1 elements) gets no gradient.

A missing gradient is a zero gradient for that step, so it's now counted as zeros. The meter keeps its history instead of resetting. It still returns None when no parameter has a gradient.

Tested: a regression script (intermittently gradless parameter; constant gradient still reads ~1.0) fails on main and passes here. The same change ran ~8 GPU-hours of train.py read at a small scale without issue.

One file, +10/-3.

🤖 Generated with Claude Code

…t#19)

observe() concatenated only the parameters that had a gradient, so the
flattened vector changed length whenever one sat a step out and the
running mean no longer matched it. Recurrence depth sampling makes that
routine: a step sampled at depth 1 forces the halt and leaves the
halting head without a gradient (d_model + 1 elements - the 129 in volotat#19
at d_model 128, 257 at d_model 256). A missing gradient is a zero
gradient for that step, so it is counted as zeros; the meter keeps its
history rather than resetting.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
10xCrazyHorse added a commit to yaaa-cool/mini-AGI that referenced this pull request Oct 3, 2026
observe concatenated only the parameters that had a gradient, so the
flattened vector changed length whenever one sat a step out, and the
running mean no longer matched it. A step sampled at recurrence depth 1
forces the halt, and the halting head (d_model + 1 elements) gets no
gradient. A missing gradient is a zero gradient for that step, so it is
counted as zeros and the meter keeps its history instead of resetting.

The optim.py change is identical to upstream PR volotat#20 by @dreddnafious
(reported by @nekomario28), so it merges cleanly if volotat#20 lands.

Adds tests/test_bug19_gradsnr.py (CPU, tiny model).
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.

read crashes in GradSNR.observe when the set of parameters with gradients changes between steps

1 participant

0