Eight ways to debug in fastai

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

Thanks for taking the time to do these videos @slawekbiel I found them instructive and will be recommending them to my team as a quick intro to python debugging!

@Antoine.C I watched the whole video on 2x speed, stopping here and there for taking notes. Great stuff and totally worth it.

@butchland @slawekbiel @farid
Late to the party, but for future reference, I followed Farid Hussainia’s blog:

3 ways to pip install a package - fastai2 use case

One difference (but not the only) with the recommended install is the use of

pip install -e .

instead of
pip install -e ".[dev]"

Farid explains why in this section of his post.

2 Likes

Good to know, I’ll keep that in mind if I run into issues with nbdev

Thank you for your kind words! It makes me happy that people find it useful.

1 Like

Thank you @Antoine.C for sharing the blog post.

As a best practice, it’s good to install the editable version of both fastai2 and fastcore, and update them at the same time in order to have both packages aligned.

@slawekbiel, Thank you for sharing your videos. I’m a heavy user of VS Code in both windows and Linux, I find it super useful despite the fact that its Jupyter notebook version is not on par with the official one. As a matter of fact, I wrote the entire timeseries package (see description here) using VS Code and the Python extension. I find it more practical to both be able working on a Jupyter notebook and easily navigate the source code. I have a fastai2 workspace that I always keep open so I can easily jump from my package to the fastai2 one.

I’d like to hijack the thread and ask if anyone knows of a way to achieve what I think of as the “holy grail” of debugging in datascience… attaching the VSCode debugger onto a running jupyter/IPython kernel and following the call stack down for any particular RunCell.

To do this I have to copy a notebook’s content into a .py file and then launch in debug mode in vscode. This is suboptimal when I’ve run cells out of order, or there is some object, like a learn.fit(), that takes a long time to run before reaching the breakpoint of interest.

I agree with you. Unfortunately, it looks like that option doesn’t exist yet based on my recent search: I hope I’m wrong because I can’t wait to see that happen: That will be a game changer.

1 Like

HI. Do we have a way to put an pdb.set_trace() to fastai library without modifying its source code (the lib is not installed by pip -e). I find in fastcore the trace() function and its source code as below.

def trace(f):
    "Add `set_trace` to an existing function `f`"
    def _inner(*args,**kwargs):
        set_trace()
        return f(*args,**kwargs)
    return _inner

So I’m thinking about kind of monkey-patching the original source code by putting trace as a decorator.

@trace
def func_to_debug(*args, **kwargs):

But really don’t know how to do it. Is it approach possible ? Thanks

With that you can just do:
ImageDataLoaders.from_dblock = trace(ImageDataLoaders.from_dblock)
and now this will break inside the function I substituted.

Alternatively you can invoke pdb earlier and then set a breakpoint with the b command. Like this:

(Pdb) b ImageDataLoaders.from_dblock
Breakpoint 1 at /notebooks/fastai2/fastai2/data/core.py:157
(Pdb) c
> /notebooks/fastai2/fastai2/data/core.py(159)from_dblock()
3 Likes

Great! Thanks, I will try it

I specially registered an account to clike a like! Thanks for the video, it really helps me a lot and improve me to debug deeper! Almost I’m just ready to give up, but find someone try a lot to do the same thing and do better.