PyTorch - Python Deep Learning Neural Network API

Deep Learning Course 4 of 6 - Level: Intermediate

How to Debug PyTorch Source Code - Deep Learning in Python


expand_more chevron_left


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(

image, label = train_set[0]


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.


expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Quiz Results


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 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: πŸ”— πŸ’» DOWNLOAD ACCESS TO CODE FILES πŸ€– Available for members of the deeplizard hivemind: πŸ”— ❀️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Tammy BufferUnderrun Mano Prime πŸ‘€ Follow deeplizard: Our vlog: Facebook: Instagram: Twitter: Patreon: YouTube: πŸŽ“ Deep Learning with deeplizard: Deep Learning Dictionary - Deep Learning Fundamentals - Learn TensorFlow - Learn PyTorch - Reinforcement Learning - Generative Adversarial Networks - πŸŽ“ Other Courses: Data Science - Trading - πŸ›’ Check out products deeplizard recommends on Amazon: πŸ”— πŸ“• Get a FREE 30-day Audible trial and 2 FREE audio books using deeplizard's link: πŸ”— 🎡 deeplizard uses music by Kevin MacLeod πŸ”— πŸ”— ❀️ Please use the knowledge gained from deeplizard content for good, not evil.


expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Update history for 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.