TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Warmup + Linear Decay LR Schedule

Optimization
Easy

Most modern training pipelines start with a warmup phase where the learning rate gradually increases from zero, followed by a decay phase where it gradually decreases. This prevents early instability from large updates while still allowing the optimizer to escape sharp minima later.

Given a base learning rate, warmup steps, total steps, and the current step, compute the learning rate at that step.

Schedule

Warmup phase (current_step < warmup_steps): the learning rate increases linearly from 0 to base_lr.

lr=base_lr×current_stepwarmup_stepslr = base\_lr \times \frac{current\_step}{warmup\_steps}lr=base_lr×warmup_stepscurrent_step​

Decay phase (current_step >= warmup_steps): the learning rate decreases linearly from base_lr to 0.

lr=base_lr×total_steps−current_steptotal_steps−warmup_stepslr = base\_lr \times \frac{total\_steps - current\_step}{total\_steps - warmup\_steps}lr=base_lr×total_steps−warmup_stepstotal_steps−current_step​
Loading visualization...

Examples

Input: base_lr = 0.1, warmup_steps = 10, total_steps = 100, current_step = 5

Output: 0.05

Explanation: Step 5 is halfway through the linear warmup.

Input: base_lr = 0.1, warmup_steps = 10, total_steps = 100, current_step = 55

Output: 0.05

Hint 1

Use the warmup fraction when the current step is below the warmup boundary.

Hint 2

Use the remaining-step fraction during linear decay.

Requirements

  • During warmup, linearly increase lr from 0 to base_lr
  • During decay, linearly decrease lr from base_lr to 0
  • At current_step = warmup_steps, lr should equal base_lr

Constraints

  • base_lr > 0, warmup_steps >= 0, total_steps > warmup_steps
  • 0 <= current_step <= total_steps
  • Return a single float
  • Time limit: 300 ms
Try Similar Problems
Cosine Annealing LrLinear Lr SchedulerAdam OptimizerAdamw OptimizerGradient Descent Quadratic

Sign in to take notes on this problem

Case 1
Case 2

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.
PrevNext

Warmup + Linear Decay LR Schedule

Optimization
Easy

Most modern training pipelines start with a warmup phase where the learning rate gradually increases from zero, followed by a decay phase where it gradually decreases. This prevents early instability from large updates while still allowing the optimizer to escape sharp minima later.

Given a base learning rate, warmup steps, total steps, and the current step, compute the learning rate at that step.

Schedule

Warmup phase (current_step < warmup_steps): the learning rate increases linearly from 0 to base_lr.

lr=base_lr×current_stepwarmup_stepslr = base\_lr \times \frac{current\_step}{warmup\_steps}lr=base_lr×warmup_stepscurrent_step​

Decay phase (current_step >= warmup_steps): the learning rate decreases linearly from base_lr to 0.

lr=base_lr×total_steps−current_steptotal_steps−warmup_stepslr = base\_lr \times \frac{total\_steps - current\_step}{total\_steps - warmup\_steps}lr=base_lr×total_steps−warmup_stepstotal_steps−current_step​
Loading visualization...

Examples

Input: base_lr = 0.1, warmup_steps = 10, total_steps = 100, current_step = 5

Output: 0.05

Explanation: Step 5 is halfway through the linear warmup.

Input: base_lr = 0.1, warmup_steps = 10, total_steps = 100, current_step = 55

Output: 0.05

Hint 1

Use the warmup fraction when the current step is below the warmup boundary.

Hint 2

Use the remaining-step fraction during linear decay.

Requirements

  • During warmup, linearly increase lr from 0 to base_lr
  • During decay, linearly decrease lr from base_lr to 0
  • At current_step = warmup_steps, lr should equal base_lr

Constraints

  • base_lr > 0, warmup_steps >= 0, total_steps > warmup_steps
  • 0 <= current_step <= total_steps
  • Return a single float
  • Time limit: 300 ms
Try Similar Problems
Cosine Annealing LrLinear Lr SchedulerAdam OptimizerAdamw OptimizerGradient Descent Quadratic

Sign in to take notes on this problem

Case 1
Case 2

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.