gluonts.mx.trainer package¶

class gluonts.mx.trainer.Trainer(ctx: Optional[mxnet.context.Context] = None, epochs: int = 100, batch_size: Optional[int] = None, num_batches_per_epoch: int = 50, learning_rate: float = 0.001, learning_rate_decay_factor: float = 0.5, patience: int = 10, minimum_learning_rate: float = 5e-05, clip_gradient: float = 10.0, weight_decay: float = 1e-08, init: Union[str, mxnet.initializer.Initializer] = 'xavier', hybridize: bool = True, callbacks: Optional[List[gluonts.mx.trainer.callback.Callback]] = None, add_default_callbacks: bool = True)[source]

Bases: object

A trainer specifies how a network is going to be trained.

A trainer is mainly defined by two sets of parameters. The first one determines the number of examples that the network will be trained on (epochs, num_batches_per_epoch), while the second one specifies how the gradient updates are performed (learning_rate, learning_rate_decay_factor, patience, minimum_learning_rate, clip_gradient and weight_decay).

Parameters
• ctx

• epochs – Number of epochs that the network will train (default: 100).

• num_batches_per_epoch – Number of batches at each epoch (default: 50).

• learning_rate – Initial learning rate (default: $$10^{-3}$$).

• learning_rate_decay_factor – Factor (between 0 and 1) by which to decrease the learning rate (default: 0.5).

• patience – The patience to observe before reducing the learning rate, nonnegative integer (default: 10).

• minimum_learning_rate – Lower bound for the learning rate (default: $$5\cdot 10^{-5}$$).

• clip_gradient – Maximum value of gradient. The gradient is clipped if it is too large (default: 10).

• weight_decay – The weight decay (or L2 regularization) coefficient. Modifies objective by adding a penalty for having large weights (default $$10^{-8}$$).

• init – Initializer of the weights of the network (default: “xavier”).

• hybridize – If set to True the network will be hybridized before training

• callbacks – A list of gluonts.mx.trainer.callback.Callback to control the training.

• add_default_callbacks – bool, True by default. If True, LearningRateReduction and ModelAveragingCallbacks are used in addition to the callbacks specified in the callbacks argument. Make sure that you only set this to true if you don’t specify one of the default callbacks yourself or there will be “duplicate callbacks”. default callbacks: >>> callbacks = [ … ModelAveraging(avg_strategy=SelectNBestMean(num_models=1)), … LearningRateReduction( … base_lr=1e-3, # learning_rate … decay_factor=0.5, # learning_rate_decay_factor … patience=10, # patience … min_lr=5e-5, # minimum_learning_rate … objective=”min”, … ) … ]

count_model_params(net: mxnet.gluon.block.HybridBlock) → int[source]