class, gamma, step_value, init, optimizer=None)[source]

Trainer extension to shift an optimizer attribute in several steps.

This extension changes an optimizer attribute in several steps, every step the attribute will multiply a factor gamma.

For example, suppose that this extension is called at every iteration, and init = x, gamma = y, step_value = [s1, s2, s3]. Then during the iterations from 0 to (s1 - 1), the attr will be x. During the iterations from s1 to (s2 - 1), the attr will be x * y. During the iterations from s2 to (s3 - 1), the attr will be x * y * y. During the iterations after s3, the attr will be x * y * y * y.

This extension is also called before the training loop starts by default.

  • attr (str) – Name of the attribute to shift.
  • init (float) – Initial value of the attribute. If it is None, the extension extracts the attribute at the first call and uses it as the initial value.
  • gamma (float) – The factor which the attr will mutiply at the beginning of each step.
  • step_value (tuple) – The first iterations of each step.
  • optimizer (Optimizer) – Target optimizer to adjust the attribute. If it is None, the main optimizer of the updater is used.



Invokes the extension.

Implementations should override this operator. This method is called at iterations which the corresponding trigger accepts.

Parameters:trainer (Trainer) – Trainer object that calls this operator.

Finalizes the extension.

This method is called at the end of the training loop.


Initializes up the trainer state.

This method is called before entering the training loop. An extension that modifies the state of Trainer can override this method to initialize it.

When the trainer has been restored from a snapshot, this method has to recover an appropriate part of the state of the trainer.

For example, ExponentialShift extension changes the optimizer’s hyperparameter at each invocation. Note that the hyperparameter is not saved to the snapshot; it is the responsibility of the extension to recover the hyperparameter. The ExponentialShift extension recovers it in its initialize method if it has been loaded from a snapshot, or just setting the initial value otherwise.

Parameters:trainer (Trainer) – Trainer object that runs the training loop.

Serializes the extension state.

It is called when a trainer that owns this extension is serialized. It serializes nothing by default.



Default name of the extension.

It is the name of the class by default. Implementation can override this property, or provide a class attribute to hide it.

name = None
priority = 100
trigger = (1, 'iteration')