Skip to content

feat: add enable_device_summary flag to Trainer#21637

Closed
crawfordxx wants to merge 2 commits into
Lightning-AI:masterfrom
crawfordxx:feat-enable-device-summary-flag
Closed

feat: add enable_device_summary flag to Trainer#21637
crawfordxx wants to merge 2 commits into
Lightning-AI:masterfrom
crawfordxx:feat-enable-device-summary-flag

Conversation

@crawfordxx
Copy link
Copy Markdown

@crawfordxx crawfordxx commented Apr 1, 2026

What does this PR do?

Fixes #13378

Adds a new enable_device_summary boolean parameter to the Trainer that controls whether device information (GPU/TPU availability and usage) is logged during initialization. Defaults to True for backward compatibility.

Setting enable_device_summary=False suppresses the device info output, which is useful when calling Trainer.predict() in a loop where the repeated device summaries clutter the output:

GPU available: False, used: False
TPU available: False, using: 0 TPU cores
=======================================================
n_gen |  n_eval |  n_nds  |     eps      |  indicator  
=======================================================
    1 |     322 |       3 |            - |            -
GPU available: False, used: False
TPU available: False, using: 0 TPU cores
    2 |    1322 |       4 |  0.625000000 |        ideal

Usage

# Suppress device info when using predict in a loop
trainer = Trainer(enable_device_summary=False)
for batch in surrogate_loop:
    trainer.predict(model, dataloaders=batch_loader)

Changes

  • Added enable_device_summary: bool = True parameter to Trainer.__init__
  • Gated the _log_device_info() call with the new flag
  • Updated CHANGELOG and documentation
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--21637.org.readthedocs.build/en/21637/

Add a new `enable_device_summary` boolean parameter to the Trainer that
controls whether device information (GPU/TPU availability and usage) is
logged during initialization. Defaults to True for backward compatibility.

Setting `enable_device_summary=False` suppresses the device info output,
which is useful when calling `Trainer.predict()` in a loop where repeated
device summaries clutter the output.

Fixes #13378
@github-actions github-actions Bot added docs Documentation related pl Generic label for PyTorch Lightning package labels Apr 1, 2026
Comment thread src/lightning/pytorch/CHANGELOG.md Outdated
@deependujha
Copy link
Copy Markdown
Collaborator

Hi @crawfordxx, based on the discussion of the issue, a callback is expected. Please update your PR accordingly.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79%. Comparing base (0a60211) to head (c0287ab).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

❗ There is a different number of reports uploaded between BASE (0a60211) and HEAD (c0287ab). Click for more details.

HEAD has 168 uploads less than BASE
Flag BASE (0a60211) HEAD (c0287ab)
cpu 84 42
python 6 3
lightning_fabric 27 0
pytest 42 0
python3.10 6 3
lightning 30 15
python3.12 24 12
python3.12.7 18 9
python3.11 12 6
python3.13 18 9
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #21637     +/-   ##
=========================================
- Coverage      87%      79%     -8%     
=========================================
  Files         270      267      -3     
  Lines       23930    23876     -54     
=========================================
- Hits        20709    18799   -1910     
- Misses       3221     5077   +1856     

@crawfordxx crawfordxx closed this by deleting the head repository May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation related pl Generic label for PyTorch Lightning package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add enable_device_summary flag to disable device printout

2 participants