Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jojje
Copy link

@jojje jojje commented Mar 5, 2024

What does this PR do?

Adds the ability to retain tqdm progress bars from prior training epochs.

Fixes #19322

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs).
    A: No, an issue was was opened but there is no PR yet to discuss (catch 22).
  • [ X ] Did you read the contributor guideline, Pull Request section?
  • [ X ] Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
    A: Yes.
  • Did you write any new necessary tests? (not for typos and docs)
    A: No. The goal was to not break any existing behavior so the existing TQDMProgressBar test suite was used to ensure that objective.
  • [ X ] Did you verify new and existing tests pass locally with your changes?
    A: Partly, I only ran the TQDMProgressBar test suite, since the other's mostly failed on my machine even before the change was made. As such am submitting a draft PR to ensure the entire test suite passes using the project's CI system before it's worth discussing the PR.
  • Did you list all the breaking changes introduced by this pull request?
    A: N/A, No breaking changes intended.
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors):
    A: Yes

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--19578.org.readthedocs.build/en/19578/

@github-actions github-actions bot added docs Documentation related pl Generic label for PyTorch Lightning package labels Mar 5, 2024

"""

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):
Copy link
Member

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!

Comment on lines +267 to +268
if self._leave:
self.train_progress_bar = self.init_train_tqdm()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this, I believe it would be better to pass leave=self.leave to the tqdm bar directly (see init_train_tqdm(), init_validation_tqdm() etc. above.

Copy link
Author

@jojje jojje Mar 8, 2024

Choose a reason for hiding this comment

The 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 init_validation_tqdm, so I don't really see the point of that, unless the intended introduction of init_validation_tqdm had some undocumented purpose that you're planning to start taking advantage of (and perhaps need to change the implementation of the constructor function)

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 init_train_tqdm function is parameterized to take the leave value?

PS. Thanks for the review.

Copy link
Member

@awaelchli awaelchli Mar 8, 2024

Choose a reason for hiding this comment

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

No, I'm proposing to simply pass leave=self.leave in init_train_tqdm() where we hard coded it to True so far. Line 205

@awaelchli awaelchli added this to the 2.3 milestone Mar 8, 2024
@awaelchli awaelchli added the community This PR is from the community label Mar 8, 2024
@awaelchli awaelchli self-assigned this Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community This PR is from the community docs Documentation related has conflicts pl Generic label for PyTorch Lightning package progress bar: tqdm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stats logging in "on_train_epoch_end" ends up on wrong progress bar
2 participants