Lightning AI Studios: Never set up a local environment again →

Log in or create a free account to track your progress and access additional course materials  

Unit 9.4 Compiling PyTorch Models



What we covered in this video lecture

In this lecture, we covered torch.compile, which is a new feature in PyTorch 2.0 that allows you to speed up your PyTorch code by JIT-compiling it into optimized kernels. Torch.compile is a fully additive feature, which means that it does not require you to make any changes to your existing code.

As we’ve seen, to use torch.compile, we can simply use the torch.compile() function for an exisiting PyTorch model without making any further modifications. The torch.compile function will then compile the model into an optimized kernel the first time it is called. Subsequent calls to the function or module will be much faster, as they will be executed directly on the GPU.

Additional resources if you want to learn more

I highly recommend reading the official PyTorch 2.0 article, which delves into additional details explaining how torch.compile works under the hood.

Log in or create a free account to access:

  • Quizzes
  • Completion badges
  • Progress tracking
  • Additional downloadable content
  • Additional AI education resources
  • Notifications when new units are released
  • Free cloud computing credits

Quiz: 9.4 Compiling PyTorch Models (PART 1)

What is the primary purpose of the graph lowering process in PyTorch?

Correct. This transformation is essential for optimization and efficient execution on certain hardware platforms.

Incorrect. This is not the primary benefit of graph lowering, although it could potentially make it easier to develop and debug visualization software.

Incorrect. The model size stays untouched.

Please answer all questions to proceed.

Quiz: 9.4 Compiling PyTorch Models (PART 2)

We have seen that PyTorch torch.compile can speed up the model training. However, what are some of the limitations of torch.compile?





Please answer all questions to proceed.
Watch Video 1

Unit 9.4