How can you learn to use the @fastdotai framework to its fullest extent? A thread on what I believe is the most important lesson you can teach yourself: π
1/
First: fixing a misconception. At its core, fastai is just PyTorch. It uses torch tensor, trains with the torch autograd system, and uses torch models.
Don't believe me? Let's talk about how you can learn to see this and utilize it
2/
Start with the PETS datablock + dataloaders, but write your own pytorch loop. Use cnn_learner if you want to start, and grab the model in learn.model
Train your model in the torch loop, and see that we can achieve (similar) scores.
3/
Don't go for fit_one_cycle when doing this, or any complex scheduler. Just use fit.
Start with completely unfreeze the model, then freeze it in fastai and pytorch. Learn what the training API is wrapping for you.
But what about the data?
4/
Use PyTorch datasets and DataLoaders, rebuild the PETS dataset with it, and use it with cnn_learner. You'll need to specify a .c attribute on them though, so cnn_learner knows how to build your model.
5/
Once you've seen how both work, bring it together. Torch loaders, a torch model, and a torch loop.
And then, go the other end (or almost) torch loaders, torch model, and fastai's base Learner class.
6/
What did this exercise teach?
It opened your eyes to how fastai really works, and how you can swap and switch it for anything in pytorch yourself.
After this, really dive deep into the callback system to understand what and how fastai's training loop is done.
7/
I have a video on this here:
8/8
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
I've written a notebook showing three additional functions for helping you navigate the @fastdotai source code and save you potentially hours of time: gist.github.com/muellerzr/3302β¦
1/
Why did I write this? Navigating the source code for fastai can be hard sometimes, especially trying to consolidate all the patch and typedispatch functionalities (especially because typedispatch doesn't show up in the __all__!)
So, how does this work? 2/
The first function, `trace_class`, will grab all functions in a class up to a particular library. This is helpful in scenarios where a class inherits something (like a torch tensor) but you only care about the super class level (like TensorBase):
I got asked a question at the end of my stream by @lukemshepherd I didn't quite get to answer:
βDo you have any advice for someone who wants to get into contributing to the @fastdotai library who has experience with fastai but not software development?
Let's try to answer:
If you have absolutely zero, I recommend watching the first few lectures in the latest part 2 (yes of a few years ago!). Since it's building a library from scratch, Jeremy covers how he approaches software design, which can help you understand the design
From there, start small. Look at the simpler areas of the library, and try and add some documentation, etc. Then slowly build yourself towards not understanding how fastai works, but how the DESIGN process works. Apply yourself towards seeing how classes interact, etc
With school over, I'll reveal one of my secrets. I'm making a new course!
Running with @fastdotai! Times and dates are TBD, but I'm shooting for this Fall to hold the course. This will be a continuation on Walk with fastai, building on what we learned there and applying it 1/
The plan is to split it up into three sections: Debugging, Implementations, and Guest Speakers.
The first section I want to be covering debugging in fastai, bringing raw torch code over (direct 1:1 conversions), and exploring inference heavily
The second will be walking through a few implementations of other libraries that have used fastai (and writing one or two ourselves) in a much more complex manor rather than "set your data up so the DataBlock works". Situations will arise where the DataBlock doesn't exist yet!
It's a very big day for me today, as I'm officially releasing version 0.2.3 for the @AdaptNLP project. With it comes a slew of changes, but what exactly?
Thanks to the lib2nbdev package (novetta.github.io/lib2nbdev), we've completely restructured the library to become test-driven development with nbdev, with integration tests and everything else that comes with the workflow 2/9
Next @fastdotai and #fastcore, I'm restructuring the internal inference API to rely on fastai's Learner and Callback system, to decouple our code and make it more modularized. With the fastai_minima package as well, only the basic Learner and Callback classes are being used: 3/9
Deploying with @fastdotai isn't always learn = load_learner(), learn.predict. There are numerous scenarios when you might only want some, part, or none of both the API and the library as a whole. In this thread we will be exploring your options, how they work, and what to do: 1/n
Ideally we have the following context:
DataBlock -> DataLoaders -> Model -> Learner -> Train
This can then stem off to a few things:
1. learn.export() -> Model and DataLoaders (which are now blank) ...
In this scenario, we need to ensure that ALL functions which were used in relation to the data are imported before loading in the learner. This can run into issues when using fastAPI and other platforms when loading in the Learner is done in a multi-process fashion 3/