Ignite: Communication between callbacks?

Created on 7 Mar 2018  路  3Comments  路  Source: pytorch/ignite

Hi developers, thanks for this nice library! I was wondering if you have ideas about how to communicate some state between callbacks?
For my specific use-case, I have 2 callbacks attached to the COMPLETED event of my Evaluator. One computes an average-precision value from the data gathered in the Evaluator's state during the epoch. The other callback saves a checkpoint. I would like to have this average-precision information available to the second callback, so that it can only checkpoint if the AP is the best so far.

Right now my checkpoint callback decides whether to checkpoint based on the validation loss, which is something I can include in the Evaluator state through the output of the function run in every iteration. But I don't know how to include the AP information in the Evaluator state, since it is calculated in a callback.

Hopefully I've explained my situation properly. I am also open to suggestions about changing my code organization, if it solves my problem.

Most helpful comment

@samarth-robo That approach will definitely work but there is another option. You can attach arbitrary data to the state object. In fact that's one of the major use cases. So you could do this in the first callback:

state.precision = ...

And then in the checkpoint callback you can access state.precision to make the decision.

This is still largely undocumented at this point but I'm working on that now.

All 3 comments

I realized one way is to make both callbacks parts of a class and maintain the best AP value in the class. So closing this issue. Feel free to re-open if you have a better suggestion.

@samarth-robo That approach will definitely work but there is another option. You can attach arbitrary data to the state object. In fact that's one of the major use cases. So you could do this in the first callback:

state.precision = ...

And then in the checkpoint callback you can access state.precision to make the decision.

This is still largely undocumented at this point but I'm working on that now.

Hi @samarth-robo,

As @jasonkriss mentioned, we recently added the State object (sorry for the API change) to primarily facilitate cross-handler communication. I would recommend using that, and as @jasonkriss said documentation is in progress - so please feel free to open issues with questions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vfdev-5 picture vfdev-5  路  4Comments

vfdev-5 picture vfdev-5  路  3Comments

alykhantejani picture alykhantejani  路  3Comments

czotti picture czotti  路  3Comments

vfdev-5 picture vfdev-5  路  3Comments