question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Engine - Continue run throws error because epoch_length is None

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vfdev-5commented, Oct 2, 2020

@fco-dv could you please take a look at this issue and propose a way to fix it along the way with https://github.com/pytorch/ignite/pull/1333 which actually shouldn’t introduce state.restart as it was discussed in the corresponding issue.

1reaction
vfdev-5commented, Sep 28, 2020

@alxlampe thanks for the details !

Yes, that’s true that engine.state.max_epochs = None is to restart the Engine from the begining and not continue. Currently, if we would like to continue, epoch_length is sort of implicitly required. It is a bug as in your case user can stop the execution during the first epoch of a run with epoch_length=None and epoch_length is not set… Let me think what can be done for that. Maybe, a solution is to set unknown epoch_length on engine.terminate_epoch() or engine.terminate()

I was already thinking about creating a new issue to ask if it is possible to separate the event handler mechanics from the engine and build the engine on top it. That would allow to create fully customized engines, e.g. engines that only require an iteration loop but no epoch loop. But I still have to dive deeper into the code to check if this makes any sense and if so, would create an issue with an initial proposal 😃

Yes, this is something to explore

In the optimal case, Engine would provide me some interface to split the run method into subcommands …

A refactor like that may also make sense… Let’s see what is more interesting: this point or above one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make node.js not exit on error - Stack Overflow
Attempting to resume application code without properly recovering from the exception can cause additional unforeseen and unpredictable issues. Exceptions thrown ...
Read more >
Check Engine Light Off But Code Still There
If the check engine light is off, but you see an error code, it may be a pending code stored by the vehicle's...
Read more >
Stop Vehicle Leave Engine Running Error Message - YouTube
Stop vehicle leave engine running message.caused by a weak battery. battery replacement has fixed this issue on this Mercedes Benz C Class ...
Read more >
Rough Running Engine - James on Engines #2
If you find yourself with a rough running engine, you've found the right post. Find out the common causes and how your mechanic...
Read more >
Is Your Engine Misfiring? Here are 6 Possible Causes
A misfire can be caused by a myriad of issues. However continuing to run an engine that is misfiring can cause catastrophic damage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found