synicix_ml_pipeline.trainers package¶
Submodules¶
synicix_ml_pipeline.trainers.NNTrainer module¶
-
class
synicix_ml_pipeline.trainers.NNTrainer.
NNTrainer
(train_dataloader, validation_dataloader, test_dataloader, device, model_class, model_class_params, optimizer_class, optimizer_class_params, criterion_class, criterion_class_params, model_save_path, max_epochs, training_strip_length, sucessive_validation_score_decline_tolerance, fp16=False, fp16_opt_level=None)[source]¶ Bases:
object
NNTrainer is a trainer class provided with synicix_ml_pipeline. It handles training and saving/loading of models with some additional useful features.
One of the most notable features it provide is integrated fp16 or mixed precision training which can drastically improve your network training speed at little to no loss in performance This is provided via Nvidia’s the apex libaray: https://github.com/NVIDIA/apex
The other feature is a built in early stoping algorithm which was implemented base off this paper: https://page.mi.fu-berlin.de/prechelt/Biblio/stop_tricks1997.pdf
-
eval_step
(data, return_outputs_targets_and_loss=False)[source]¶ Evluate step function to handle training of one batch
- Parameters:
- data (tuple): Data point sample obtain from pytorch dataloader return_outputs_targets_and_loss If true then it will return outputs_targets_and_losses as a dict
- Returns:
- float: Model’s test dataset loss if return_outputs_targets_and_loss False dict(outputs, target, loss): If return_outputs_targets_and_loss True
-
evaluate
(return_outputs_targets_and_loss=False)[source]¶ Run the test dataset through the model and return the average loss
- Parameters:
- return_outputs_targets_and_loss (bool): If true then it will return outputs_targets_and_losses as a dict
- Returns:
- float: Model’s test dataset loss if return_outputs_targets_and_loss False dict(outputs, target, loss): If return_outputs_targets_and_loss True
-
load_best_performing_model
()[source]¶ Load the best performing model which is the previous save file of the lowest validation score form model_save_path
Parameters: Returns:
None
-
load_model
(path)[source]¶ Load model, optmizer, and amp from path
- Parameters:
- path (str): path of where to load model file from
- Returns:
- None
-
save_model
()[source]¶ Save model optmizer, and amp to model_save_path
- Parameters:
- None
- Returns:
- None
-
should_early_stop
(current_epoch)[source]¶ Checks wheter to early stop or not based on the the previous validation score and training strip performance
- Parameters:
- current_epoch (int): Current epoch, mainly use for printing
- Returns:
- bool: Whether to early stop or not
-