-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability for TQDMProgressBar to retain prior epoch training bars (… #19578
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,12 +99,13 @@ class TQDMProgressBar(ProgressBar): | |
together. This corresponds to | ||
:paramref:`~lightning.pytorch.trainer.trainer.Trainer.process_position` in the | ||
:class:`~lightning.pytorch.trainer.trainer.Trainer`. | ||
leave: Leaves the finished progress bar in the terminal at the end of the epoch. Default: False | ||
|
||
""" | ||
|
||
BAR_FORMAT = "{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_noinv_fmt}{postfix}]" | ||
|
||
def __init__(self, refresh_rate: int = 1, process_position: int = 0): | ||
def __init__(self, refresh_rate: int = 1, process_position: int = 0, leave: bool = False): | ||
super().__init__() | ||
self._refresh_rate = self._resolve_refresh_rate(refresh_rate) | ||
self._process_position = process_position | ||
|
@@ -113,6 +114,7 @@ def __init__(self, refresh_rate: int = 1, process_position: int = 0): | |
self._val_progress_bar: Optional[_tqdm] = None | ||
self._test_progress_bar: Optional[_tqdm] = None | ||
self._predict_progress_bar: Optional[_tqdm] = None | ||
self._leave = leave | ||
|
||
def __getstate__(self) -> Dict: | ||
# can't pickle the tqdm objects | ||
|
@@ -262,6 +264,8 @@ def on_train_start(self, *_: Any) -> None: | |
|
||
@override | ||
def on_train_epoch_start(self, trainer: "pl.Trainer", *_: Any) -> None: | ||
if self._leave: | ||
self.train_progress_bar = self.init_train_tqdm() | ||
Comment on lines
+267
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this, I believe it would be better to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean creating yet another constructor wrapper, like in the rich progress bar, and what is already present in this file? E.g. def reinit_train_tqdm(self) -> Tqdm:
"""Override this to customize the tqdm bar for training."""
return Tqdm(
desc=self.train_description,
position=(2 * self.process_position),
disable=self.is_disabled,
leave=self._leave,
dynamic_ncols=True,
file=sys.stdout,
smoothing=0,
bar_format=self.BAR_FORMAT,
) It'd be identical to Or did you perhaps mean changing the hard coded "leave=True" to "leave=self._leave" in the existing "init_train_tqdm" function. Or perhaps a third variant, where the PS. Thanks for the review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'm proposing to simply pass |
||
self.train_progress_bar.reset(convert_inf(self.total_train_batches)) | ||
self.train_progress_bar.initial = 0 | ||
self.train_progress_bar.set_description(f"Epoch {trainer.current_epoch}") | ||
|
@@ -279,6 +283,8 @@ def on_train_batch_end( | |
def on_train_epoch_end(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None: | ||
if not self.train_progress_bar.disable: | ||
self.train_progress_bar.set_postfix(self.get_metrics(trainer, pl_module)) | ||
if self._leave: | ||
self.train_progress_bar.close() | ||
|
||
@override | ||
def on_train_end(self, *_: Any) -> None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea!