Repository navigation
fix(optim): prevent learning rate reset at warmdown iteration boundary - #2180
reginaldalfret wants to merge 2 commits into
Conversation
When training with fixed iteration warmdown (without wallclock timeout), lr_mul checked warmdown_start <= step < iterations. When step reached iterations, the condition evaluated to False, causing the multiplier to fall back to the else branch and jump from near-zero back up to 1.0. This change simplifies the condition to step >= warmdown_start so that max((iterations - step) / warmdown_iters, 0.0) correctly yields 0.0 at and beyond the iteration boundary across PyTorch and MLX baselines. Signed-off-by: reginaldalfret <[email protected]>
|
The fix itself looks right to me, and dropping the In Small nit on the tests: |
…irectly Hoist lr_mul to Hyperparameters in train_gpt.py to match train_gpt_mlx.py, aliasing lr_mul = args.lr_mul in main(). Update test_warmdown_schedule.py to test both production Hyperparameters implementations directly across all schedule edge cases without duplicate closure logic. Signed-off-by: reginaldalfret <[email protected]>
|
Thanks for the careful review and the spot-on catch regarding the loop break order! You are completely right: on stock Regarding the test suite: to avoid replicating the closure in |
|
Nice, hoisting it onto Tiny thing, not blocking: the mocks stay in |
Problem
In both
train_gpt.pyandtrain_gpt_mlx.py, the iteration-based learning rate multiplier evaluates:When training with fixed iteration budgets (when wallclock timeout is disabled or not reached), the condition checked
step < args.iterations. For any evaluation wherestep >= args.iterations:step < args.iterationsevaluates toFalse.elsebranch, returning1.0.lr_mul(step, ...)at or past the iteration boundary returns full learning rate (1.0) instead of0.0. The inner clampmax((iterations - step) / warmdown_iters, 0.0)was rendered unreachable at non-positive values due to the< args.iterationsupper guard.Stock loop context:
In standard training runs (
train_gpt.pyL974/L1005 andtrain_gpt_mlx.pyL1004/L1026),last_step = step == args.iterationstriggers validation and breaks beforelr_mul(step, elapsed_ms)is invoked. Thus, standard runs exit without training a step atstep == args.iterations, and existing benchmark records were not affected.However, for continuation runs past
args.iterations, post-budget logging/evaluations callinglr_mul, custom training loops, or forks that do not break immediately, returning1.0is unexpected.Change
Simplify the decay condition to
step >= warmdown_startin bothtrain_gpt.pyandtrain_gpt_mlx.py:step < warmdown_start, multiplier remains1.0.warmdown_start <= step < iterations, multiplier decays linearly from 1.0 to 0.0.step >= iterations,max(..., 0.0)cleanly clamps to0.0.In
train_gpt.py, definelr_mul(self, step, elapsed_ms)onHyperparametersand aliaslr_mul = args.lr_mulinmain(), mirroring the structure oftrain_gpt_mlx.py. This avoids duplicated closure logic in the test suite and enables direct unit testing of production code.Line counts remain well within the 1,500-line limit:
train_gpt.py: 1,127 linestrain_gpt_mlx.py: 1,104 linesValidation
tests/test_warmdown_schedule.pywith 8 parameterized tests directly exercisingtrain_gpt.Hyperparametersandtrain_gpt_mlx.Hyperparameters.step == iterations), post-budget steps (step > iterations), disabled warmdown (warmdown_iters = 0), warmdown exceeding iteration budget, and wallclock expiration.ruff check --select E,F,W --ignore E501andgit diff --checkpass with 0 errors.