21
21
from typing import Any , Dict , Optional
22
22
23
23
import pytorch_lightning as pl
24
+ from pytorch_lightning .accelerators .cpu import _PSUTIL_AVAILABLE
24
25
from pytorch_lightning .callbacks .callback import Callback
25
26
from pytorch_lightning .utilities .exceptions import MisconfigurationException
26
- from pytorch_lightning .utilities .imports import _PSUTIL_AVAILABLE
27
- from pytorch_lightning .utilities .rank_zero import rank_zero_warn
28
27
from pytorch_lightning .utilities .types import STEP_OUTPUT
29
28
30
29
@@ -36,14 +35,14 @@ class DeviceStatsMonitor(Callback):
36
35
37
36
Args:
38
37
cpu_stats: if ``None``, it will log CPU stats only if the accelerator is CPU.
39
- It will raise a warning if ``psutil`` is not installed till v1.9.0.
40
- If ``True``, it will log CPU stats regardless of the accelerator, and it will
41
- raise an exception if ``psutil`` is not installed.
38
+ If ``True``, it will log CPU stats regardless of the accelerator.
42
39
If ``False``, it will not log CPU stats regardless of the accelerator.
43
40
44
41
Raises:
45
42
MisconfigurationException:
46
43
If ``Trainer`` has no logger.
44
+ ModuleNotFoundError:
45
+ If ``psutil`` is not installed and CPU stats are monitored.
47
46
48
47
Example:
49
48
>>> from pytorch_lightning import Trainer
@@ -70,13 +69,9 @@ def setup(
70
69
# warn in setup to warn once
71
70
device = trainer .strategy .root_device
72
71
if self ._cpu_stats is None and device .type == "cpu" and not _PSUTIL_AVAILABLE :
73
- # TODO: raise an exception from v1.9
74
- rank_zero_warn (
75
- "`DeviceStatsMonitor` will not log CPU stats as `psutil` is not installed."
76
- " To install `psutil`, run `pip install psutil`."
77
- " It will raise an exception if `psutil` is not installed post v1.9.0."
72
+ raise ModuleNotFoundError (
73
+ f"`DeviceStatsMonitor` cannot log CPU stats as `psutil` is not installed. { str (_PSUTIL_AVAILABLE )} "
78
74
)
79
- self ._cpu_stats = False
80
75
81
76
def _get_and_log_device_stats (self , trainer : "pl.Trainer" , key : str ) -> None :
82
77
if not trainer ._logger_connector .should_update_logs :
0 commit comments