Skip to content

feat: Default to RichProgressBar and RichModelSummary if rich is avai… #20896

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

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

Conversation

littlebullGit
Copy link
Contributor

@littlebullGit littlebullGit commented Jun 12, 2025

What does this PR do?

This PR implements automatic detection of the optional rich package. If rich is available in the environment, PyTorch Lightning will now default to using RichProgressBar and RichModelSummary for an enhanced visual experience during training and model summarization. If rich is not available, it gracefully falls back to the standard TQDMProgressBar and ModelSummary.

This change aims to improve the out-of-the-box user experience by providing richer feedback mechanisms without requiring manual configuration when rich is installed. The existing behavior of respecting user-provided callbacks or explicit disabling of progress bars/model summaries is maintained.

The rich package is an optional dependency to enable the new default behaviors. If not present, the existing default callbacks are used.

Fixes #9580

No breaking changes are introduced by this PR.

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs) (Yes, issue Enable Rich Progress Bar/Model Summary if Rich is available #9580)
  • Did you read the contributor guideline, Pull Request section? (Assumed)
  • Did you make sure your PR does only one thing, instead of bundling different changes together? (Yes)
  • Did you make sure to update the documentation with your changes? (if necessary) (No explicit documentation changes were made in this PR. The behavior change is user-facing, and a note in relevant documentation sections might be beneficial as a follow-up.)
  • Did you write any new necessary tests? (not for typos and docs) (Yes, comprehensive tests were added in the test file tests/tests_pytorch/trainer/connectors/test_rich_integration.py.)
  • Did you verify new and existing tests pass locally with your changes? (Yes)
  • Did you list all the breaking changes introduced by this pull request? (Yes, none.)
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors) (Yes, this is a feature enhancement and should be added to the changelog.)

Changelog Entry Suggestion (for CHANGELOG.md):

### Added

- Default to RichProgressBar and RichModelSummary if the rich package is available. Fallback to TQDMProgressBar and ModelSummary otherwise. (#9580)

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

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Jun 12, 2025
@littlebullGit littlebullGit force-pushed the feature/9580-rich-defaults branch from f8081b0 to 929c530 Compare June 12, 2025 16:07
littlebullGit and others added 9 commits June 15, 2025 13:16
…lable

Implements automatic detection of the 'rich' package and enables
RichProgressBar and RichModelSummary by default in the Trainer
when the package is present.

This enhances the user experience with improved visual feedback
without requiring manual configuration. Includes comprehensive tests
for various scenarios.

Fixes Lightning-AI#9580
The RichProgressBar was failing in multi-GPU environments because it could not handle tensor metrics from different devices. This commit overrides the get_metrics method to convert all tensor metrics to floats before they are rendered, preventing errors. An accompanying test is added to verify the fix.
The test_progress_bar_max_val_check_interval_ddp test was failing in CI due to an AttributeError. This occurred because _RICH_AVAILABLE was not mocked, leading to RichProgressBar being used incorrectly. This commit adds the necessary @patch decorator to ensure TQDMProgressBar is instantiated as expected.
Addresses a PR comment by bhimrazy regarding inconsistent _RICH_AVAILABLE checks.

This commit:
1. Defines _RICH_MIN_VERSION = "10.2.2" in utilities/imports.py.
2. Updates _RICH_AVAILABLE in utilities/imports.py to use this minimum version.
3. Modifies callbacks/progress/rich_progress.py to import and use the centralized _RICH_AVAILABLE from utilities/imports.py, removing its local definition.

This ensures a single source of truth for rich package availability and version checking.
Fixes import statements in files that were still importing _RICH_AVAILABLE from rich_progress.py instead of the centralized utilities.imports.

Updated files:
- src/lightning/pytorch/callbacks/rich_model_summary.py
- src/lightning/pytorch/loops/evaluation_loop.py
- src/lightning/pytorch/utilities/testing/_runif.py
- tests/tests_pytorch/trainer/logging_/test_eval_loop_logging.py

This completes the centralization of _RICH_AVAILABLE checks.
@littlebullGit littlebullGit force-pushed the feature/9580-rich-defaults branch from 0e502fa to 8f97b42 Compare June 15, 2025 17:17
@Borda
Copy link
Member

Borda commented Jun 16, 2025

Changelog Entry Suggestion (for CHANGELOG.md):

pls add it as part of your PR :)

Added entry to CHANGELOG.md documenting the new feature that defaults to RichProgressBar and RichModelSummary when the rich package is available, with fallback to TQDM variants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pl Generic label for PyTorch Lightning package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable Rich Progress Bar/Model Summary if Rich is available
3 participants