Skip to content

Commit 152a2eb

Browse files
Oliver NeumannawaelchliBorda
authored
wandb logger 'global_step' affects other logger (Lightning-AI#1492)
* Removed unnecessary 'global_step' from wandb logger. * Fixed wrong step implementation in wandb and missing metric skipping in logger base. * simplified metric check in base logger * Added Fix Description in CHANGELOG.md * Updated wandb logger tests. * udpate test, step=3 * Moved Fix Description in CHANGELOG.md to unreleased. * Update CHANGELOG.md Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
1 parent 4dc77b5 commit 152a2eb

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2424

2525
- Fixed Horovod distributed backend to set the `root_gpu` property ([#1669](https://github.com/PyTorchLightning/pytorch-lightning/pull/1669))
2626

27+
- Fixed wandb logger `global_step` affects other loggers ([#1492](https://github.com/PyTorchLightning/pytorch-lightning/issues/1485))
2728

2829
## [0.7.5] - 2020-04-27
2930

pytorch_lightning/loggers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def agg_and_log_metrics(self, metrics: Dict[str, float], step: Optional[int] = N
125125
"""
126126
agg_step, metrics_to_log = self._aggregate_metrics(metrics=metrics, step=step)
127127

128-
if metrics_to_log is not None:
128+
if metrics_to_log:
129129
self.log_metrics(metrics=metrics_to_log, step=agg_step)
130130

131131
@abstractmethod

pytorch_lightning/loggers/wandb.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def log_hyperparams(self, params: Union[Dict[str, Any], Namespace]) -> None:
119119

120120
@rank_zero_only
121121
def log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None) -> None:
122-
if step is not None:
123-
metrics['global_step'] = step
124-
self.experiment.log(metrics)
122+
self.experiment.log(metrics, step=step)
125123

126124
@property
127125
def name(self) -> str:

tests/loggers/test_wandb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def test_wandb_logger(wandb):
1414
logger = WandbLogger(anonymous=True, offline=True)
1515

1616
logger.log_metrics({'acc': 1.0})
17-
wandb.init().log.assert_called_once_with({'acc': 1.0})
17+
wandb.init().log.assert_called_once_with({'acc': 1.0}, step=None)
1818

1919
wandb.init().log.reset_mock()
2020
logger.log_metrics({'acc': 1.0}, step=3)
21-
wandb.init().log.assert_called_once_with({'global_step': 3, 'acc': 1.0})
21+
wandb.init().log.assert_called_once_with({'acc': 1.0}, step=3)
2222

2323
logger.log_hyperparams({'test': None})
2424
wandb.init().config.update.assert_called_once_with({'test': None}, allow_val_change=True)

0 commit comments

Comments
 (0)