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.

Avoid running `on_training_end` after Keyboard Interrupt

See original GitHub issue

🚀 Feature

Right now, due to #795 , on_training_end runs after a KeyboardInterrupt. This ends up running code that’s meant to be run only after successful training completion. This feature should either be reverted, or an alternative should be provided, so as to run some code only after successful training.

Motivation

I am training a model on Sagemaker and have added a notebook shutdown code within the on_training_end method. There were times where I had to manually cancel my model training because some parameters were incorrect. However, If I do that, the notebook shuts down immediately. This is because the on_training_end method runs even after a KeyboardInterrupt. I don’t want my notebook shutting down after a keyboard interrupt, only after successful training completion.

Pitch

Maybe add an on_training_completed method for code that’s meant to be run after successful training.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:20 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostcommented, Mar 22, 2020

@jeremyjordan sounds like a good idea! also I was thinking that since we have TrainerStatus, can it be the main class while TrainerMode servers as a nested enum instead of putting them all under a single enum? something like:

class TrainerMode(enum.Enum):
    TRAINING = enum.auto()
    VALIDATING = enum.auto()
    TESTING = enum.auto()

class TrainerStatus(enum.Enum):
    PENDING = enum.auto()
    FAILED = enum.auto()
    INTERRUPTED = enum.auto()
    ...
    MODE = TrainerMode

then user can access the current status and mode through:

# Interrupted when validation is running
if ... is TrainerStatus.INTERRUPTED and ... is TrainerStatus.MODE.VALIDATING:
1reaction
ghostcommented, Mar 23, 2020

not too sure about that, but probably the order matters too when new status or mode is added. so I guess we should use exact numbers like you suggested in case any import or export is involved! 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid running on_training_end after Keyboard Interrupt #1099
I am training a model on Sagemaker and have added a notebook shutdown code within the on_training_end method. There were times where I...
Read more >
What's the correct way to clean up after an interrupted event ...
Once we catch KeyboardInterrupt , we call tasks.cancel() and then ... t: loop.stop()) tasks.cancel() # Keep the event loop running until it ...
Read more >
Complete Guide to Python KeyboardInterrupt - eduCBA
Guide to Python KeyboardInterrupt. Here we discuss how KeyboardInterrupt exception work, how to avoid KeyboardInterrupt exceptions in Python.
Read more >
Example of KeyboardInterrupt exception - Lesson 131
Example of KeyboardInterrupt exception - Lesson 131 - Learn Python programming, and make your career in machine learning, data science, ...
Read more >
Stop kills the Python interpreter under Windows instead of ...
Process finished with exit code -1. C detected. This unfortunately only effects Windows. Under Linux, the expected KeyboardInterrupt is thrown.
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