gluonts.mx.trainer.callback module

class gluonts.mx.trainer.callback.Callback[source]

Bases: object

Abstract Callback base class. Callbacks control the training of the GluonTS trainer. To write a custom Callback, you can subclass Callback and overwrite one or more of the hook methods. Hook methods with boolean return value stop the training if False is returned.

on_epoch_end(epoch_no: int, epoch_loss: float, training_network: mxnet.gluon.block.HybridBlock, trainer: mxnet.gluon.trainer.Trainer, best_epoch_info: Dict[str, Any], ctx: mxnet.context.Context) → bool[source]

Hook that is called after every epoch. As on_train_epoch_end and on_validation_epoch_end, it returns a boolean whether training should continue. This hook is always called after on_train_epoch_end and on_validation_epoch_end. It is called regardless of these hooks’ return values.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The validation loss that was recorded in the last epoch if validation data was provided. The training loss otherwise.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

  • best_epoch_info – Aggregate information about the best epoch. Contains keys params_path, epoch_no and score. The score is the best validation loss if validation data is provided or the best training loss otherwise.

  • ctx – The MXNet context used.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_network_initializing_end(training_network: mxnet.gluon.block.HybridBlock) → None[source]

Hook that is called prior to training, after the training network has been initialized. This is the first hook where the network is passed.

Parameters

training_network – The network that is being trained.

on_train_batch_end(training_network: mxnet.gluon.block.HybridBlock) → None[source]

Hook that is called after each training batch.

Parameters

training_network – The network that is being trained.

on_train_end(training_network: mxnet.gluon.block.HybridBlock, temporary_dir: str, ctx: mxnet.context.Context = None) → None[source]

Hook that is called after training is finished. This is the last hook to be called.

Parameters
  • training_network – The network that was trained.

  • temporary_dir – The directory where model parameters are logged throughout training.

  • ctx – An MXNet context used.

on_train_epoch_end(epoch_no: int, epoch_loss: float, training_network: mxnet.gluon.block.HybridBlock, trainer: mxnet.gluon.trainer.Trainer) → bool[source]

Hook that is called after each training epoch. This method returns a boolean whether training should continue.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_train_epoch_start(training_network: mxnet.gluon.block.HybridBlock) → None[source]

Hook that is called prior to each training epoch.

Parameters

training_network – The network that is being trained.

on_train_start(max_epochs: int) → None[source]

Hook that is called prior to training. This is the very first hook to be called.

Parameters

max_epochs – The maximum number of epochs that training is running. The actual number of epochs may be fewer if another callback hook stops training early.

on_validation_batch_end(training_network: mxnet.gluon.block.HybridBlock) → None[source]

Hook that is called after each validation batch. This hook is never called if no validation data is available during training.

Parameters

training_network – The network that is being trained.

on_validation_epoch_end(epoch_no: int, epoch_loss: float, training_network: mxnet.gluon.block.HybridBlock, trainer: mxnet.gluon.trainer.Trainer) → bool[source]

Hook that is called after each validation epoch. Similar to on_train_epoch_end, this method returns a boolean whether training should continue. Note that it is always called after on_train_epoch_end within a single epoch. If on_train_epoch_end returned False, this method will not be called.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The validation loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_validation_epoch_start(training_network: mxnet.gluon.block.HybridBlock) → None[source]

Hook that is called prior to each validation epoch. This hook is never called if no validation data is available during training.

Parameters

training_network – The network that is being trained.

class gluonts.mx.trainer.callback.CallbackList(callbacks: List[gluonts.mx.trainer.callback.Callback])[source]

Bases: gluonts.mx.trainer.callback.Callback

Used to chain a list of callbacks to one Callback. Boolean hook methods are logically joined with AND, meaning that if at least one callback method returns False, the training is stopped.

Variables

callbacks – A list of gluonts.mx.trainer.callback.Callback’s.

on_epoch_end(*args: Any, **kwargs: Any) → bool[source]

