yamle.utils.trainer_utils module#

class yamle.utils.trainer_utils.ValidationReporterMonitorCallback(reporter, epoch_offset=None)[source]#

Bases: Callback

This callback reports all the metrics back to the Syne-Tune Reporter.

This is happening after each validation epoch.

Parameters:
  • reporter (Reporter) – The Syne-Tune Reporter.

  • epoch_offset (int) – The offset for the epoch number. Defaults to None.

on_validation_epoch_end(trainer, pl_module)[source]#

This method reports the validation metric of choice to the Syne-Tune Reporter.

Parameters:
  • trainer (Trainer) – The PyTorch Lightning Trainer.

  • pl_module (BaseMethod) – The PyTorch Lightning Module.

Return type:

None

class yamle.utils.trainer_utils.GradientNormMonitorCallback(norm=2, frequency=10)[source]#

Bases: Callback

This callback logs the norm of the gradients of the method.

This is happening after each training batch with a given frequency.

Parameters:
  • norm (int) – The norm to be used. Defaults to 2.

  • frequency (int) – The frequency of the logging. Defaults to 10.

on_after_backward(trainer, pl_module)[source]#

This method logs the norm of the gradients of the method.

Parameters:
  • trainer (Trainer) – The PyTorch Lightning Trainer.

  • pl_module (BaseMethod) – The PyTorch Lightning Module.

Return type:

None

class yamle.utils.trainer_utils.GradientValueClippingCallback(value=None)[source]#

Bases: Callback

This callback clips the value of the gradient to a min and max.

on_after_backward(trainer, pl_module)[source]#

This method clips the value of the gradient to a min and max.

Parameters:
  • trainer (Trainer) – The PyTorch Lightning Trainer.

  • pl_module (BaseMethod) – The PyTorch Lightning Module.

Return type:

None

class yamle.utils.trainer_utils.L1L2MonitorCallback[source]#

Bases: Callback

This callback logs the L1 and L2 norm of the parameters of the method.

This is happening after each training epoch.

on_train_epoch_end(trainer, pl_module)[source]#

This method logs the L1 and L2 norm of the parameters of the method.

It logs the L1 and L2 norm of the parameters of the method. It calculates the total norm as well as per model part norm.

Parameters:
  • trainer (Trainer) – The PyTorch Lightning Trainer.

  • pl_module (BaseMethod) – The PyTorch Lightning Module.

Return type:

None

class yamle.utils.trainer_utils.WeightHistogramMonitorCallback[source]#

Bases: Callback

This callback logs the histogram of the weights of the method.

This is happening after each training epoch.

on_train_epoch_end(trainer, pl_module)[source]#

This method logs the histogram of the weights of the method.

Return type:

None

class yamle.utils.trainer_utils.RegularizedWeightsMonitorCallback[source]#

Bases: Callback

This callback logs the regularized weights of the method on the start of the training.

on_fit_start(trainer, pl_module)[source]#

Called when fit begins.

Return type:

None

class yamle.utils.trainer_utils.SplitParametersMonitorCallback[source]#

Bases: Callback

This callback logs how the parameters are split between different optimizers at the start of the training.

on_fit_start(trainer, pl_module)[source]#

Called when fit begins.

Return type:

None

class yamle.utils.trainer_utils.NoOptimizationMonitorCallback[source]#

Bases: Callback

This callback logs which parameters are not optimized at the start of the training.

on_fit_start(trainer, pl_module)[source]#

Called when fit begins.

Return type:

None

class yamle.utils.trainer_utils.LoggingCallback[source]#

Bases: Callback

This callback updates, logs and resets all the metrics.

This is happening after each training, validation or test epoch.

on_train_batch_end(trainer, pl_module, outputs, batch, batch_idx)[source]#

This method is used to update the training metrics after each training step.

Return type:

None

on_validation_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)[source]#

This method is used to update the validation metrics after each validation step.

Return type:

None

on_test_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)[source]#

This method is used to update the test metrics after each test step.

Return type:

None

on_train_epoch_start(trainer, pl_module)[source]#

This method is used at the start of each training epoch.

Return type:

None

on_train_epoch_end(trainer, pl_module)[source]#

This method is used to log the training metrics at the end of each training epoch.

Return type:

None

on_validation_epoch_start(trainer, pl_module)[source]#

This method is used at the start of each validation epoch.

Return type:

None

on_validation_epoch_end(trainer, pl_module)[source]#

This method is used to log the validation metrics at the end of each validation epoch.

Return type:

None

on_test_epoch_start(trainer, pl_module)[source]#

This method is used at the start of each test epoch.

Return type:

None

on_test_epoch_end(trainer, pl_module)[source]#

This method is used to log the test metrics at the end of each test epoch.

The reset is performed manually in the Trainer class.

Return type:

None

class yamle.utils.trainer_utils.ValidationModelSavingCallback(task)[source]#

Bases: Callback

This callback saves the best model given a validation metric.

The metric is decided by the main metric given by the task. It comes from MAIN_METRIC.

Parameters:

task (str) – The task of the method.

on_validation_epoch_end(trainer, pl_module)[source]#

This method saves the best model given a validation metric.

Return type:

None

class yamle.utils.trainer_utils.TrainingModelSavingCallback[source]#

Bases: Callback

This callback saves the model at the end of the training epoch.

on_train_epoch_end(trainer, pl_module)[source]#

This method saves the model at the end of the training epoch.

Return type:

None

class yamle.utils.trainer_utils.InitialModelSavingCallback[source]#

Bases: Callback

This callback saves the model at the start of the training.

on_fit_start(trainer, pl_module)[source]#

This method saves the model at the start of the training.

Return type:

None