Lesson 9: understanding callbacks and runner class

In Lesson 9 on Callbacks I’m really struggling to understand what the class Runner is doing and how it interacts with the refactored Callback class.

Problem 1. What does this code do in class Callback?

    def set_runner(self, run): 
        self.run=run
        
    def __getattr__(self, k): 
        return getattr(self.run, k)

The callbacks get access to the Runner that they are passed to? Then do all attributes of the Callback become self.run.attr instead of self.attr?

Problem 2. Looking at the class AvgStatsCallback it references an attribute self.in_train, but this doesn’t get set in this class or its parent class. It seems that it gets set in another callback class TrainEvalCallback, which is called by default by Runner, right? I could only figure that out from the source code. If I’m writing my own Callback subclass is there some contract of attributes that I can rely upon existing?
Thanks.

Hi @jimypbr - I wouldn’t worry about the runner class…b/c as you’ll see in Lesson 10 or so, it gets removed never to appear again either for that course or in FastAI2 :slight_smile:

Thus may make sense to just jump to the next lessons and runner will disappear before you know it.
Hope that helps!

8 Likes