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

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

2.5 Debugging Code

References

What we covered in this video lecture

In this lecture, we saw how we could use pdb as an alternative to print statements for debugging code. Using a debugger to find and fix errors in your code is not a requirement. However, it can make your life easier. There is definitely a learning curve to it, and it takes time to become comfortable with using it.

Additional resources if you want to learn more

While pdb is the most fundamental debugger, many people prefer visual debuggers. Check out the resources below if you want to learn more:

Log in or create a free Lightning.ai 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: 2.5 Debugging Code

Suppose we have the following code, c = a + b, which raises a TypeError.

To find the cause for the TypeError, we want to inspect the values of a and b using the pdb debugger. If we want to drop into the interactive debugger to evaluate the values a and b, we place the line import pdb; pdb.set_trace() before or after c = a + b?

Correct. We need to insert the set_trace() command before the error occurs.

Incorrect. We need to insert the set_trace() command after the error occurs.

Suppose we have the following code, c = a + b, which raises a TypeError.

What are good options for evaluating the values of a and b to find out why the TypeError is raised?

Correct. We need to insert the set_trace() command before the error occurs.

Incorrect. We need to insert the set_trace() command after the error occurs.

Incorrect. Post-mortem is used to inspect code after the error occurs.

Incorrect. Post-mortem is used to inspect code after the error occurs, but it also requires the try-except.

Incorrect. The post_mortem mode should be entered when an exception is raised, not the other way around.

Correct. The post_mortem mode should be entered when an exception is raised.

Please answer all questions to proceed.
Watch Video 1

Unit 2.5

Videos
Follow along in a Lightning Studio

DL Fundamentals 2: Tensors and PyTorch

Sebastian
Launch Studio →
Questions or Feedback?

Join the Discussion