Skip to content

Conversation

@sdesrozis
Copy link
Contributor

Fixes #1543

Description:

Allow EventsList in BaseLogger attachment. The key point is to attach each event independently as it is done in Engine.

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@sdesrozis sdesrozis requested a review from vfdev-5 January 5, 2021 13:55
Copy link
Contributor

@ydcjeff ydcjeff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you!

:class:`~ignite.engine.RemovableEventHandle`, which can be used to remove the handler.
"""
name = event_name
if isinstance(event_name, EventsList):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use return engine.add_event_handler(event_name, log_handler, self, event_name) for any type of events. Below for loop if considered without check if name not in State.event_to_attr is exactly what is done by Engine.add_event_handler.
I think we can simply generalize event checking like

event_to_check = event_name if isinstance(event_name, EventsList) else [event_name, ]
for name in event_to_check:
    if name not in State.event_to_attr:
        raise RuntimeError(f"Unknown event name '{name}'")

return engine.add_event_handler(event_name, log_handler, self, event_name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does not work.

The last argument of the method add_event_handler is a list of events. Internally in engine, there is a loop where the handler is attached at every event in the list. But the list is forwarded to each handler while just each event should be.

If there was no argument to the method, it would work.

Thoughts ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. In this case, my suggestion is not valid. OK, let's do it as you proposed.

Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @sdesrozis !

I let you merge it.

@sdesrozis sdesrozis merged commit 5ceacbb into pytorch:master Jan 5, 2021
@sdesrozis sdesrozis deleted the issue_1543 branch January 5, 2021 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to attach output handler using event list

3 participants