Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pytorch_lightning/trainer/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,9 @@ def train(self):
# stop training
stop = should_stop and met_min_epochs
if stop:
self.main_progress_bar.close()
model.on_train_end()
return
break

self.main_progress_bar.close()

model.on_train_end()

if self.logger is not None:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cpu_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_early_stopping_cpu_model(tmpdir):
stopping = EarlyStopping(monitor='val_loss', min_delta=0.1)
trainer_options = dict(
default_save_path=tmpdir,
min_epochs=2,
early_stop_callback=stopping,
gradient_clip_val=1.0,
overfit_pct=0.20,
Expand All @@ -33,7 +34,7 @@ def test_early_stopping_cpu_model(tmpdir):
)

model, hparams = tutils.get_model()
tutils.run_model_test(trainer_options, model, on_gpu=False)
tutils.run_model_test(trainer_options, model, on_gpu=False, early_stop=True)

# test freeze on cpu
model.freeze()
Expand Down
6 changes: 5 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run_model_test_no_loggers(trainer_options, model, min_acc=0.50):
trainer.optimizers, trainer.lr_schedulers = pretrained_model.configure_optimizers()


def run_model_test(trainer_options, model, on_gpu=True):
def run_model_test(trainer_options, model, on_gpu=True, early_stop=False):
save_dir = trainer_options['default_save_path']

# logger file to get meta
Expand All @@ -65,6 +65,10 @@ def run_model_test(trainer_options, model, on_gpu=True):
# correct result and ok accuracy
assert result == 1, 'amp + ddp model failed to complete'

if early_stop:
assert trainer.current_epoch >= trainer.min_epochs, 'amp + ddp model failed to complete'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather make is raise an error

assert trainer.current_epoch < trainer.max_epochs-1, 'amp + ddp model failed to stop early'

# test model loading
pretrained_model = load_model(logger, trainer.checkpoint_callback.filepath)

Expand Down