1. Learn
  2. /
  3. Courses
  4. /
  5. Scalable AI Models with PyTorch Lightning

Connected

Exercise

Perfecting the forward method

After setting up layers in the __init__ method, the forward method dictates how data flows through them. In PyTorch Lightning, this separation keeps your code clean and easy to maintain. You've already seen how to structure the constructor-now it's time to focus on the forward pass, ensuring your classification logic is clear and optimized for training. Here, the layers in __init__ are already defined for you, so you can concentrate purely on the forward flow.

The lightning.pytorch and torch.nn have already been imported as pl and nn.

Instructions

100 XP
  • Implement the forward method inside ClassifierModel.
  • Apply a ReLU activation after the hidden layer.