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

Configurable metric formatting for RichProgressBar #18373

Merged
merged 15 commits into from
Aug 29, 2023
Merged

Configurable metric formatting for RichProgressBar #18373

merged 15 commits into from
Aug 29, 2023

Conversation

quintenroets
Copy link
Contributor

@quintenroets quintenroets commented Aug 23, 2023

What does this PR do?

Fixes #18367

This PR makes the string formatting of metric values configurable.
This allows for tracking losses in non-standard scenarios (e.g losses in the range 1e-7).

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • 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)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

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

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Aug 23, 2023
@mergify mergify bot removed the has conflicts label Aug 24, 2023
@awaelchli awaelchli added feature Is an improvement or enhancement progress bar: rich community This PR is from the community labels Aug 28, 2023
@awaelchli awaelchli changed the title Feature 18367 configurable metric formatting Configurable metric formatting for RichProgressBar Aug 28, 2023
Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution 🚀

Would it be possible to provide a test as well?

@Borda Borda merged commit d5440a0 into Lightning-AI:master Aug 29, 2023
@Borda Borda added this to the 2.1 milestone Aug 29, 2023
@mergify mergify bot added the ready PRs ready to be merged label Aug 29, 2023
yield f"{k}: {round(v, 3) if isinstance(v, float) else v}"
for name, value in self._metrics.items():
if not isinstance(value, str):
value = round(value, 3) if self._metrics_format is None else f"{value:{self._metrics_format}}"
Copy link
Contributor

Choose a reason for hiding this comment

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

metrics_format could have .3f as default which should be equivalent to round(, 3):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely agree. It would not entirely be backward compatible for metrics with lower precision. That's why I didn't propose it originally.

e.g.
100.1 becomes

  • round(, 3) => 100.1
  • .3f => 100.100

In my opinion, the .3f option is actually better than the current behavior because it results in consistent metrics lengths, making the progress bar values jump around less, and making the metrics more readable. (For example, if 10.111 changes to 10.1, this introduces a shift in all other metric values)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. I don't think we need to be this strict about backward compatibility in terms of how the data is presented on the progress bar. Especially if the change is it's for a better UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I agree. I created a PR for this at #18483

@quintenroets
Copy link
Contributor Author

quintenroets commented Sep 5, 2023

Thanks for the contribution 🚀

Would it be possible to provide a test as well?

Sure, I added two tests at #18483

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 feature Is an improvement or enhancement pl Generic label for PyTorch Lightning package progress bar: rich ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customizable Metric Formatting for Rich Progress Bar
4 participants