Skip to content

Conversation

@yurekami
Copy link

@yurekami yurekami commented Dec 28, 2025

What does this PR do?

This PR adds a DeviceSummary callback and enable_device_summary Trainer flag to control the device availability printout (GPU, TPU info), addressing issue #13378.

Based on the discussion in #13378, the callback approach was chosen as it:

  1. Keeps consistency with how ModelSummary is handled
  2. Allows fine-grained control over what gets printed
  3. Avoids adding more flags to the Trainer constructor while still providing an easy disable option

Changes

  • Add DeviceSummary callback in callbacks/device_summary.py
  • Add enable_device_summary parameter to Trainer (default True)
  • Remove direct _log_device_info call from Trainer init
  • Device info is now logged via callback at setup stage (only once per Trainer)
  • Add show_warnings parameter to control availability warnings
  • Handle barebones mode (disables device summary)
  • Add comprehensive tests

Usage

# Default - shows device info
trainer = Trainer()

# Disable device summary
trainer = Trainer(enable_device_summary=False)

# Custom callback with warnings disabled
trainer = Trainer(callbacks=[DeviceSummary(show_warnings=False)])

Test plan

  • Unit tests for callback enabling/disabling
  • Test that device info is only logged once
  • Test barebones mode behavior
  • Test custom callback usage

Fixes #13378

🤖 Generated with Claude Code


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

This PR adds a `DeviceSummary` callback and `enable_device_summary` Trainer flag
to control the device availability printout (GPU, TPU info), addressing issue Lightning-AI#13378.

Changes:
- Add `DeviceSummary` callback in `callbacks/device_summary.py`
- Add `enable_device_summary` parameter to Trainer (default True)
- Remove direct `_log_device_info` call from Trainer init
- Device info is now logged via callback at setup stage
- Add `show_warnings` parameter to control availability warnings
- Handle barebones mode (disable device summary)
- Add comprehensive tests

Usage:
```python
# Default - shows device info
trainer = Trainer()

# Disable device summary
trainer = Trainer(enable_device_summary=False)

# Custom callback with warnings disabled
trainer = Trainer(callbacks=[DeviceSummary(show_warnings=False)])
```

Fixes Lightning-AI#13378

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Dec 28, 2025
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.

Add enable_device_summary flag to disable device printout

1 participant