Skip to content

feat: add verbose flag to DeviceStatsMonitor for non-expert mode#21706

Open
deependujha wants to merge 2 commits intoLightning-AI:masterfrom
deependujha:feat/device-stats-monitor-non-expert-mode
Open

feat: add verbose flag to DeviceStatsMonitor for non-expert mode#21706
deependujha wants to merge 2 commits intoLightning-AI:masterfrom
deependujha:feat/device-stats-monitor-non-expert-mode

Conversation

@deependujha
Copy link
Copy Markdown
Collaborator

@deependujha deependujha commented May 8, 2026

What does this PR do?

Fixes #18652

DeviceStatsMonitor previously dumped all device stats unconditionally, overwhelming beginner users unfamiliar with PyTorch allocator internals.

Added a verbose flag (default True to preserve existing behavior).
When verbose=False, only core metrics are logged: memory usage and CPU utilization for CUDA/CPU, and HBM memory metrics for TPU.

Changes:

  • Added _CORE_DEVICE_STATS_KEYS and _CORE_TPU_STATS_PREFIXES module-level constants
  • Added _filter_core_device_stats static method to DeviceStatsMonitor
  • Added verbose parameter to __init__ with updated docstring
  • Added parametrized tests for both CPU and GPU
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

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

@github-actions github-actions Bot added the pl Generic label for PyTorch Lightning package label May 8, 2026
@deependujha deependujha force-pushed the feat/device-stats-monitor-non-expert-mode branch from b589eb9 to ea6eb4d Compare May 8, 2026 16:32
@deependujha deependujha requested a review from Copilot May 8, 2026 16:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a verbose flag to DeviceStatsMonitor to support a “non-expert” logging mode that reduces the amount of device statistics emitted to loggers, addressing issue #18652.

Changes:

  • Added a verbose parameter to DeviceStatsMonitor (default True) and core-metric filtering logic for verbose=False.
  • Introduced module-level constants defining the “core” metrics and a helper to filter stats dictionaries.
  • Added parameterized tests covering verbose=True/False behavior for CPU and CUDA.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/lightning/pytorch/callbacks/device_stats_monitor.py Adds verbose flag and core-metric filtering for device stats logging.
tests/tests_pytorch/callbacks/test_device_stats_monitor.py Adds new parameterized tests validating verbose vs non-verbose logging on CPU and CUDA.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lightning/pytorch/callbacks/device_stats_monitor.py
Comment thread tests/tests_pytorch/callbacks/test_device_stats_monitor.py
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 8, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79%. Comparing base (78bf021) to head (ea6eb4d).
✅ All tests successful. No failed tests found.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

❗ There is a different number of reports uploaded between BASE (78bf021) and HEAD (ea6eb4d). Click for more details.

HEAD has 1297 uploads less than BASE
Flag BASE (78bf021) HEAD (ea6eb4d)
cpu 335 42
python 23 3
lightning_fabric 108 0
pytest 168 0
python3.12 96 12
python3.10 24 3
lightning 120 15
python3.13 72 9
python3.11 48 6
python3.12.7 72 9
pytorch2.4.1 12 3
pytest-full 167 42
pytorch2.8 24 6
pytorch_lightning 107 27
pytorch2.6 12 3
pytorch2.5.1 12 3
pytorch2.1 23 6
pytorch2.3 12 3
pytorch2.2.2 12 3
pytorch2.9 24 6
pytorch2.10 24 6
pytorch2.7 12 3
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #21706     +/-   ##
=========================================
- Coverage      87%      79%     -8%     
=========================================
  Files         270      267      -3     
  Lines       23973    23922     -51     
=========================================
- Hits        20748    18809   -1939     
- Misses       3225     5113   +1888     

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.

Provide a non-expert mode for the DeviceStatsMonitor

3 participants