fix: Fix CosineAnnealingWarmUpRestarts#293
Draft
yamsam wants to merge 1 commit into
Draft
Conversation
The scheduler named CosineAnnealingWarmUpRestarts actually held the lr
CONSTANT after warmup (post-warmup phase was MultiplicativeLR(lambda=1.0)),
so training collapsed right after warmup: every model peaked in the warmup
epochs and then degraded.
- Add WarmupCosineAnnealingLR: linear warmup then real cosine decay to
eta_min over the remaining epochs (matches original planTF).
- Rename the legacy behavior to WarmupConstantLR (accurate name), kept for
backward-compatible reproduction of pre-existing runs.
- Keep CosineAnnealingWarmUpRestarts as an alias bound to the exact legacy
(constant) behavior so existing imports and resumed checkpoints reproduce.
- Add build_lr_scheduler dispatch and --lr_schedule_type {cosine,constant}
(default cosine). Training now cosine-decays by default; select "constant"
to reproduce old runs.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Isamu Yamashita <isamu.yamashita@tier4.jp>
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.
Fix the post-warmup LR schedule to cosine-decay
Summary
The scheduler
CosineAnnealingWarmUpRestartsdid not cosine-anneal — despite the name, its post-warmup phase wasMultiplicativeLR(lambda=1.0), i.e. it held the learning rate constant at its peak for the entire run. This let training collapse right after warmup: models peaked during the warmup epochs and then degraded, andbest_model(by valid loss) tended to be a warmup-epoch fluke.This PR makes the schedule a real linear-warmup → cosine-decay, while keeping the old behavior available under an accurate name for backward-compatible reproduction of pre-existing runs.
Based on
dev.Changes
diffusion_planner/utils/lr_schedule.py:WarmupCosineAnnealingLR(new): linear warmup forwarm_up_epochepochs, thenCosineAnnealingLRdecay toeta_min(1e-6) over the remaining epochs. Matches original planTF.WarmupConstantLR: the legacy behavior (warmup → constant), renamed to describe what it actually does. Kept for reproducing old runs / resumed checkpoints.CosineAnnealingWarmUpRestarts: retained as a backward-compatible alias bound toWarmupConstantLR(the exact legacy/constant behavior), so existing imports and resumed checkpoints reproduce unchanged. Marked deprecated in favor ofWarmupCosineAnnealingLR.build_lr_scheduler(...): small dispatcher selecting"cosine"(default) or"constant".train.py,train_config.py,train_predictor.py:train.pynow builds the scheduler viabuild_lr_scheduler(..., schedule_type=args.lr_schedule_type).--lr_schedule_type {cosine,constant}(defaultcosine).Behavior change & compatibility
--lr_schedule_type constant, or importingWarmupConstantLR/ theCosineAnnealingWarmUpRestartsalias.Before vs. after (peak_lr=1e-3, warmup=5, 25 epochs), lr at the final epoch:
constant(legacy)cosine(new default)Verification
diffusion_planner/tests/test_lr_schedule.py, 7 cases): warmup ramp fromstart_factor·peakto peak; constant holds peak post-warmup; cosine strictly decreases post-warmup and lands neareta_min; cosine vs. constant identical through warmup then diverge; the alias reproduces the constant behavior exactly;build_lr_schedulerdispatch + invalid type raises; and thewarm_up_epoch==1/epoch==warm_up_epochedge cases don't raise. All pass.TrainConfigbuilds withlr_schedule_typedefaultcosineand--lr_schedule_type constantoverride;train.pyimports and wires the dispatcher.🤖 Generated with Claude Code