Skip to content

Commit

Permalink
Set warnings : Unify epoch numbers to be zero-based : #675 (#786)
Browse files Browse the repository at this point in the history
* [update] : #675 : set warnings

* [fix] : #675 : remove white space
  • Loading branch information
onkyo14taro authored Feb 5, 2020
1 parent 4cbcb78 commit 734b28e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pytorch_lightning/callbacks/pt_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def on_epoch_end(self, epoch, logs=None):

def on_train_end(self, logs=None):
if self.stopped_epoch > 0 and self.verbose > 0:
warnings.warn('Displayed epoch numbers by `EarlyStopping` start from "1" until v0.6.x,'
' but will start from "0" in v0.8.0.', DeprecationWarning)
log.info(f'Epoch {self.stopped_epoch + 1:05d}: early stopping')


Expand Down Expand Up @@ -374,6 +376,7 @@ class GradientAccumulationScheduler(Callback):
Args:
scheduling (dict): scheduling in format {epoch: accumulation_factor}
warning:: Epochs indexing starts from "1" until v0.6.x, but will start from "0" in v0.8.0.
Example::
Expand All @@ -394,6 +397,8 @@ def __init__(self, scheduling: dict):
raise TypeError("All epoches and accumulation factor must be integers")

minimal_epoch = min(scheduling.keys())
warnings.warn('Epochs indexing of `scheduling` starts from "1" until v0.6.x,'
' but will start from "0" in v0.8.0.', DeprecationWarning)
if minimal_epoch < 1:
msg = f"Epochs indexing from 1, epoch {minimal_epoch} cannot be interpreted correct"
raise IndexError(msg)
Expand All @@ -404,7 +409,9 @@ def __init__(self, scheduling: dict):
self.epochs = sorted(scheduling.keys())

def on_epoch_begin(self, epoch, trainer):
epoch += 1 # indexing epochs from 1
# indexing epochs from 1 (until v0.6.x)
# In v0.8.0, `epoch += 1` should be removed.
epoch += 1
for i in reversed(range(len(self.epochs))):
if epoch >= self.epochs[i]:
trainer.accumulate_grad_batches = self.scheduling.get(self.epochs[i])
Expand Down
2 changes: 2 additions & 0 deletions pytorch_lightning/trainer/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def process_output(self, output, train):
pass

def train(self):
warnings.warn('Displayed epoch numbers in the progress bar start from "1" until v0.6.x,'
' but will start from "0" in v0.8.0.', DeprecationWarning)
model = self.get_model()
# run all epochs
for epoch in range(self.current_epoch, self.max_epochs):
Expand Down

0 comments on commit 734b28e

Please sign in to comment.