Search⌘ K
AI Features

Functions

Explore how to define and integrate function attributes inside a PyTorch class, enabling streamlined train and validation steps by leveraging model, loss function, and optimizer attributes. Understand the use of helper functions and attribute naming conventions to improve your code organization within custom classes.

We'll cover the following...

Creating function attributes

For convenience, sometimes it is useful to create attributes that are functions, which will be called somewhere else inside the class. In our case, we can create both train_step and val_step by using the higher-order functions we defined in the chapter, Rethinking the Training Loop (helper functions #1 ...