I think I didn’t explain well my question.
Consider the following:
trainer.add_event_handler(Events.ITERATION_COMPLETED(every=1), foo)
I want to run foo() on every iteration, but only every 20 epochs.
I cant just do:
if (epoch%20==0):
trainer.add_event_handler(Events.ITERATION_COMPLETED(every=1), foo)
Because the first time epoch gets to 20, the handler will be attached to the trainer and then foo() will be called on every single iteration from then on, whether epoch%20 or not.