-
-
Notifications
You must be signed in to change notification settings - Fork 656
Description
🐛 Bug description
From the documentation it seems that the event TERMINATE_SINGLE_EPOCH is only fired, if engine.terminate_epoch is called.
I discovered, that the event is also fired, if I call engine.terminate inside of an epoch as can be seen in the code linked below.
Event description:
ignite/ignite/engine/events.py
Lines 161 to 162 in 51d3e3e
| - TERMINATE_SINGLE_EPOCH : triggered when the run is about to end the current epoch, | |
| after receiving :meth:`~ignite.engine.engine.Engine.terminate_epoch()` call. |
Current implementation:
ignite/ignite/engine/engine.py
Lines 817 to 821 in 51d3e3e
| if self.should_terminate or self.should_terminate_single_epoch: | |
| self._fire_event(Events.TERMINATE_SINGLE_EPOCH, iter_counter=iter_counter) | |
| self.should_terminate_single_epoch = False | |
| self.set_data(self.state.dataloader) | |
| break |
IMO, the implementation is fine and only the documentation should be updated.
I think the other option to not fire TERMINATE_SINGLE_EPOCH if enginge.terminate is called would make handling different types of termination more complicated.
Because:
Assuming you have to do some post processing after each epoch and it doesn't matter if the epoch completes with engine.terminate, engine.terminate_epoch or by StopIteration from the data loader.
You would have to attach the same processing function three times, for EPOCH_COMPLETED, TERMINATE_SINGLE_EPOCH and TERMINATE.
At the moment one have to attach post processing function to the two events EPOCH_COMPLETED and TERMINATE_SINGLE_EPOCH to catch termination via command.
I didn't expect that EPOCH_COMPLETED is not fired if I call any termination method. Is this documented somewhere? Haven't found it.
Thanks in advance :)
EDIT: Sorry, I missed that the signature of the function that is called on EPOCH_COMPLETED is different than for TERMINATE_SINGLE_EPOCH.
EDIT2: Fixed event name TERMINATE_SINGLE_EPOCH
EDIT3: I think, now I got it:
- If
engine.terminateis called,TERMINATE_SINGLE_EPOCHandTERMINATEare called but notEPOCH_COMPLETED. - If
engine.terminate_epochis called,TERMINATE_SINGLE_EPOCHandEPOCH_COMPLETEDare called but notTERMINATE. - If epoch completes without termination,
EPOCH_COMPLETEDis called but notTERMINATE_SINGLE_EPOCHandTERMINATE.
There is no common event that is called in all three cases and which could be used if all cases should be treated equally.
Environment
- PyTorch Version (e.g., 1.4): 1.5.1
- Ignite Version (e.g., 0.3.0): 0.4.2
- OS (e.g., Linux): Windows
- How you installed Ignite (
conda,pip, source): pip - Python version: 3.7.7
- Any other relevant information: -