10 Adopting PyTorch Lightning

 

This chapter covers

  • Implementing PyTorch Lightning to reduce boilerplate code
  • Adding training, validation, and test support for the DC taxi model
  • Analyzing DC taxi model training and validation using pandas

Thus far, you have written your own implementation related to training and testing your machine learning model. However, much of the code you wrote was unrelated to your machine learning model architecture and could have applied to a broad range of distinct models. Building on this observation, this chapter introduces you to PyTorch Lightning, a framework that can help you reduce the amount of boilerplate engineering code in your machine learning system, and consequently help you focus on evolving your model design and implementation.

10.1 Understanding PyTorch Lightning

This section introduces the PyTorch Lightning framework for your PyTorch DC taxi fare estimation model and teaches you the steps involved in enabling PyTorch Lightning training, validation, and test features.

Thus far, you have implemented a sizable portion of Python and PyTorch boilerplate code for your machine learning model. This meant that only a few parts of your implementation were model specific, such as the code to

  • Package the feature values as tensors
  • Configure the neural net layers
  • Calculate the tensors for the loss
  • Report on the model metrics

10.1.1 Converting PyTorch model training to PyTorch Lightning

10.1.2 Enabling test and reporting for a trained model

10.1.3 Enabling validation during model training

Summary