Repository navigation
[BugFix] optim["interval"] is silently ignored: schedulers step once per batch regardless - #513
Open
SolidusAbi wants to merge 3 commits into
Open
SolidusAbi wants to merge 3 commits into
SolidusAbi wants to merge 3 commits into
Conversation
added 2 commits
December 1, 2026 16:11
With automatic_optimization=False Lightning never steps schedulers, so "interval" was dead config and every scheduler stepped per batch. Epoch-interval schedulers now step once per epoch in on_train_epoch_end (independent of frequency); step-interval ones stay in training_step.
This branch has not been deployed
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.
Description
Module documents interval ("step" or "epoch") in optim, but ignores it during training. Manual optimization (automatic_optimization = False) disables Lightning's automatic scheduler stepping, and training_step manually called scheduler.step() every batch—so "epoch" acted just like "step".
As a result, the README example ($2 * T_{max}$ batches instead of once over the whole run. The average learning rate is roughly half the target, and logging every 50 steps samples the extremes in a sawtooth pattern that looks convincing enough to hide the bug.
interval: epoch+CosineAnnealingLR(T_max=trainer.max_epochs)) runs a full cycle everyThis PR makes
sp.Modulehandle scheduler stepping for bothstepandepoch.What changed
Modulestores the configured interval per optimizer in_optimizer_intervals, mirroring_optimizer_frequencies: the flat single-optimizer config, the multi-optimizer{name: {...}}form, and theon_train_startfallback for callbackoptimizers (which keep the
"step"default).training_stepsteps onlyinterval="step"schedulers, as before.on_train_epoch_endstepsinterval="epoch"schedulers once per epoch.Tests
New
stable_pretraining/tests/unit/test_optimizer_interval.py: 9 CPU-only unit tests on toy data using aCosineAnnealingLRwhosestepis wrapped to count calls.interval="step"->n_batches * n_epochsscheduler steps (flat, named and two-optimizer configs)interval="epoch"-> exactlyn_epochssteps, one per epoch"step"+"epoch") -> each follows its own, which also pins the index -> name mapping betweenoptimizers()andlr_schedulers()frequency > 1does not swallow the end-of-epoch stepn_epochstimesVerified the tests fail without the fix (5 of 9) and pass with it.
Checklist