Skip to content

Commit 37952fe

Browse files
authored
Use step parameter when logging metrics with NeptuneLogger (#19126)
1 parent 11bac94 commit 37952fe

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/lightning/pytorch/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
3535
- The `LightningModule.load_from_checkpoint()` function now calls `.configure_model()` on the model if it is overridden, to ensure all layers can be loaded from the checkpoint ([#19036](https://github.com/Lightning-AI/lightning/pull/19036))
3636

3737

38+
- Restored usage of `step` parameter when logging metrics with `NeptuneLogger` ([#19126](https://github.com/Lightning-AI/pytorch-lightning/pull/19126))
39+
40+
3841
- Changed the `TransformerEnginePrecision(dtype=)` argument to `weights_dtype` and made it required ([#19082](https://github.com/Lightning-AI/lightning/pull/19082))
3942

4043

src/lightning/pytorch/loggers/neptune.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def log_metrics( # type: ignore[override]
447447
448448
Args:
449449
metrics: Dictionary with metric names as keys and measured quantities as values.
450-
step: Step number at which the metrics should be recorded, currently ignored.
450+
step: Step number at which the metrics should be recorded
451451
452452
"""
453453
if rank_zero_only.rank != 0:
@@ -456,9 +456,7 @@ def log_metrics( # type: ignore[override]
456456
metrics = _add_prefix(metrics, self._prefix, self.LOGGER_JOIN_CHAR)
457457

458458
for key, val in metrics.items():
459-
# `step` is ignored because Neptune expects strictly increasing step values which
460-
# Lightning does not always guarantee.
461-
self.run[key].append(val)
459+
self.run[key].append(val, step=step)
462460

463461
@override
464462
@rank_zero_only

tests/tests_pytorch/loggers/test_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def test_logger_with_prefix_all(mlflow_mock, wandb_mock, comet_mock, neptune_moc
307307
logger.log_metrics({"test": 1.0}, step=0)
308308
assert logger.experiment.__getitem__.call_count == 1
309309
logger.experiment.__getitem__.assert_called_with("tmp/test")
310-
logger.experiment.__getitem__().append.assert_called_once_with(1.0)
310+
logger.experiment.__getitem__().append.assert_called_once_with(1.0, step=0)
311311

312312
# TensorBoard
313313
if _TENSORBOARD_AVAILABLE:

tests/tests_pytorch/loggers/test_neptune.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def on_validation_epoch_end(self):
166166
logger, run_instance_mock, _ = _get_logger_with_mocks(api_key="test", project="project")
167167
_fit_and_test(logger=logger, model=LoggingModel(), tmp_path=tmp_path)
168168
run_instance_mock.__getitem__.assert_any_call("training/some/key")
169-
run_instance_mock.__getitem__.return_value.append.assert_has_calls([call(42)])
169+
run_instance_mock.__getitem__.return_value.append.assert_has_calls([call(42, step=2)])
170170

171171

172172
def test_log_hyperparams(neptune_mock):
@@ -204,7 +204,7 @@ def test_log_metrics(neptune_mock):
204204
assert run_instance_mock.__getitem__.call_count == 2
205205
run_instance_mock.__getitem__.assert_any_call(metrics_foo_key)
206206
run_instance_mock.__getitem__.assert_any_call(metrics_bar_key)
207-
run_attr_mock.append.assert_has_calls([call(42), call(555)])
207+
run_attr_mock.append.assert_has_calls([call(42, step=None), call(555, step=None)])
208208

209209

210210
def test_log_model_summary(neptune_mock):

0 commit comments

Comments
 (0)