Neural Network Programming - Deep Learning with PyTorch

Deep Learning Course 3 of 4 - Level: Intermediate

How to Debug PyTorch Source Code - Deep Learning in Python

video

expand_more chevron_left

text

expand_more chevron_left

How to Debug PyTorch Source Code

Welcome to deeplizard. My name's Chris. In this episode, we're going to see how we can debug PyTorch source code using the Visual Studio Code IDE.

Without further ado, let's get started.

Getting Started Debugging PyTorch

The first step, of course, is to get Visual Studio Code installed on your system. Once this is complete, we are ready to go.

A Program to Debug

To debug, we need a program that we can use to kick things off.

We have created a sample program here that we're going use to debug some PyTorch source code. We're going debug the Fashion MNIST dataset which actually lives in the torchvision package. But nonetheless, everything is going be the same.

import torch
import torchvision
import torchvision.transforms as transforms

train_set = torchvision.datasets.FashionMNIST(
    root='./data'
    ,train=True
    ,download=True
    ,transform=transforms.Compose([
        transforms.ToTensor()
    ])
)

image, label = train_set[0]

print(image.shape)

How to Debug

In order to debug any python code in Visual Studio Code, we need toe install the python debugging extension. This will give us debugging capabilities. Once the debugging extension is installed, we follow these steps.

  1. Place a breakpoint
  2. Run the program in debug mode
  3. Use Keyboard to manually control program execution
  4. Step into something PyTorch

Note that there is an additional requirement to debug imported libraries like PyTorch. We need to set the justMyCode attribute to false inside the launch.json file for VS Code.

Below is an example launch configuration.

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "justMyCode": false,
    "cwd": "${fileDirname}"
}

Debugging code is one of the absolute best ways to understand what's going on. Note that we don't have to write a lot of code to actually get set up to debug PyTorch. In our example it was just 15 or 16 lines of code.

To debug PyTorch source code, we simply need a path into the PyTorch code we want to debug.

quiz

expand_more chevron_left

resources

expand_more chevron_left
In this episode, we learn how to set up debugging for PyTorch source code in Visual Studio Code. 🕒🦎 VIDEO SECTIONS 🦎🕒 00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources 00:27 Visual Studio Code 00:55 Python Debugging Extension 01:30 Debugging a Python Program 03:46 Manual Navigation and Control of a Program 06:34 Configuring VS Code to Debug PyTorch 08:44 Stepping into PyTorch Source Code 10:36 Choosing the Python Environment 12:30 Collective Intelligence and the DEEPLIZARD HIVEMIND 💥🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎💥 👋 Hey, we're Chris and Mandy, the creators of deeplizard! 👀 CHECK OUT OUR VLOG: 🔗 https://youtube.com/deeplizardvlog 👉 Check out the blog post and other resources for this video: 🔗 https://deeplizard.com/learn/video/el39D7rz7K0 💻 DOWNLOAD ACCESS TO CODE FILES 🤖 Available for members of the deeplizard hivemind: 🔗 https://deeplizard.com/resources 🧠 Support collective intelligence, join the deeplizard hivemind: 🔗 https://deeplizard.com/hivemind 🤜 Support collective intelligence, create a quiz question for this video: 🔗 https://deeplizard.com/create-quiz-question 🚀 Boost collective intelligence by sharing this video on social media! ❤️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Tammy Prash Guy Payeur Christian Sikuq 👀 Follow deeplizard: Our vlog: https://youtube.com/deeplizardvlog Facebook: https://facebook.com/deeplizard Instagram: https://instagram.com/deeplizard Twitter: https://twitter.com/deeplizard Patreon: https://patreon.com/deeplizard YouTube: https://youtube.com/deeplizard 🎓 Deep Learning with deeplizard: Fundamental Concepts - https://deeplizard.com/learn/video/gZmobeGL0Yg Beginner Code - https://deeplizard.com/learn/video/RznKVRTFkBY Intermediate Code - https://deeplizard.com/learn/video/v5cngxo4mIg Advanced Deep RL - https://deeplizard.com/learn/video/nyjbcRQ-uQ8 🎓 Other Courses: Data Science - https://deeplizard.com/learn/video/d11chG7Z-xk Trading - https://deeplizard.com/learn/video/ZpfCK_uHL9Y 🛒 Check out products deeplizard recommends on Amazon: 🔗 https://amazon.com/shop/deeplizard 📕 Get a FREE 30-day Audible trial and 2 FREE audio books using deeplizard’s link: 🔗 https://amzn.to/2yoqWRn 🎵 deeplizard uses music by Kevin MacLeod 🔗 https://youtube.com/channel/UCSZXFhRIx6b0dFX3xS8L1yQ 🔗 http://incompetech.com/ ❤️ Please use the knowledge gained from deeplizard content for good, not evil.

updates

expand_more chevron_left

Updates to the information on this page!

Did you know you that deeplizard content is regularly updated and maintained?

  • Updated
  • Maintained

Spot something that needs to be updated? Don't hesitate to let us know. We'll fix it!


All relevant updates for the content on this page are listed below.

So far, so good! The content on this page hasn't required any updates thus far.