Repository: pytorch/ignite

Issue:
NeptuneSaver saves more checkpoints than specified by the n_saved parameter
## 🐛 Bug description

The recent change to Checkpointing in PR #937 seemed to have affected the NeptuneSaver in that it saves more than the specified `n_saved` checkpoints.  It is probably because it doesn't have the the `BaseSaveHandler` interface. Maybe because of this change [checkpoint.py]( https://github.com/vfdev-5/ignite/blob/f5d00c9887888fa31059ca4cc7a5e744889ce49f/ignite/handlers/checkpoint.py#L249)

## Environment

 - PyTorch Version (e.g., 1.4): 1.4
 - Ignite Version (e.g., 0.3.0): nightly
 - OS (e.g., Linux): Linux
 - How you installed Ignite (`conda`, `pip`, source): pip
 - Python version: 3.7



Discussion:

Patch:
diff --git a/ignite/contrib/handlers/neptune_logger.py b/ignite/contrib/handlers/neptune_logger.py
index abcda692..8ed8974b 100644
--- a/ignite/contrib/handlers/neptune_logger.py
+++ b/ignite/contrib/handlers/neptune_logger.py
@@ -6,6 +6,7 @@ import warnings
 import torch
 
 import ignite
+from ignite.handlers.checkpoint import BaseSaveHandler
 from ignite.contrib.handlers.base_logger import (
     BaseLogger,
     BaseOptimizerParamsHandler,
@@ -466,7 +467,7 @@ class NeptuneLogger(BaseLogger):
         self.stop()
 
 
-class NeptuneSaver:
+class NeptuneSaver(BaseSaveHandler):
     """Handler that saves input checkpoint to the Neptune server.
 
     Args:


Test patch:
diff --git a/tests/ignite/contrib/handlers/test_neptune_logger.py b/tests/ignite/contrib/handlers/test_neptune_logger.py
index 46f42ffd..5b1ba12c 100644
--- a/tests/ignite/contrib/handlers/test_neptune_logger.py
+++ b/tests/ignite/contrib/handlers/test_neptune_logger.py
@@ -6,6 +6,7 @@ import pytest
 import torch
 
 from ignite.engine import Engine, Events, State
+from ignite.handlers.checkpoint import Checkpoint
 from ignite.contrib.handlers.neptune_logger import *
 
 
@@ -414,7 +415,7 @@ def test_integration_as_context_manager():
         trainer.run(data, max_epochs=n_epochs)
 
 
-def test_neptune_saver_serializable(dummy_model_factory, dirname):
+def test_neptune_saver_serializable():
 
     mock_logger = MagicMock(spec=NeptuneLogger)
     mock_logger.log_artifact = MagicMock()
@@ -428,7 +429,28 @@ def test_neptune_saver_serializable(dummy_model_factory, dirname):
     assert mock_logger.log_artifact.call_count == 1
 
 
-def test_neptune_saver_non_serializable(dirname):
+def test_neptune_saver_integration():
+
+    model = torch.nn.Module()
+    to_save_serializable = {"model": model}
+
+    mock_logger = MagicMock(spec=NeptuneLogger)
+    mock_logger.log_artifact = MagicMock()
+    mock_logger.delete_artifacts = MagicMock()
+    saver = NeptuneSaver(mock_logger)
+
+    checkpoint = Checkpoint(to_save=to_save_serializable, save_handler=saver, n_saved=1)
+
+    trainer = Engine(lambda e, b: None)
+    trainer.state = State(epoch=0, iteration=0)
+    checkpoint(trainer)
+    trainer.state.iteration = 1
+    checkpoint(trainer)
+    assert mock_logger.log_artifact.call_count == 2
+    assert mock_logger.delete_artifacts.call_count == 1
+
+
+def test_neptune_saver_non_serializable():
 
     mock_logger = MagicMock(spec=NeptuneLogger)
     mock_logger.log_artifact = MagicMock()