Compute a learning rate that rises linearly during warmup and then follows a cosine curve down to a floor, for a step count that is a traced JAX array.
For an entry s of step, with W equal to warmup_steps, S equal to total_steps, ηmax equal to peak_lr and ηmin equal to min_lr, the learning rate is
η(s)=⎩⎨⎧ηmaxWsηmin+2ηmax−ηmin(1+cos(πp))s<Ws≥W,p=min(S−Ws−W, 1).Your function is compiled with jax.jit, with step traced and the other four arguments static, so step is a placeholder without a known value while the code runs. A Python if statement, float(step) or int(step) cannot be used on it.
Return a float32 JAX array with the same shape as step, holding the learning rate of each step.
Input: step = [0,5,10,55,100,150], peak_lr = 1.0, min_lr = 0.0, warmup_steps = 10, total_steps = 100
Output: [0.0,0.5,1.0,0.5,0.0,0.0]
Explanation: Warmup covers steps 0 to 9, so step 5 is halfway up the ramp at 0.5 and step 10 reaches the peak of 1. Step 55 is halfway through the decay, where the cosine is 0 and the rate is the midpoint 0.5, and steps 100 and 150 sit at the floor of 0.
Input: step = 3, peak_lr = 0.001, min_lr = 0.0001, warmup_steps = 8, total_steps = 40
Output: 0.000375
Input: step = [0,1,2,3], peak_lr = 0.5, min_lr = 0.05, warmup_steps = 1, total_steps = 3
Output: [0.0,0.5,0.275,0.05]
jnp.where(step < warmup, a, b) replaces a Python if on a traced step.
jnp.clip(progress, 0.0, 1.0) keeps the decay progress in range.
step.astype(jnp.float32) before dividing.
Accepts: integer, array
Accepts: number
Accepts: number
Accepts: integer
Accepts: integer
Compute a learning rate that rises linearly during warmup and then follows a cosine curve down to a floor, for a step count that is a traced JAX array.
For an entry s of step, with W equal to warmup_steps, S equal to total_steps, ηmax equal to peak_lr and ηmin equal to min_lr, the learning rate is
η(s)=⎩⎨⎧ηmaxWsηmin+2ηmax−ηmin(1+cos(πp))s<Ws≥W,p=min(S−Ws−W, 1).Your function is compiled with jax.jit, with step traced and the other four arguments static, so step is a placeholder without a known value while the code runs. A Python if statement, float(step) or int(step) cannot be used on it.
Return a float32 JAX array with the same shape as step, holding the learning rate of each step.
Input: step = [0,5,10,55,100,150], peak_lr = 1.0, min_lr = 0.0, warmup_steps = 10, total_steps = 100
Output: [0.0,0.5,1.0,0.5,0.0,0.0]
Explanation: Warmup covers steps 0 to 9, so step 5 is halfway up the ramp at 0.5 and step 10 reaches the peak of 1. Step 55 is halfway through the decay, where the cosine is 0 and the rate is the midpoint 0.5, and steps 100 and 150 sit at the floor of 0.
Input: step = 3, peak_lr = 0.001, min_lr = 0.0001, warmup_steps = 8, total_steps = 40
Output: 0.000375
Input: step = [0,1,2,3], peak_lr = 0.5, min_lr = 0.05, warmup_steps = 1, total_steps = 3
Output: [0.0,0.5,0.275,0.05]
jnp.where(step < warmup, a, b) replaces a Python if on a traced step.
jnp.clip(progress, 0.0, 1.0) keeps the decay progress in range.
step.astype(jnp.float32) before dividing.
Accepts: integer, array
Accepts: number
Accepts: number
Accepts: integer
Accepts: integer