medium primitives

Piecewise Constant Schedule

Why this matters

Classical step-decay schedules — halve the LR every K steps — were the dominant training recipe before cosine/warmup became standard. They are still common in computer vision training (ResNet, VGG). Optax provides piecewise_constant_schedule for this pattern.

How it works

optax.piecewise_constant_schedule(init_value, boundaries_and_scales):

  • Starts at init_value.
  • At each boundary step, multiplies the current LR by the corresponding scale factor.
  • Between boundaries, the LR is held constant.

Example with init_value=0.1, {100: 0.5, 200: 0.5}:

step range LR
0–99 0.1
100–199 0.05
200+ 0.025

Common pitfalls

  • Scale factors are multipliers, not absolute values. 0.5 means “halve the current LR”, not “set LR to 0.5”.
  • Boundary steps must be strictly increasing integers.
  • The LR at boundary step K is the post-scale value (i.e. applying the scale happens at step K, not after K).

Inputs

This problem uses a fixed schedule wired into the function: init_value=0.1, boundaries {100: 0.5, 200: 0.5}.

  • step: scalar (cast to int).

Output

Scalar — the LR at step.

Hints

optax schedule piecewise

Sign in to attempt this problem and view the solution.