Hook that is called after every epoch. As on_train_epoch_end and on_validation_epoch_end, it returns a boolean whether training should continue. This hook is always called after on_train_epoch_end and on_validation_epoch_end. It is called regardless of these hooks’ return values.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The validation loss that was recorded in the last epoch if validation data was provided. The training loss otherwise.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

  • best_epoch_info – Aggregate information about the best epoch. Contains keys params_path, epoch_no and score. The score is the best validation loss if validation data is provided or the best training loss otherwise.

  • ctx – The MXNet context used.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_network_initializing_end(*args: Any, **kwargs: Any) → None[source]

Hook that is called prior to training, after the training network has been initialized. This is the first hook where the network is passed.

Parameters

training_network – The network that is being trained.

on_train_batch_end(*args: Any, **kwargs: Any) → None[source]

Hook that is called after each training batch.

Parameters

training_network – The network that is being trained.

on_train_end(*args: Any, **kwargs: Any) → None[source]

Hook that is called after training is finished. This is the last hook to be called.

Parameters
  • training_network – The network that was trained.

  • temporary_dir – The directory where model parameters are logged throughout training.

  • ctx – An MXNet context used.

on_train_epoch_end(*args: Any, **kwargs: Any) → bool[source]

Hook that is called after each training epoch. This method returns a boolean whether training should continue.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_train_epoch_start(*args: Any, **kwargs: Any) → None[source]

Hook that is called prior to each training epoch.

Parameters

training_network – The network that is being trained.

on_train_start(*args: Any, **kwargs: Any) → None[source]

Hook that is called prior to training. This is the very first hook to be called.

Parameters

max_epochs – The maximum number of epochs that training is running. The actual number of epochs may be fewer if another callback hook stops training early.

on_validation_batch_end(*args: Any, **kwargs: Any) → None[source]

Hook that is called after each validation batch. This hook is never called if no validation data is available during training.

Parameters

training_network – The network that is being trained.

on_validation_epoch_end(*args: Any, **kwargs: Any) → bool[source]

Hook that is called after each validation epoch. Similar to on_train_epoch_end, this method returns a boolean whether training should continue. Note that it is always called after on_train_epoch_end within a single epoch. If on_train_epoch_end returned False, this method will not be called.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The validation loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_validation_epoch_start(*args: Any, **kwargs: Any) → None[source]

Hook that is called prior to each validation epoch. This hook is never called if no validation data is available during training.

Parameters

training_network – The network that is being trained.

class gluonts.mx.trainer.callback.TerminateOnNaN[source]

Bases: gluonts.mx.trainer.callback.Callback

on_train_epoch_end(epoch_no: int, epoch_loss: float, training_network: mxnet.gluon.block.HybridBlock, trainer: mxnet.gluon.trainer.Trainer) → bool[source]

Hook that is called after each training epoch. This method returns a boolean whether training should continue.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

class gluonts.mx.trainer.callback.TrainingHistory[source]

Bases: gluonts.mx.trainer.callback.Callback

on_train_epoch_end(epoch_no: int, epoch_loss: float, training_network: mxnet.gluon.block.HybridBlock, trainer: mxnet.gluon.trainer.Trainer) → bool[source]

Hook that is called after each training epoch. This method returns a boolean whether training should continue.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

on_validation_epoch_end(epoch_no: int, epoch_loss: float, training_network: mxnet.gluon.block.HybridBlock, trainer: mxnet.gluon.trainer.Trainer) → bool[source]

Hook that is called after each validation epoch. Similar to on_train_epoch_end, this method returns a boolean whether training should continue. Note that it is always called after on_train_epoch_end within a single epoch. If on_train_epoch_end returned False, this method will not be called.

Parameters
  • epoch_no – The current epoch (the first epoch has epoch_no = 0).

  • epoch_loss – The validation loss that was recorded in the last epoch.

  • training_network – The network that is being trained.

  • trainer – The trainer which is running the training.

Returns

A boolean whether the training should continue. Defaults to True.

Return type

bool

class gluonts.mx.trainer.callback.WarmStart(predictor)[source]

Bases: gluonts.mx.trainer.callback.Callback

on_network_initializing_end(training_network: mxnet.gluon.block.HybridBlock) → None[source]

Hook that is called prior to training, after the training network has been initialized. This is the first hook where the network is passed.

Parameters

training_network – The network that is being trained.