Skip to content

Commit ad3f183

Browse files
authored
convert warning cache usage to rank_zero_only in WandbLogger (#8764)
1 parent f87b2ef commit ad3f183

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pytorch_lightning/loggers/wandb.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
from pytorch_lightning.utilities import _module_available, rank_zero_only
3030
from pytorch_lightning.utilities.exceptions import MisconfigurationException
3131
from pytorch_lightning.utilities.imports import _compare_version
32-
from pytorch_lightning.utilities.warnings import WarningCache
33-
34-
warning_cache = WarningCache()
32+
from pytorch_lightning.utilities.warnings import rank_zero_deprecation, rank_zero_warn
3533

3634
_WANDB_AVAILABLE = _module_available("wandb")
3735
_WANDB_GREATER_EQUAL_0_10_22 = _compare_version("wandb", operator.ge, "0.10.22")
@@ -129,7 +127,7 @@ def __init__(
129127
)
130128

131129
if log_model and not _WANDB_GREATER_EQUAL_0_10_22:
132-
warning_cache.warn(
130+
rank_zero_warn(
133131
f"Providing log_model={log_model} requires wandb version >= 0.10.22"
134132
" for logging associated model metadata.\n"
135133
"Hint: Upgrade with `pip install --ugrade wandb`."
@@ -186,7 +184,7 @@ def experiment(self) -> Run:
186184
if wandb.run is None:
187185
self._experiment = wandb.init(**self._wandb_init)
188186
else:
189-
warning_cache.warn(
187+
rank_zero_warn(
190188
"There is a wandb run already in progress and newly created instances of `WandbLogger` will reuse"
191189
" this run. If this is not desired, call `wandb.finish()` before instantiating `WandbLogger`."
192190
)

tests/loggers/test_wandb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def test_wandb_logger_init(wandb):
5656
# verify default resume value
5757
assert logger._wandb_init["resume"] == "allow"
5858

59-
_ = logger.experiment
60-
assert any("There is a wandb run already in progress" in w for w in pytorch_lightning.loggers.wandb.warning_cache)
59+
with pytest.warns(UserWarning, match="There is a wandb run already in progress"):
60+
_ = logger.experiment
6161

6262
logger.log_metrics({"acc": 1.0}, step=3)
6363
wandb.init.assert_called_once()

0 commit comments

Comments
 (0)