TensorTonic
Study Plans
Study Plan
Generate a Warmup-Stable-Decay Schedule
Language ModelsOptimization
Medium

Generate a warmup-stable-decay learning-rate schedule. Let TTT be total_steps, www warmup_steps, sss stable_steps, d=T−w−sd=T-w-sd=T−w−s the decay length, ηmax⁡\eta_{\max}ηmax​ peak_learning_rate, and rrr final_ratio. For zero-based warmup index ttt:

ηt=ηmax⁡t+1w.\eta_t=\eta_{\max}\frac{t+1}{w}.ηt​=ηmax​wt+1​.

The next sss rates equal ηmax⁡\eta_{\max}ηmax​. For zero-based decay index jjj, normalized progress is:

pj={1,d=1,j/(d−1),d>1.p_j=\begin{cases}1,&d=1,\\j/(d-1),&d>1.\end{cases}pj​={1,j/(d−1),​d=1,d>1.​

The decay rate is:

ηw+s+j=ηmax⁡[r+(1−r)1+cos⁡(πpj)2].\eta_{w+s+j}=\eta_{\max}\left[r+(1-r)\frac{1+\cos(\pi p_j)}{2}\right].ηw+s+j​=ηmax​[r+(1−r)21+cos(πpj​)​].

Here, η\etaη denotes learning rate, cos⁡\coscos is cosine and π\piπ is pi. A zero-length warmup or stable phase contributes no entries. The final rate is rηmax⁡r\eta_{\max}rηmax​, including a one-step decay. Return a float64 PyTorch tensor on the CPU with shape (total_steps,), in training-step order.

Loading visualization...

Examples

Input: total_steps = 6, warmup_steps = 2, stable_steps = 2, peak_learning_rate = 1, final_ratio = 0

Output: [0.5,1,1,1,1,0]

Explanation: Two warmup steps reach the peak, two stable steps hold it, and two decay steps include the peak and zero endpoints.

Input: total_steps = 4, warmup_steps = 0, stable_steps = 2, peak_learning_rate = 0.5, final_ratio = 0.2

Output: [0.5,0.5,0.5,0.1]

Input: total_steps = 3, warmup_steps = 1, stable_steps = 1, peak_learning_rate = 2, final_ratio = 0.25

Output: [2,2,0.5]

Hint 1

torch.arange can generate the indices of a phase.

Hint 2

torch.cos evaluates cosine elementwise.

Hint 3

torch.cat joins one-dimensional tensors.

Requirements

  • Use PyTorch and return float64 values.
  • Match the stated phase lengths and endpoints exactly.

Constraints

  • total_steps, warmup_steps, and stable_steps are Python integers.
  • warmup_steps and stable_steps are nonnegative and leave at least one decay step.
  • peak_learning_rate is positive and finite.
  • final_ratio lies in [0, 1].
Try Similar Problems
Orthogonalize a Muon Momentum UpdateEasyFit Learning-Rate and Batch-Size ScalingHardDiagnose muP Width InvariantsMediumRecover an IsoFLOP Compute-Optimal FrontierHardMixed-Precision Training Memory AccountantEasyTrain a BPE Tokenizer From Scratch in PythonMediumCanonicalize Pairwise Preference DataMediumCompute Temperature-Based Data MixturesMediumNesterov MomentumMediumBatch vs Stochastic vs Mini-Batch GDMediumBradley-Terry Reward Model LossMediumRLOO (REINFORCE Leave-One-Out)Medium

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.

Generate a Warmup-Stable-Decay Schedule

Language ModelsOptimization
Medium

Generate a warmup-stable-decay learning-rate schedule. Let TTT be total_steps, www warmup_steps, sss stable_steps, d=T−w−sd=T-w-sd=T−w−s the decay length, ηmax⁡\eta_{\max}ηmax​ peak_learning_rate, and rrr final_ratio. For zero-based warmup index ttt:

ηt=ηmax⁡t+1w.\eta_t=\eta_{\max}\frac{t+1}{w}.ηt​=ηmax​wt+1​.

The next sss rates equal ηmax⁡\eta_{\max}ηmax​. For zero-based decay index jjj, normalized progress is:

pj={1,d=1,j/(d−1),d>1.p_j=\begin{cases}1,&d=1,\\j/(d-1),&d>1.\end{cases}pj​={1,j/(d−1),​d=1,d>1.​

The decay rate is:

ηw+s+j=ηmax⁡[r+(1−r)1+cos⁡(πpj)2].\eta_{w+s+j}=\eta_{\max}\left[r+(1-r)\frac{1+\cos(\pi p_j)}{2}\right].ηw+s+j​=ηmax​[r+(1−r)21+cos(πpj​)​].

Here, η\etaη denotes learning rate, cos⁡\coscos is cosine and π\piπ is pi. A zero-length warmup or stable phase contributes no entries. The final rate is rηmax⁡r\eta_{\max}rηmax​, including a one-step decay. Return a float64 PyTorch tensor on the CPU with shape (total_steps,), in training-step order.

Loading visualization...

Examples

Input: total_steps = 6, warmup_steps = 2, stable_steps = 2, peak_learning_rate = 1, final_ratio = 0

Output: [0.5,1,1,1,1,0]

Explanation: Two warmup steps reach the peak, two stable steps hold it, and two decay steps include the peak and zero endpoints.

Input: total_steps = 4, warmup_steps = 0, stable_steps = 2, peak_learning_rate = 0.5, final_ratio = 0.2

Output: [0.5,0.5,0.5,0.1]

Input: total_steps = 3, warmup_steps = 1, stable_steps = 1, peak_learning_rate = 2, final_ratio = 0.25

Output: [2,2,0.5]

Hint 1

torch.arange can generate the indices of a phase.

Hint 2

torch.cos evaluates cosine elementwise.

Hint 3

torch.cat joins one-dimensional tensors.

Requirements

  • Use PyTorch and return float64 values.
  • Match the stated phase lengths and endpoints exactly.

Constraints

  • total_steps, warmup_steps, and stable_steps are Python integers.
  • warmup_steps and stable_steps are nonnegative and leave at least one decay step.
  • peak_learning_rate is positive and finite.
  • final_ratio lies in [0, 1].
Try Similar Problems
Orthogonalize a Muon Momentum UpdateEasyFit Learning-Rate and Batch-Size ScalingHardDiagnose muP Width InvariantsMediumRecover an IsoFLOP Compute-Optimal FrontierHardMixed-Precision Training Memory AccountantEasyTrain a BPE Tokenizer From Scratch in PythonMediumCanonicalize Pairwise Preference DataMediumCompute Temperature-Based Data MixturesMediumNesterov MomentumMediumBatch vs Stochastic vs Mini-Batch GDMediumBradley-Terry Reward Model LossMediumRLOO (REINFORCE Leave-One-Out)Medium

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.