Fastai v2 daily code walk-thrus

It will be an O’Reilly book.

2 Likes

@jeremy do you think if people put questions over here during future walk-thrus, you would answer it? Similar to how the courses were set up?

does fastai have an animal or will the cover be a random one from O’Reilly’s zoo? (important questions here) :grinning:

2 Likes

If it has an animal, it should be “fast”. Like a cheetah. Or peregrine falcon.

Although… blue wildebeests reach about 50 mph. An enticing option.

(I just realized: “swift” for tensorflow. There is a definite theme.)

1 Like

It would be easier if you can put questions in the zoom chat.

17 Likes

Is that a tench?

5 Likes

It is a Boarfish, which is notable for being deeper than it is long :slight_smile:

17 Likes

The walk-thru format seems to be working great :slight_smile: Thank you so much Jeremy for doing this!

Here is what I learned on decorators today:
image
Oh no, we are losing the name! Along with it we would also lose the docstring, argument list, etc.

But fear not for functools.wraps is here!

image

Here is more information on this.

6 Likes

Thank you Jeremy, the walk-tru was great (around midnight from France but so worth it!)

The literate programming approach, with Jupyter as the editor + scripts to translate to .py and docs, is very interesting and quite different from what I know.
It’s illuminating to learn such a different way of coding.
Do you plan to describe in depth the development process and the tools you used? Will it be part of the book?

2 Likes

I did the exact same discovery while doing this just for the Metaclass in the initial few cells. Python programming learning at its best :slight_smile:

2 Likes

This seems quite important and I am not sure this behavior is widely documented. The normal flow is for __init__ to be called after __new__. __init__ gets passed as first argument whatever __new__ returns. But what happens if __new__ returns something that is not of type cls?

image

This is the usual scenario. If __new__ return an object of class cls, __init__ gets called.

But if it returns an object of a different type, __init__ does not get called!

image

So this works like this for regular classes, but does it work in the same fashion for metaclasses? :thinking:

image

yes, it does!

PS: As a sidenote, it seems we can conceptualize __new__ as literally being the constructor of an instance - it takes a class (and possibly other arguments) and returns an instance of that class. And __init__ is just an initializer - it gets passed the newly created instance (or whatever object of type cls __new__ returns and acts on it.

2 Likes

The transcript of fastai v2 walk-thru #1

1 Like

Did you find there’s somewhere in fastai v2 that we rely on that behavior? Or were you just curious? (I don’t think I was aware this happened - so if there’s somewhere in fastai that relies on this, then it might be a lucky accident!)

… seems like I am not able to convert pacific times into the correct time for Germany, so I missed watching the video live as I thought the first one would start today (Wednesday night) and not yesterday :sweat_smile: But thanks to the fast YouTube upload of the video I was able to watch it now! I took some detailed notes of the code walk-thru (hopefully I am better at taking notes than at converting timezones :smile:) and shared them here: Fastai v2 code walk-thru 1 notes

1 Like

Thanks @Honigtoast - I’ve added a link to your notes to the top post of this thread.

1 Like

I was trying to understand NewChkMeta and for that I felt I needed to take a closer look at the object model and that is how I came across this behavior. Specifically, I didn’t understand that __new__ was supposed to return an instance that would be automatically passed to __init__ and stumbled across reading about this. I haven’t seen fastai rely on this.

You got me curious @radek. Turns out it doesn’t even call __init__ of the other class!

Note that there’s nothing printed from that last cell.

2 Likes

I use and find it helpful this simple service – www.worldtimebuddy.com

Yep, thanks, that’s the tool I used too :thinking: The top post from Jeremy says it was created on “Sep 3”, so that was Tuesday and therefore I thought that

at 2.30pm pacific starting tomorrow.

will mean Wednesday 2.30pm which would be Wednesday 11:30pm here in Germany… my guess is that the time that is displayed in the forums is my local time and that would mean, Jeremy wrote the post on Monday evening and that was the thing I missed while converting the timezones :sweat_smile:

2 Likes