pytorchnewbie:

Exactly… so then normally the value of trainer.state.epoch shouldn’t be 0 every single time the event handler is triggered?


Well, it is more like the following:
def foo(x):
    print(x)
    

handlers = []

def add_handler(fn, args):
    handlers.append((fn, args))
    
    
def execute():
    for h, args in handlers:
        h(args)
        

epoch = 0

# args are registered with value 0
add_handler(foo, epoch)

execute()

# even if we update the variable, registered args are not changed
epoch = 1

execute()