-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add INTERRUPTED state, improve tests, move state switching from callb…
…ack to a trainer.
- Loading branch information
Showing
4 changed files
with
103 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
from enum import Enum, auto | ||
|
||
from pytorch_lightning import Callback | ||
from enum import Enum | ||
|
||
|
||
class TrainerState(Enum): | ||
""" State which is set to the Trainer to indicate what is being executed. """ | ||
INITIALIZE = auto() | ||
RUNNING = auto() | ||
FINISHED = auto() | ||
|
||
|
||
class _TrainerStateSwitcher(Callback): | ||
""" Special callback used by the Trainer. This callback sets proper | ||
state to the trainer depending on what is being executed. | ||
""" | ||
|
||
def on_init_start(self, trainer): | ||
trainer.state = TrainerState.INITIALIZE | ||
|
||
def on_init_end(self, trainer): | ||
trainer.state = TrainerState.INITIALIZE | ||
|
||
def setup(self, trainer, stage: str): | ||
trainer.state = TrainerState.RUNNING | ||
|
||
def teardown(self, trainer, stage: str): | ||
trainer.state = TrainerState.FINISHED | ||
|
||
def on_keyboard_interrupt(self, trainer, pl_module): | ||
trainer.state = TrainerState.FINISHED | ||
""" State which is set in the Trainer to indicate what is currently or was executed. """ | ||
INITIALIZE = 'INITIALIZE' | ||
RUNNING = 'RUNNING' | ||
FINISHED = 'FINISHED' | ||
INTERRUPTED = 'INTERRUPTED' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters