-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
base: master
Are you sure you want to change the base?
feat: Default to RichProgressBar and RichModelSummary if rich is avai… #20896
Conversation
tests/tests_pytorch/callbacks/progress/test_tqdm_progress_bar.py
Outdated
Show resolved
Hide resolved
tests/tests_pytorch/callbacks/progress/test_tqdm_progress_bar.py
Outdated
Show resolved
Hide resolved
f8081b0
to
929c530
Compare
…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
…and rich progress bars
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.
Co-authored-by: Bhimraj Yadav <bhimrajyadav977@gmail.com>
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.
0e502fa
to
8f97b42
Compare
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.
) | ||
assert user_progress_bar in trainer.callbacks | ||
assert sum(isinstance(cb, ProgressBar) for cb in trainer.callbacks) == 1 | ||
assert isinstance(trainer.progress_bar_callback, RichProgressBar) |
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.
why the pbar is RichProgressBar
if _RICH_AVAILABLE=False
?
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.
I understand that the RichProgressBar class checks for _RICH_AVAILABLE in the init method; however, I believe this test is still needed just in case a user explicitly provides a RichProgressBar instance, even when Rich is not available in this environment. This could happen if:
- The user has Rich installed in their development environment
- Their code directly uses RichProgressBar
- Then they run it in an environment without Rich
The test is verifying that the system respects the user's explicit choice to use RichProgressBar, regardless of the _RICH_AVAILABLE flag.
I have these in the comments:
# If user explicitly provides RichProgressBar, it should be used,
# even if _RICH_AVAILABLE is False (simulating our connector logic).
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.
well but how you can have RichProgressBar
if the rich package is not installed?
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.
ok, I can remove this test. Anything else I need to change before I commit?
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.
just removed the test. build successful
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.
I am not complaining about the test, the test just documents the implemented behaviors so removing the test does not change anything on my concerns, rather oposit we would have untested behaviour
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.
Let me clarify. The test test_no_rich_respects_user_provided_rich_progress_bar
was removed because it tested an impossible scenario. Here's why:
-
Import Behavior:
- The Rich imports are checked when the module loads
- If Rich isn't installed, Python raises an
ImportError
immediately when the module is imported with code reference RichProgressBar - The user can't even reach the point of initializing [RichProgressBar] if Rich isn't installed
-
Impossible Scenario:
- The test tried to create a situation where [RichProgressBar] was used with
_RICH_AVAILABLE=False
- In reality, if Rich isn't available:
- The import would fail at module load time with
ImportError
- The code would never reach the point of instantiating [RichProgressBar]
- The import would fail at module load time with
- So, this Mock scenario is invalid
- The test tried to create a situation where [RichProgressBar] was used with
-
Safety:
- Python's import system ensures that if Rich isn't installed, any attempt to use [RichProgressBar] fails immediately with an
ImportError
- This is the correct and expected behavior - users must have Rich installed to use RichProgressBar
- Python's import system ensures that if Rich isn't installed, any attempt to use [RichProgressBar] fails immediately with an
The removal makes the test suite more accurate by only testing possible scenarios.
Let me know if this addresses your concerns.
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
Changelog Entry Suggestion (for CHANGELOG.md):
📚 Documentation preview 📚: https://pytorch-lightning--20896.org.readthedocs.build/en/20896/