feat(optim): mutable learning rate and warmup+cosine LR schedule#866
Merged
Conversation
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
AdamOptimizer and SgdOptimizer expose lr as a public var so training loops can adjust it between steps without recreating the optimizer and losing the moment estimates. A stateless LrSchedule fun interface plus a linearWarmupCosineDecay factory cover the GPT-style pretraining recipe: linear ramp from initialLr to peakLr over the warmup steps, then cosine decay to minLr. Closes #865
michalharakal
force-pushed
the
feature/865-lr-schedules
branch
from
July 23, 2026 21:04
cbbcbb5 to
6559806
Compare
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
aharakal
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #865.
What
AdamOptimizer.lrandSgdOptimizer.lrare nowpublic var(previouslyprivate val), so training loops can adjust the learning rate between steps without recreating the optimizer and discarding Adam's moment estimates.LrSchedulefun interface +linearWarmupCosineDecay(totalSteps, warmupSteps, peakLr, initialLr, minLr)factory insk.ainet.lang.nn.optim: linear ramp frominitialLrtopeakLrover the warmup steps, then cosine decay tominLr— the standard GPT-style pretraining recipe.Schedules stay stateless and decoupled from optimizers; usage is one assignment per step:
No changes to the
Optimizerinterface.Tests
LrScheduleTest(lang-core commonTest): warmup starts atinitialLrand ramps with constant increments, peak reached exactly at warmup end, decay is monotonic and approachesminLr, invalid arguments rejected,lrassignable on both optimizers.SgdOptimizerTest.lr_can_be_rescheduled_between_steps(backend-cpu): a rescheduled lr changes the applied update (0.1 → 9.8, then 0.5 → 8.8 on a hand-computed example).apiDump; android mirrored by hand — no Android SDK on this machine, additions are the property accessors and the two new types).Motivation
Found while porting an educational GPT pretraining pipeline (appendix D of Raschka's book: warmup + cosine decay + gradient clipping) to SKaiNET — previously impossible without a project-local optimizer re-implementation whose only difference was
var lr.