8000 GradSNR: drop the bias correction from ratio() by 10xCrazyHorse · Pull Request #28 · volotat/mini-AGI · GitHub
[go: up one dir, main page]

Skip to content

GradSNR: drop the bias correction from ratio() - #28

Open
10xCrazyHorse wants to merge 1 commit into
volotat:mainfrom
yaaa-cool:pr/gradsnr-bias-correction
Open

10xCrazyHorse wants to merge 1 commit into
volotat:mainfrom
yaaa-cool:pr/gradsnr-bias-correction

Conversation

@10xCrazyHorse
Copy link
Copy Markdown

GradSNR.ratio() divides both running averages by 1 - beta^n, the Adam-style bias correction. That correction is for averages that start at zero. Here both start at the first reading (self.m = flat.clone(), and self.sq = s when n == 0), so their weights already sum to one and neither is biased toward zero. Since m is squared in the numerator, the correction leaves the ratio multiplied by 1 / (1 - beta^n): 6.7x at the eighth reading, where it is first reported.

Readings at beta = 0.98, 256 elements, before and after:

reading constant gradient, before after pure noise (randn), before after
8 6.70 1.00 4.87 0.73
20 3.01 1.00 1.34 0.44
50 1.57 1.00 0.21 0.14
100 1.15 1.00 0.032 0.028
400 1.0003 1.00 0.0093 0.0093

So for the first 50 to 100 steps of a run the signal value in the read log sits above its documented 0..1 range: pure noise reads 4.9 on the first report, and a constant gradient only comes down to 1 as beta^n decays. In steady state (a few hundred steps) the two agree, and pure noise settles near (1 - beta) / (1 + beta), about 0.01, either way.

The impact is diagnostic only. ratio() feeds the signal field of the progress line in train.py, and nothing steers on it (the class docstring says so), so training is unchanged; only the early readings were wrong.

The fix removes the correction and returns ||m||^2 / sq directly. One thing it does not change: with only 8 readings the first gradient still carries about 0.87 of the weight, so pure noise reads around 0.7 at the first report. That comes from starting the averages at the first reading, not from this bug, so I left the n < 8 warm-up as it is.

Relation to #19 / #20

Independent of both. #20 changes observe() (what goes into the averages, for the crash in #19); this changes ratio() (how they are read). The hunks don't overlap: this branch merges with #20's head (cb36633) without conflicts in either order, and the merged result passes this test and a missing-gradient test. The new test uses a single parameter that always has a gradient, so it doesn't depend on #20.

Test plan

Two files: minagi/optim.py (+5/-2) and the new tests/test_gradsnr.py (+25).

Both averages start at the first reading, not at zero, so dividing by
1 - beta^n only inflated the ratio: 6.7x at the eighth reading, and a
constant gradient read above one. Reported only, nothing steers on it.
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

0