ignite
ignite copied to clipboard
DATALOADER_STOP_ITERATION should not be triggered if `Engine.run(data=None, ...)`
Reported in this issue: https://github.com/pytorch/ignite/issues/3189#issuecomment-1902560344
Repro code:
from ignite.engine import Engine, Events
max_epochs = 4
dataset = range(10)
def training_step(engine, _):
print(f"- {engine.state.epoch} / {engine.state.max_epochs} | {engine.state.iteration}")
print(f"- batch: {next(engine.state.dataiter)}")
print('-'*120)
trainer = Engine(training_step)
trainer.state.dataiter = iter(dataset)
@trainer.on(Events.DATALOADER_STOP_ITERATION)
def init_data_iter():
print('THIS SHOULD NOT BE CALLED')
trainer.state.dataiter = iter(dataset)
trainer.run(max_epochs=max_epochs, epoch_length=4)
gives the output:
- 1 / 4 | 1
- batch: 0
------------------------------------------------------------------------------------------------------------------------
- 1 / 4 | 2
- batch: 1
------------------------------------------------------------------------------------------------------------------------
- 1 / 4 | 3
- batch: 2
------------------------------------------------------------------------------------------------------------------------
- 1 / 4 | 4
- batch: 3
------------------------------------------------------------------------------------------------------------------------
THIS SHOULD NOT BE CALLED
- 2 / 4 | 5
- batch: 0
------------------------------------------------------------------------------------------------------------------------
- 2 / 4 | 6
- batch: 1
------------------------------------------------------------------------------------------------------------------------
- 2 / 4 | 7
- batch: 2
------------------------------------------------------------------------------------------------------------------------
- 2 / 4 | 8
- batch: 3
------------------------------------------------------------------------------------------------------------------------
THIS SHOULD NOT BE CALLED
- 3 / 4 | 9
- batch: 0
------------------------------------------------------------------------------------------------------------------------
- 3 / 4 | 10
- batch: 1
------------------------------------------------------------------------------------------------------------------------
- 3 / 4 | 11
- batch: 2
------------------------------------------------------------------------------------------------------------------------
- 3 / 4 | 12
- batch: 3
------------------------------------------------------------------------------------------------------------------------
THIS SHOULD NOT BE CALLED
- 4 / 4 | 13
- batch: 0
------------------------------------------------------------------------------------------------------------------------
- 4 / 4 | 14
- batch: 1
------------------------------------------------------------------------------------------------------------------------
- 4 / 4 | 15
- batch: 2
------------------------------------------------------------------------------------------------------------------------
- 4 / 4 | 16
- batch: 3
------------------------------------------------------------------------------------------------------------------------