Skip to content

Training, adaptation, compression, and systems techniques · Training, fine-tuning, adaptation, compression, and systems techniques · TRN006 · Training method

Learning-rate warmup and cosine schedules

Control the step size through training, often using a cautious initial increase followed by gradual decay.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through decide.offline_rl, decide.rl_dqn, decide.rl_ppo, discover.autoencoder, discover.contrastive, discover.dagmm, discover.deep_svdd, discover.graph_embed, discover.ts_embed, discover.vae, forecast.deepar, forecast.nbeats, forecast.nhits, forecast.patchtst, forecast.rnn, forecast.tcn, forecast.tft, forecast.timegrad, learn.cnn, learn.dann, learn.deep_ensemble, learn.ft_transformer, learn.gnn, learn.neural_cde, learn.set_model, learn.tabm, learn.tabnet, learn.torch_mlp, missing.csdi, simulate.calibrate, synth.flow, synth.flow_matching, synth.tvae. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Control the step size through training, often using a cautious initial increase followed by gradual decay.

Question / hypotheses

Does this intervention improve the intended quality, adaptation, resource, or reliability objective under a controlled comparison? It defines a method, not an intrinsic null-hypothesis test.

Architecture / computational structure

A deterministic scheduler changes optimizer-group learning rates as a function of completed optimizer steps; warm restarts are an optional distinct schedule.

Assumptions

Count optimizer steps consistently with gradient accumulation. Warmup is a recipe choice, not a universal requirement. A schedule depends on the planned total budget.

Formula / computational definition

ηt=ηmaxt/Tw (t≤Tw);ηt=ηmin+12(ηmax−ηmin)[1+cos⁡(π(t−Tw)/(T−Tw))].\eta_t=\eta_{max}t/T_w\ (t\le T_w);\quad\eta_t=\eta_{min}+\tfrac12(\eta_{max}-\eta_{min})[1+\cos(\pi (t-T_w)/(T-T_w))].

Parameters and notation

Hyperparameters: maximum/minimum rate, warmup steps T_w, total T, restart periods, group multipliers. No separately learned scheduler weights in this fixed form.

Fitting, fine-tuning, and adaptation

For small adaptation datasets, choose steps rather than blindly copying pretraining epoch schedules. Resume the scheduler state with the optimizer; reevaluate if changing the training budget.

How to use and calibrate

Plot the planned schedule before training and overlay loss/update norms. Example: adapt a pretrained language model without a large destructive first update.

Example application

adapt a pretrained language model without a large destructive first update.

Interpretation / pitfalls

Watch out

A warm restart does not reset model weights. Calling a scheduler on every microbatch rather than optimizer step can unintentionally shorten warmup and decay.

Python and R code examples

Scope: numerical mechanism demonstration. Validation: Python executed successfully on the supplied synthetic inputs; R reviewed but not executed (Rscript unavailable).

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — numerical mechanism demonstration. · needs numpy

import numpy as np
T=100; warm=10; top=.001; t=np.array([0,5,10,50,100])
lr=np.where(t<=warm,top*t/warm,.5*top*(1+np.cos(np.pi*(t-warm)/(T-warm)))); print(lr)
R

Component demo, not a trained model — numerical mechanism demonstration.

T <- 100; warm <- 10; top <- .001; t <- c(0,5,10,50,100)
lr <- ifelse(t<=warm,top*t/warm,.5*top*(1+cos(pi*(t-warm)/(T-warm)))); print(lr)

Sources

From the CodeSplash reference, entry TRN006.