Skip to content

Fix centered RMSprop: clamp the variance, keep eps inside the root - #80

Merged
CanReader merged 2 commits into
masterfrom
land/rmsprop-centered
Nov 12, 2026
Merged

CanReader merged 2 commits into
masterfrom
land/rmsprop-centered

Conversation

@CanReader

Copy link
Copy Markdown
Owner

What this changes

Centered RMSprop clamps the variance estimate at zero before the square root, so cancellation in E[g²] - E[g]² can no longer produce a NaN denominator. eps stays inside the root, as before. The two centered tests assert that every step is finite and at or under lr·|g|/√eps.

Why

This is #73 with one correction. The clamp is the fix for #12. Moving eps outside the root, which #73 also did, makes the step lr/eps once the variance estimate reaches zero, which it does exactly in f32 for a constant gradient after about 155 steps: ten thousand times the previous step, the opposite of what that change was meant to do. With eps inside, the step is capped at lr·|g|/√eps, and the tests now check that cap, which the outside placement fails. The contributor's commit is kept with their authorship. Landing from a branch in this repository because the fork's branch cannot be updated from here.

Closes #12.

How it was verified

  • cargo test passes
  • cargo clippy --all-targets -- -D warnings is clean
  • Ran cuda_parity on a GPU
  • Trained an example in --release
  • No GPU here, CUDA side not runtime tested

The rmsprop unit tests pass locally; CI runs the rest.

Checklist

  • Every new or changed backward rule has a gradcheck case
  • Every new kernel has a cuda_parity case
  • tensor/ops and autograd/ops still mirror each other
  • Public items have /// docs

@CanReader
CanReader merged commit 14742ab into master Nov 12, 2026
12 checks passed
@CanReader
CanReader deleted the land/rmsprop-centered branch November 12, 2026 10:18
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.

Centered RMSprop can take the square root of a negative number

2 participants