2020-08-20 02:03:22 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2021-01-12 13:56:07 +00:00
|
|
|
from pytorch_lightning.utilities import LightningEnum
|
2020-08-09 10:24:09 +00:00
|
|
|
|
|
|
|
|
2021-01-12 13:56:07 +00:00
|
|
|
class TrainerState(LightningEnum):
|
2021-03-06 12:40:19 +00:00
|
|
|
""" State for the :class:`~pytorch_lightning.trainer.trainer.Trainer`
|
|
|
|
to indicate what is currently or was executed. It follows the user-called
|
|
|
|
functions such as `trainer.fit()` and `trainer.test().
|
2020-12-09 19:13:57 +00:00
|
|
|
|
2021-01-13 01:33:39 +00:00
|
|
|
>>> # you can compare the type with a string
|
2021-03-08 14:27:07 +00:00
|
|
|
>>> TrainerState.FITTING == 'fit'
|
2020-12-09 19:13:57 +00:00
|
|
|
True
|
2021-01-13 01:33:39 +00:00
|
|
|
>>> # which is case insensitive
|
2021-03-08 14:27:07 +00:00
|
|
|
>>> TrainerState.FINISHED == 'FINISHED'
|
2021-01-12 13:56:07 +00:00
|
|
|
True
|
2020-12-09 19:13:57 +00:00
|
|
|
"""
|
2021-03-08 14:27:07 +00:00
|
|
|
INITIALIZING = 'initializing' # trainer creation
|
|
|
|
FITTING = 'fit' # trainer.fit()
|
|
|
|
VALIDATING = 'validate' # trainer.validate()
|
|
|
|
TESTING = 'test' # trainer.test()
|
|
|
|
PREDICTING = 'predict' # trainer.predict()
|
|
|
|
TUNING = 'tune' # trainer.tune()
|
|
|
|
FINISHED = 'finished'
|
|
|
|
INTERRUPTED = 'interrupted'
|
2020-08-09 10:24:09 +00:00
|
|
|
|
2021-03-06 12:40:19 +00:00
|
|
|
@property
|
|
|
|
def stopped(self) -> bool:
|
|
|
|
return self in (self.FINISHED, self.INTERRUPTED)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def running(self) -> bool:
|
|
|
|
return self in (self.FITTING, self.VALIDATING, self.TESTING, self.PREDICTING, self.TUNING)
|
|
|
|
|
2020-08-09 10:24:09 +00:00
|
|
|
|
2021-01-13 01:33:39 +00:00
|
|
|
class RunningStage(LightningEnum):
|
2021-03-06 12:40:19 +00:00
|
|
|
"""Current running stage.
|
|
|
|
|
|
|
|
This stage complements :class:`TrainerState` for example to indicate that
|
|
|
|
`RunningStage.VALIDATING` will be set both during `TrainerState.FITTING`
|
|
|
|
and `TrainerState.VALIDATING`. It follows the internal code logic.
|
2021-01-13 01:33:39 +00:00
|
|
|
|
|
|
|
>>> # you can match the Enum with string
|
|
|
|
>>> RunningStage.TRAINING == 'train'
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
TRAINING = 'train'
|
2021-03-06 12:40:19 +00:00
|
|
|
SANITY_CHECKING = 'sanity_check'
|
2021-03-11 02:46:37 +00:00
|
|
|
VALIDATING = 'validate'
|
2021-01-13 01:33:39 +00:00
|
|
|
TESTING = 'test'
|
2021-01-27 16:38:14 +00:00
|
|
|
PREDICTING = 'predict'
|
2021-01-13 01:33:39 +00:00
|
|
|
TUNING = 'tune'
|
|
|
|
|
2021-03-06 12:40:19 +00:00
|
|
|
@property
|
|
|
|
def evaluating(self) -> bool:
|
|
|
|
return self in (self.VALIDATING, self.TESTING)
|