Introducing Higher-Order Functions
Explore how higher-order functions can streamline PyTorch training loops by generating custom training step functions. Understand the concept of functions returning functions and see how this functional programming approach applies to different models, losses, and optimizers.
We'll cover the following...
Using different optimizers, loss, and models
We finished the previous chapter with an important question:
“Would the code inside the training loop change if we were using a different optimizer, loss, or even model?”
Below, you will find the commands that run the data generation, data preparation, and model configuration parts of our code:
Next is the code for the training of the model:
Below, after running the code, you will get the parameter values of the linear model:
GPU users will get an output similar to the following:
So, I guess we could say all these lines of code (5-21 of model ...