Skip to content

Engine - Continue run throws error because epoch_length is None #1331

@alxlampe

Description

@alxlampe

🐛 Bug description

I am using an engine such that it runs a previously undefined number of iterations with an infinite iterator. Epoch will be terminated in the process function with engine.terminate().

I am always running the engine for only one epoch, because I need to do some calculations outside the engines framework and then continue the engine to run one further epoch with engine.run(itertools.counter(start=0), max_epochs=engine.state.epoch + 1).

I get an error in engine._is_done because engine.state.epoch_length is None. Is this the intended behavior? Do I have to set epoch_length explicitly?

Here is a minimum example to reproduce the error:

import itertools

from ignite.engine import Engine


def _run_iteration(engine, counter):
    if counter > 2:
        # same behavior observed for engine.terminate_epoch()
        engine.terminate()


if __name__ == '__main__':
    engine = Engine(_run_iteration)
    # run one epoch
    engine.run(itertools.count(start=0), max_epochs=engine.state.epoch + 1)
    # epoch length is None after run:
    print(engine.state.epoch_length)
    # running another epoch throws the error:
    engine.run(itertools.count(start=0), max_epochs=engine.state.epoch + 1)

Thanks in advance!

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: -

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions