Skip to content

Schedules: Epoch-Scaled Annealing


annealing_schedule()

from jaxhybridmodels.schedules import annealing_schedule  ·  also re-exported as jaxhybridmodels.annealing_schedule

python
annealing_schedule(
    kind: 'str' = 'cosine',
    total_epochs: 'int',
    init_value: 'float' = 1.0,
    end_value: 'float' = 0.0,
    warmup_epochs: 'int' = 0,
) -> optax.Schedule

Return schedule(step: int) -> float, a multiplier over [0, total_epochs].

Built on optax's own schedule helpers, so the returned callable is a plain pure function of the integer step count: jit-safe, usable inside a traced loop. Every kind lands exactly on end_value at step == total_epochs and stays there afterwards, so the run length is genuinely baked in.

Parameters

ParameterTypeDescription
kindstrOne of "cosine" (default), "linear", "warmup_cosine", "exponential". The exponential kind decays geometrically with the per-epoch rate derived from (init_value, end_value, total_epochs), so its end point and run length are honoured like every other kind.
total_epochsintRun length in steps (one step == one epoch). Must be at least 1.
init_valuefloatValue at step=0, except "warmup_cosine" where it is the peak the schedule rises to after warmup_epochs. Must be positive.
end_valuefloatValue at step=total_epochs, where every kind arrives. Must lie in [0, init_value].
warmup_epochsint"warmup_cosine" only: steps from 0 to init_value before the decay. Must lie in [0, total_epochs).

Returns

ItemTypeDescription
optax.Scheduleschedule(step) in [end_value, init_value]. Compose as a multiplier: lr = base_lr * schedule(step).

Source

Released under the BSD-3-Clause License.