Understanding the init function of the Runner class

(Kushal) #1

I am not able to understand the meaning of the two arguments and what they essentially stand for. From my understanding, cbs is callbacks and cb_funcs is callback_functions. But how are they different? Also, according to the loop, we are calling the callback_functions and adding them to the list of callbacks. Is that it ? What is going on over here? What am I missing?


(Akash Palrecha) #2

I see why you’re potentially confused. On the first look, it may seem as if all the functions that you may pass in cb_funcs will eventually be appended to cbs. Then why not just pass them along with cbs?

Here’s why:
Notice the line setattr(self, cb.name, cb) inside the for loop. This makes every function passed in cb_func accessible through its class name.
The Callback class contains this code which makes it possible:

def name(self):
        name = re.sub(r'Callback$', '', self.__class__.__name__)
        return camel2snake(name or 'callback')

This allows you to easily refer to the callbacks you passed in by their name and get access to some of their potentially useful inner states (maybe metrics, etc.)
You cannot similarly refer to the callbacks you passed in through cbs. Although you could index into them surely. But that doesn’t look ideal I guess.

Also, if you go further into the notebook you’ll notice:

Here Jeremy refers to a callback in the exact way that I just talked about.