Skip to content

DOC: Clarify DeviceStatsMonitor logged metrics #20895

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 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/lightning/pytorch/callbacks/device_stats_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ class DeviceStatsMonitor(Callback):
r"""Automatically monitors and logs device stats during training, validation and testing stage.
``DeviceStatsMonitor`` is a special callback as it requires a ``logger`` to passed as argument to the ``Trainer``.

Device statistics are logged with keys prefixed as ``DeviceStatsMonitor.{hook_name}/{base_metric_name}`` (e.g.,
``DeviceStatsMonitor.on_train_batch_start/cpu_percent``).
The source of these metrics depends on the ``cpu_stats`` flag and the active accelerator.

CPU (via ``psutil``): Logs ``cpu_percent``, ``cpu_vm_percent``, ``cpu_swap_percent``.
All are percentages (%).
CUDA GPU (via :func:`torch.cuda.memory_stats`): Logs detailed memory statistics from
PyTorch's allocator (e.g., ``allocated_bytes.all.current``, ``num_ooms``; all in Bytes).
GPU compute utilization is not logged by default.
Other Accelerators (e.g., TPU, MPS): Logs device-specific stats:

- TPU example: ``avg. free memory (MB)``.
- MPS example: ``mps.current_allocated_bytes``.

Observe logs or check accelerator documentation for details.
Comment on lines +41 to +51
Copy link
Member

Choose a reason for hiding this comment

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

'Let''s make this a complete list and you can validate the compiled docs in readthedocs link 📚: pytorch-lightning--20895.org.readthedocs.build/en/20895


Args:
cpu_stats: if ``None``, it will log CPU stats only if the accelerator is CPU.
If ``True``, it will log CPU stats regardless of the accelerator.
Expand All @@ -45,6 +61,7 @@ class DeviceStatsMonitor(Callback):
ModuleNotFoundError:
If ``psutil`` is not installed and CPU stats are monitored.


Example::

from lightning import Trainer
Expand Down