Optimization#
Training#
|
Compile a one-step training function from a loss graph and an update rule. |
Update rules#
|
Stochastic gradient descent, optionally with momentum. |
|
Adam optimizer. |
|
AdamW optimizer (Adam with decoupled weight decay). |
|
Nadam optimizer (Adam with Nesterov momentum). |
|
AdaMax optimizer (Adam with an infinity-norm denominator). |
|
RMSProp optimizer. |
|
Rprop optimizer (resilient backpropagation). |
|
AdaGrad optimizer. |
|
AdaDelta optimizer. |
Transforms#
|
Compose transforms left to right, each reading what the one before it produced. |
|
Scale each step by a constant factor. |
|
Scale each step by a schedule read off a training clock of its own. |
|
Subtract a weight-decay term \(\lambda p\). |
|
Accumulate into a velocity buffer (classical or Nesterov momentum). |
|
Rescale everything by a single factor so its global L2 norm does not exceed |
|
Clamp every value element-wise into |
Guards and policies#
|
Throw away any step |
|
Skip any step that would write a non-finite parameter, leaving the parameters and the optimizer state as they were. |
Throw the step away when any parameter the rule would write is inf or NaN. |
|
|
Throw the step away when the global L2 norm of the steps reaches |
|
Cut |
|
A rule for throwing a training step away, paired with the phrase naming why. |
Schedules#
Every step count a schedule takes – total_steps, transition_begin, decay_every, and the
boundaries of join_schedules() – accepts a symbolic value as readily as a literal one, so a
horizon can be written in terms of the data it will run over. With X the minibatch and
n_samples the size of the dataset, total_steps=10 * (n_samples // X.shape[0]) is ten epochs.
The same holds for the patience, cooldown, and accumulation_size of
reduce_on_plateau() and the max_norm of large_step() and
clip_by_global_norm(), and the bounds of clip_by_value(). A count whose value is not known
when the graph is built carries its check into the graph instead. That check rides on the value, so it
runs wherever the value does: not under jax, which drops assertions, and not where a rewrite has
eliminated the value’s last consumer.
|
Hold the learning rate at |
|
Move the learning rate from |
|
Move the learning rate through three linear phases over one cycle. |
|
Move the learning rate from |
|
Move the learning rate from |
|
Move the learning rate from |
|
Multiply the learning rate by |
|
Run |
Building blocks#
|
Return the training clock a component counts its own steps on. |
|
Return gradients of the loss with respect to |
|
Give |
|
Return a floatX scalar shared variable, reused across invocations of a rule wrapped in |
|
Return the optimizer-state shared variable shaped and typed like |
|
Return the amount each parameter's entry moves it by. |
|
Return |
|
Return |
What every optimizer, clip, and schedule in this module is: a callable taking a loss, gradients, or an updates dict, along with the parameters, and returning the updates dict that moves them. |
|
Pytensor's native |
|
Updates carrying gradients: |
|
Updates carrying steps: |
|
A learning-rate schedule: symbolic step count in, scalar learning rate out. |
|
A rate a rule multiplies into its step. |
|
What an optimizer alias accepts as its rate, adding a schedule that drives it on-graph. |
Reads the step a rule has proposed and returns a scalar boolean graph: True to throw the step away. |
Low-level update functions#
|
Vanilla stochastic gradient descent: \(p \leftarrow p - \eta g\). |
|
Adam optimizer. |
|
AdamW: Adam with decoupled weight decay applied directly to the parameter, not the gradient. |
|
Nadam: Adam with Nesterov momentum applied to the first-moment estimate. |
|
AdaMax: Adam variant using an exponentially weighted infinity norm instead of the second moment. |
|
RMSProp: per-parameter learning rate scaled by a decaying average of squared gradients. |
|
Rprop: resilient backpropagation, stepping by a per-parameter magnitude that adapts to gradient-sign agreement and ignores gradient magnitude. |
|
AdaGrad: per-parameter learning rate scaled by the inverse root of accumulated squared gradients. |
|
AdaDelta: AdaGrad variant with a decaying window of squared gradients and squared updates. |