Plain PyTorch implementation of fast.ai notebooks

Great discussion! Here are some ways that you can learn a lot about the library, whilst also contributing to the community:

  • Pick a class, function, or method and write tests for it. For instance, here are the tests for fastai.core. Adding tests for anything without good test coverage is a great way to really understand that part of the library deeply, and have in depth conversations with the dev team about the reasoning behind decisions in the code
  • Document something that is currently undocumented. You can find them by looking for the “new methods” section in any doc notebook. Here’s a search that lists them
  • Add an example of use to the docs for something that doesn’t currently have an example of use. We’d like everything soon in the docs to include an actual piece of working code demonstrating it. Currently we’ve largely only provided working examples for stuff higher up the abstraction ladder.
37 Likes

Agree, a good test coverage and thorough documentation would be really helpful. I guess the library will get a lot of contributors during the course.

1 Like

Yeah! Totally agree on this.

I would love to write test for the library. However I have no experience on it :smiley:, I will search but appreciated if someone can give me some useful resources about it.

Then, when finish, I will do a PR on github ? I have no experience on doing a PR also so I’m sorry in advance if I bother you too much @jeremy.

Thank you

That’s great! Here’s a starting point for you:

https://docs-dev.fast.ai/test.html

Easiest is to read the source for some existing tests, and play around with them to see how they work. And read the pytest docs or a tutorial.

That’s right. It’s wonderfully easy if you install hub:

https://hub.github.com/

And it’s certainly no bother to help folks wanting to help me! :smiley:

14 Likes

I’ve moved this to the ‘advanced’ category.

I have no experience doing any of this but I’m willing to roll my sleeves up and learn while helping!!

1 Like

That’s an awesome attitude! Just yell if you need any help. :slight_smile:

@shoof @jayeshsaita @cedric @devforfu I really like the idea of moving some of the key parts of the fastai library into plain PyTorch, and, even more interestingly, extending some of the functionality. We could create both fastai-independent and dependent versions. If we enhance something sufficiently, we should create a pull request with a dependent version. I’m definitely up to help with a few key parts of this. If we get at least two people to volunteer, then we can split up responsibilities and check in on progress every now and then.

1 Like

That’s an interesting idea. However, I propose to make sure that we really understand how the library works at first, helping with tests, digging into PyTorch, building custom torch.Dataset classes, applications, meaningful PR’s, etc. Then we’ll get enough expertise, I believe, to make our own forks.

Of course, it is only my point of view, based on some experience with building training loops and data loaders. And, probably others already are quite flexible with fastai and pytorch. Anyway, would be glad to participate in fastai development, its forks, or inspired-by libraries.

3 Likes

Also this way you’ll get a lot of help from me and the team here! :slight_smile: We’ll review your code, make suggestions, and give you support if you get stuck.

8 Likes

Yes, agree, that’s the main benefit I would say! :smile: I am sure that fastai team would be a great help for anyone who wants to build something within fastai and pytorch ecosystem.

1 Like

I want to learn internals of this version of fastai.
I did go through the fastai_V1 code internals and tried implementing learner and imagedataloader class in pytorch/python.
I want to contribute to this initiative and be part of code reviews and idea discussions.

Hi @jeremy thanks for the very practical advice. Very useful for beginners like me. So i followed all the instructions to setup the developer install and ran the pytest command. Looks like test_image_data in tests/test_vision_train.py is failing.

Here is what i get:

On little experimenting in the notebook: i think the line assert abs(d.mean()-0.2)<0.1 is the reason why the test is failing. So i tried to check the real mean of the first images in the dataset. See the image below, where i try to replicate the test case.

In particular cell 31 output suggests that mean of the img - 0.2 is 0.1181 whereas the test asserts it to be less that 0.1.

I think this maybe the reason it is failing.

*this is my first time messing around with testing/contributing in an open source library. little guidance for the first time will be much appreciated. In case this is not really an issue, many apologies.

2 Likes

@jeremy Little update, if i change the assert condition mentioned above to assert abs(d.mean()-0.2) < 0.12 all the test pass. Why 0.12 because the mean of the image - 0.2 is 0.1181. Image below of all the test passing.

1 Like

Not relevant to your question but I wound advice to use pytest.approx function to compare floating point numbers.

1 Like

thanks. i will use pytest.approx and see how it goes. I am still new at this. I will make changes in the appropriate function. But not sure about next step so waiting for @jeremy’s response or someone else. not sure who to contact. Would you be able to guide for the next steps ?

opened an issue in repo. https://github.com/fastai/fastai/issues/1007

*names and email addresses are different from here to github, apologies for that.

That’s odd - the test passes for me. I’ll increase the threshold however to fix for you too.

1 Like

ICAMI, a follow-up to Vijay’s original post.

https://forums.fast.ai/t/lesson-1-learner-what-goes-on-behind-in-the-fastai-library/29346?u=cedric

In continuation of my efforts to dig deeper and understand how the fastai library works, I embarked upon the task of finding out how the ‘learner’ that we create in Lesson 1 operates. As a part of the same I have created this post and along with it a Jupyter notebook that explains the code line by line as well as a presentation (converted into pdf) on the same.

Vijay first presented this to our virtual study group in Asia where his project is attempting to understand deeper into the internals of fastai v1 ‘learner’ object, something that is currently undocumented:

  • He has deep dive into fastai v1 and deconstructed some of the codes there.
  • Go through what is behind the scene of the fastai v1.
3 Likes