Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed print errors in `ProgressBar` when `trainer.fit` is not called ([#7674](https://github.com/PyTorchLightning/pytorch-lightning/pull/7674))


- Fixed formatting of info message when max training time reached ([#7780](https://github.com/PyTorchLightning/pytorch-lightning/pull/7780))


## [1.3.2] - 2021-05-18

### Changed
Expand Down
3 changes: 2 additions & 1 deletion pytorch_lightning/callbacks/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ def _check_time_remaining(self, trainer: 'pl.Trainer') -> None:
should_stop = trainer.accelerator.broadcast(should_stop)
trainer.should_stop = trainer.should_stop or should_stop
if should_stop and self._verbose:
rank_zero_info(f"Time limit reached. Elapsed time is {self.time_elapsed}. Signaling Trainer to stop.")
elapsed = timedelta(seconds=int(self.time_elapsed(RunningStage.TRAINING)))
rank_zero_info(f"Time limit reached. Elapsed time is {elapsed}. Signaling Trainer to stop.")
7 changes: 5 additions & 2 deletions tests/callbacks/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_timer_time_remaining(time_mock):
assert round(timer.time_elapsed()) == 3


def test_timer_stops_training(tmpdir):
def test_timer_stops_training(tmpdir, caplog):
""" Test that the timer stops training before reaching max_epochs """
model = BoringModel()
duration = timedelta(milliseconds=100)
Expand All @@ -106,9 +106,12 @@ def test_timer_stops_training(tmpdir):
max_epochs=1000,
callbacks=[timer],
)
trainer.fit(model)
with caplog.at_level(logging.INFO):
trainer.fit(model)
assert trainer.global_step > 1
assert trainer.current_epoch < 999
assert "Time limit reached." in caplog.text
assert "Signaling Trainer to stop." in caplog.text
Comment on lines +113 to +114
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert "Time limit reached." in caplog.text
assert "Signaling Trainer to stop." in caplog.text
assert re.match(r"Time limit reached. Elapsed time is .*\. Signaling Trainer to stop.", caplog.text)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@justusschock mind rather use reg expresions?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Borda it wouldn't work.

Not even

assert re.match(r".*Time limit reached.*", caplog.text)

wants to match.

Copy link
Collaborator

Choose a reason for hiding this comment

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

import re
m = "Time limit reached. Elapsed time is any text here I want. Signaling Trainer to stop."
assert re.match(r"Time limit reached. Elapsed time is .*\. Signaling Trainer to stop.", m)

or what is in the caplog.text?



@pytest.mark.parametrize("interval", ["step", "epoch"])
Expand Down