Lesson 10 Discussion & Wiki (2019)

good opportunity for using python partials

1 Like

That’s a great idea to start from simple things and models, and datasets at first. It is so overwhelming to write new code with huge datasets and cutting edge models. Starting simple gives you a feeling of progress and helps to make things work. And, this approach with callbacks allows one to do exactly this: gradually build the training code and models from basic to sophisticated.

3 Likes

In looking at these Python callbacks, I’m curious how much the inclusion of lots of unused callbacks can slow down training. Is it negligible to check all these if statements on every batch?

1 Like

@tamhash
If you’re looking for a book The Pragmatic Programmer is a solid choice that is easy to walk through

5 Likes

Most conflicts happen when loading other python packages built against conflicting versions of MKL and alikes. e.g. currently OSX has a problem with numpy and pytorch pip packages built against different MKL builds that conflict.

pytorch will loads its own cuda+cudnn libraries, so the conflict can only happen if you have some other python component loaded that is linked against a different version of the same library.

1 Like

The Clean Code is also an interesting thing, I would say. The classic books :smile:

5 Likes

I think that’s just how the callback there is structured. If you modify f to also print out o, you’ll see that you get a Button object: <class 'ipywidgets.widgets.widget_button.Button'>. Maybe this is in case you want f to depend on button attributes.

Like I said up there, it used to be that JIT required a proper install of CUDA the same as your PyTorch, but maybe they have changed that.

1 Like

What’s the tradeoff/best practice to help decide when to use partials or closures or class? Is it more a stylistic thing because it looks like different techniques to accomplish the same thing.

Like you said, it’s a style choice. Though if you have a function defined that you can use as a partial, it seems the best idea.

3 Likes

What do the * and ** prefixes mean?

2 Likes

args and kwargs: the main way to get lost in the fastai (and other libraries) source code :stuck_out_tongue:

7 Likes

Also, lambda’s don’t have names, and you can have a pretty name for classes with __call__ and named functions. So you can print them during debugging.

>>> x = lambda x: x + 1
>>> def func(x): return x + 1
...
>>> x
<function <lambda> at 0x7fc06abb58c8>
>>> func
<function func at 0x7fc06911f488>
2 Likes

`* is to unwrap a list: *[1,2,3] becomes 1,2,3

** is to unwrap a dictionary: **{‘a’:1, ‘b’:2} becomes a=1, b=2

Note that this only works when you pass things to a function, not directly in python.

16 Likes

agree, i often gets lost with kwargs

9 Likes

Nowadays, kwargs are only used when absolutely necessary (e.g. we have to pass things that are going to be different depending on the cases and we can unwrap them). If you spot convenience kwargs, please tell us.

2 Likes

I haven’t looked at fastai source code recently, so maybe I’m being a scandalmonger for nothing here :wink:

1 Like

Yeah, I would say that matplotlib library is especially notorious in this thing. You can’t guess all the possible arguments you can pass from the signature only. Seems that the modern libs like bokeh tend to enumerate everything in an explicit way.

`* is to unwrap a list: *[1,2,3] becomes 1,2,3
** is to unwrap a dictionary: **{‘a’:1, ‘b’:2} becomes a=1, b=2
Note that this only works when you pass things to a function, not directly in python.

This simple explanation is way too hard to find on google when you first see this usage IMO… Yours is crystal clear!

5 Likes