Eight ways to debug in fastai

UPDATE I learned about more options since posting the thread and recorded a followup video https://www.youtube.com/watch?v=xovzuPfuglE. Timestamps to the all 8 ways are at the bottom of this post.

Hello folks!

After watching the Lesson 1, I’ve decided to spend some time on figuring out ways to debug and explore fastai. Since I know from experience I’ll be doing it a lot during the course.
I figured it might be useful for others, especially beginners, so I made a video tutorial out of it: https://www.youtube.com/watch?v=T1RJvUZieig

There is nothing groundbreaking here, things you can know from previous courses, forums or tutorials. But I hope there will be people who find it useful.

I’m using the Lesson 1 notebook as the starting point and the five ways are: logging, pdb, pixiedust, VS code, and notebook juggling. You can jump directly to these timestamps:

38 Likes

That was great, thanks Slawek!

1 Like

Thanks @slawekbiel! I have a question. It is slightly unrelated to debugging, but I got curious haha I noticed that the show_batch function is defined multiple times. How is that possible? Wouldn’t one conflict with the other? For example, you showed there was a show_batch function calling another show_batch function (which you copied from another notebook). My intuition would be that a recursive call would occur there, but actually both of them continued existing even though they had the same name. That’s counter intuitive to me that’s why I decided to ask. Not sure how I would google that hahah Thanks!

UPDATE: I just found in this reference from fastai:

TypeDispatch — allows for the same function to work differently for different types

So, that means that by using the @typedispatch decorator, I can declare the very same function multiple times, but have it to act differently depending on it’s input type. Is that correct?

Yes, you got it right. TypeDispatch is basically a DIY function overloading,

@typedispatch
def foo(x:int): print(x,'is an int')
    
@typedispatch
def foo(x:str): print(x,'is a string')
    
@typedispatch
def foo(x): print(x,'is something else')
    
foo(42)
foo('bar')
foo(3.14)

Great content! Have you tried the new visual debugger from Jupyter Lab?

I can’t seem to make it work with fastai v2.

1 Like

I just learnt about it today, I’ll report back here if I get it to work.

I see that it is forty minutes long, and I find that a bit discouraging. In other words, I wasn’t sure if I should invest the time to fast forward through it.

Do you think you could highlight the “five ways to debug in fastai”, for example in the video description, or even in a separate notebook?

That’s a very valid point. I actually didn’t expect this to be this long (I have no experience in content creation). If you have limited time, you’d get a much better return on time invested by listening to someone who’s more knowledgable and a better speaker, like Jeremy Howard :slight_smile:

Anyway the five things I talk about is:

  • putting print statements into the fastai code
  • using pdb in jupyter
  • using pixiedust in jupyter
  • running development notebooks from fastai
  • debugging a local script with vscode

I actually learned about two more ways since. I’m yet to explore:

  • connecting vscode to a running notebook instance
  • installing a newly created debugger inside jupyter lab.

You can learn about any of this by googling, searching the forums and experimenting on your own.

1 Like

Great content. Is your VSCode running in WSL2 ?

No, it’s the old one.I have no nvidia GPU on my desktop anyway so I’m just using it to read the code.

Cool, could you tell me how you’re running vscode on headless WSL1? An X-Server or something? Or provide any links you used to setup?

PS - I know I can also just google this info (and I have before) but I see many conflicting reports on WSL. I want mine to work just like the way you have it running.

May I suggest that you include timestamps?

And you haven’t updated your video with the description on YouTube!

I followed this

1 Like

I edited the top post with it

1 Like

Me too.
I got it running on simple functions like

def add(a:int, b:int) -> int:
    s = a + b
    return s

but stepping through fastai2 code I couldn’t figure how to view the fastai source
code once you try to step inside the function code.

I think its still in its early days of development (especially documentation).

BTW, it uses a xeus-python kernel instead of the regular one so you’ve got to open your notebook using that.

HTH.
Best regards,
Butch

Thanks! Here is my question, does anyone have an idea on how to do memory profiling for the GPU? In a way that is easy enough for a beginner to understand?

I got it to step inside fastai functions. You can see it at this timestamp

Hi @slawekbiel,

How did you install the fastai2 library?
On your video, I noticed that the path of the fastai2 source code seemed to
be on the same directory as your notebook, is this correct?

My mistake is maybe that I just did a pip install fastai2
Also I saw in the video you the problem you had with training the model so this
might not be the best debugging solution right now.

Thanks for posting the videos, BTW!
Best regards,
Butch

Cloned the repo and run

pip install -e ".[dev]"

@slawekbiel,
Thanks!
I’m trying your other suggestions (VS code) right now.

Best regards,
Butch