SOURCE CODE: Mid-Level API

Must be the FakeLoader bit.

I’ll join you. Can we maybe have a call tomorrow? I very thoroughly looked into DataLoaders and Transforms and also have a write up on TypedList from around 2-3 months ago. Would love to jump on a call and get back into this.

I use a combination of vim & tmux to step through code and Jupyter to interact with code.

Checkout lesson-3 here! https://missing.csail.mit.edu/

It’s a wonderful course by MIT on command line/ git/ vim/ editors etc :slight_smile:

3 Likes

Hey @arora_aman, thanks for the resource! Always wanted to learn vim properly but didn’t invest the time mainly due to lack of good suggestions on learning source for it! Will definitely check theirs out!

I’m playing around with it, it’s from the fastpages template so gotta adjust that css (and learn how to make it adaptable :wink: )

1 Like

Thanks for the video!

CMD + t doesn’t work unfortunately … I always get “no symbols found”. is there anything I have to do to get it to work?

Are you in the fastai2 directory in VS code?

yes, it doesn’t even find symbols in the same file …

That’s strange. Could you try doing a pip install of the fastai2 in vs code again since I believe you’re using its virtual environment where fastai2 isn’t available…

Forgot how great this is. Thanks for putting it here :slight_smile:

i had to enable workspace symbols in VSCode settings. Now it’s working :slight_smile: Thanks!

3 Likes

@florianl
Here’s what I personally do:

  1. Open up the fastai2 and fastcore folders in sublime text. (could be VS Code based on your preference)
  2. Open up a Jupyter notebook.
  3. Decide what to work on/understand and copy it’s source code into Jupyter.
  4. Read every line, put comments based on what I understand, and wade through the source code using sublime text (any IDE works) when needed.
  5. For the bits I find weird, I’d try and run something similar in the Jupyter notebook.
  6. I don’t always do a set_trace and follow through the source code. For me personally, I’ve had a lot of practice with just looking at code with parameters in my head and keeping a sort-of mental stack trace of where things are at the moment and I find this better for my purposes. Also, given the fact that there’s an insane amount of loops all over the place, I wouldn’t want to trouble myself with stepping through them in a debugger.

This ends up working very well for me. Of course, it can be different for different people.

6 Likes

Yes, very accurately guessed.

Sure, whenever you’re free.

1 Like

That’s definitely a neat approach of wading through the library’s code! :slight_smile:

One advantage of keeping a mental stack trace is that I don’t need to be on the server or Colab and be running things on a GPU. I have a fair idea of how arrays/tensors work on a GPU so I can just do this exercise on my MacBook.

Its good if we can debug and actually see the instance variable and value to understand whats happening in real time with something like pixiedebugger - https://medium.com/codait/the-visual-python-debugger-for-jupyter-notebooks-youve-always-wanted-761713babc62

OR something in jupyterlab - https://github.com/jupyterlab/debugger

Has anyone tried this before? I havent and hence checking before I do now.

Regards
Ganesh

I’ve used a similar thing in PyCharm. It definitely does help, no doubts about that. But for me personally, this helps in cases when there’s a bug in my code, not when I’m simply trying to understand someone else’s code. But that’s just me, I guess.

I was finding some new things with python while reviewing the fastai2 code which I haven’t used before so it make sense for me to actually look up the method/function, before and after the method gets applied to data in order to visually understand whats happening.

Personally for me, its important for me to visualize in my mind whats actually happening and if I can’t do that, then I don’t understand it (applies to any topic… :slight_smile:)

1 Like

Yup. I have trouble quite a few times when going through FastAI source code because there’s a lot of clever bits in it which I have never seen before. That’s the reason why I always keep a jupyter notebook on at all times so I can execute, modify and completely understand what’s there.

2 Likes

I had hard time with VS Code too, I now maintain a clone of fastai2 repo and added that as a workspace. For me code navigation in VS code is a life saver, with jupyter I’m always confused which is where.

1 Like

i debug in colab all the time. (i tried for a long time with vscode, and gave up because it was kind of … wonky)

i use ipdb in notebooks now

!pip install ipdb
import ipdb

then where you want to break use

ipdb.set_trace()

and this is the cheat sheet i use https://appletree.or.kr/quick_reference_cards/Python/Python%20Debugger%20Cheatsheet.pdf