Ignite: Allow both `every` and `once` args to be defined in Events.*

Created on 2 Jan 2021  路  10Comments  路  Source: pytorch/ignite

馃殌 Feature

Allow users to define both every and once arguments in Events.*
The use case is I want to log the training loss at the first iteration to check that the loss makes sense or not, and then log the training loss at every iteration.

As of today per Events docs, we can use like

e = Events.ITERATION_COMPLETED(every=100) | Events.ITERATION_COMPLETED(once=1)
@engine.on(e)
def log_loss(engine):
    ...

It would be more useful if we can use like

e = Events.ITERATION_COMPLETED(every=100, once=1)
@engine.on(e)
def log_loss(engine):
    ...

Comments are welcome!

Most helpful comment

What about allowing both every and once in Events.* ? Can you reopen for that? I think i can't

As I said previously, I think it can be a bit misleading. On the other hand if user would like to have both, this can be done with a custom filter:

e = Events.ITERATION_COMPLETED(event_filter=lambda _, ev: (ev % 100 == 0) or (ev == 1))
@engine.on(e)
def log_loss(engine):
    ...

See https://pytorch.org/ignite/engine.html#ignite.engine.events.Events

All 10 comments

@ydcjeff thanks for feature request ! I was thinking about having every and once available together and IMO it can be a bit misleading inside a single event as you suggest: Events.ITERATION_COMPLETED(every=100, once=1)...
However, I understand that it could be interesting to introduce something to simplify:

e = Events.ITERATION_COMPLETED(every=100) | Events.ITERATION_COMPLETED(once=1)

@sdesrozis what do you think ?

I agree with you. Maybe an idea could be to use the or operator as following

e = Events.ITERATION_COMPLETED(every=100 | once=1)

What do you think ?

It seems unusual to me to use or operator when passing parameters to arguments. Main motivation of this request is that attach_output_handler of WandBLogger currently doesn't accept a list of Events.

It seems unusual to me to use or operator when passing parameters to arguments. Main motivation of this request is that attach_output_handler of WandBLogger currently doesn't accept a list of Events.

This seems a bit weird, normally it should work. Do you see this runtime error here ?
https://github.com/pytorch/ignite/blob/3061d5e369f3f3ec89bf417aaf779e2c33d1a4fc/ignite/contrib/handlers/base_logger.py#L166-L167

Yes, I am seeing it.

RuntimeError: Unknown event name '<ignite.engine.events.EventsList object at 0x7ffd21678310>'

@sdesrozis could you please open another issue for that.

This check is required by BaseOutputHandler : https://github.com/pytorch/ignite/blob/3061d5e369f3f3ec89bf417aaf779e2c33d1a4fc/ignite/contrib/handlers/base_logger.py#L70-L71

@ydcjeff I think we can close this issue as #1543 has been resolved. Feel free to reopen if we need to discuss more about that.

What about allowing both every and once in Events.* ? Can you reopen for that? I think i can't

Yes, OutputHandler now accepts EventsList.

What about allowing both every and once in Events.* ? Can you reopen for that? I think i can't

As I said previously, I think it can be a bit misleading. On the other hand if user would like to have both, this can be done with a custom filter:

e = Events.ITERATION_COMPLETED(event_filter=lambda _, ev: (ev % 100 == 0) or (ev == 1))
@engine.on(e)
def log_loss(engine):
    ...

See https://pytorch.org/ignite/engine.html#ignite.engine.events.Events

Thank you for the snippet @vfdev-5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vfdev-5 picture vfdev-5  路  3Comments

UjwalKandi picture UjwalKandi  路  3Comments

alykhantejani picture alykhantejani  路  3Comments

vfdev-5 picture vfdev-5  路  3Comments

czotti picture czotti  路  3Comments