Skip to content

Commit 0f0348b

Browse files
PiotrJanderawaelchlimergify[bot]SkafteNicki
authored andcommitted
Ignore step param in Neptune logger's log_metric method (#5510)
* Ignore `step` param in Neptune logger's log_metric method The `step` parameter is ignored because Neptune requires strictly increasing step values, a condition which is sometimes violated in Lighting e.g. when `fit()` and `test()` are called one after another on some models. `step` could be enabled again once Lightning guarantees that step values are always strictly increasing. Also a minor bugfix: the `log_text()` method should use Neptune's `log_text()` method. * Update neptune.py * Update test_neptune.py * Update test_all.py * fix neptune tests * add chlog Co-authored-by: Adrian Wälchli <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Nicki Skafte <[email protected]> (cherry picked from commit 5d76b31)
1 parent 4509129 commit 0f0348b

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
128128
- Increased TPU check timeout from 20s to 100s ([#5598](https://github.com/PyTorchLightning/pytorch-lightning/pull/5598))
129129

130130

131+
- Ignored `step` param in Neptune logger's log_metric method ([#5510](https://github.com/PyTorchLightning/pytorch-lightning/pull/5510))
132+
133+
131134
### Deprecated
132135

133136
- Function `stat_scores_multiple_classes` is deprecated in favor of `stat_scores` ([#4839](https://github.com/PyTorchLightning/pytorch-lightning/pull/4839))

pytorch_lightning/loggers/neptune.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,15 @@ def log_metrics(
251251
252252
Args:
253253
metrics: Dictionary with metric names as keys and measured quantities as values
254-
step: Step number at which the metrics should be recorded, must be strictly increasing
254+
step: Step number at which the metrics should be recorded, currently ignored
255255
"""
256256
assert rank_zero_only.rank == 0, 'experiment tried to log from global_rank != 0'
257257

258258
metrics = self._add_prefix(metrics)
259259
for key, val in metrics.items():
260-
self.log_metric(key, val, step=step)
260+
# `step` is ignored because Neptune expects strictly increasing step values which
261+
# Lighting does not always guarantee.
262+
self.log_metric(key, val)
261263

262264
@rank_zero_only
263265
def finalize(self, status: str) -> None:
@@ -317,7 +319,7 @@ def log_text(self, log_name: str, text: str, step: Optional[int] = None) -> None
317319
text: The value of the log (data-point).
318320
step: Step number at which the metrics should be recorded, must be strictly increasing
319321
"""
320-
self.log_metric(log_name, text, step=step)
322+
self.experiment.log_text(log_name, text, step=step)
321323

322324
@rank_zero_only
323325
def log_image(self,

tests/loggers/test_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_logger_with_prefix_all(tmpdir, monkeypatch):
373373
with mock.patch('pytorch_lightning.loggers.neptune.neptune'):
374374
logger = _instantiate_logger(NeptuneLogger, save_idr=tmpdir, prefix=prefix)
375375
logger.log_metrics({"test": 1.0}, step=0)
376-
logger.experiment.log_metric.assert_called_once_with("tmp-test", x=0, y=1.0)
376+
logger.experiment.log_metric.assert_called_once_with("tmp-test", 1.0)
377377

378378
# TensorBoard
379379
with mock.patch('pytorch_lightning.loggers.tensorboard.SummaryWriter'):

tests/loggers/test_neptune.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def test_neptune_additional_methods(neptune):
7676
created_experiment.log_metric.reset_mock()
7777

7878
logger.log_text('test', 'text')
79-
created_experiment.log_metric.assert_called_once_with('test', 'text')
80-
created_experiment.log_metric.reset_mock()
79+
created_experiment.log_text.assert_called_once_with('test', 'text', step=None)
80+
created_experiment.log_text.reset_mock()
8181

8282
logger.log_image('test', 'image file')
8383
created_experiment.log_image.assert_called_once_with('test', 'image file')

0 commit comments

Comments
 (0)