Added test case for existing experiment.
This commit is contained in:
parent
9b7b1d5e26
commit
9f3ba2e37b
|
@ -7,9 +7,9 @@ from pytorch_lightning.loggers import NeptuneLogger
|
|||
from tests.base import EvalModelTemplate
|
||||
|
||||
|
||||
@patch('pytorch_lightning.loggers.neptune.neptune')
|
||||
@patch("pytorch_lightning.loggers.neptune.neptune")
|
||||
def test_neptune_online(neptune):
|
||||
logger = NeptuneLogger(api_key='test', project_name='project')
|
||||
logger = NeptuneLogger(api_key="test", project_name="project")
|
||||
|
||||
created_experiment = neptune.Session.with_default_backend().get_project().create_experiment()
|
||||
|
||||
|
@ -21,7 +21,20 @@ def test_neptune_online(neptune):
|
|||
assert logger.version == created_experiment.id
|
||||
|
||||
|
||||
@patch('pytorch_lightning.loggers.neptune.neptune')
|
||||
@patch("pytorch_lightning.loggers.neptune.neptune")
|
||||
def test_neptune_existing_experiment(neptune):
|
||||
logger = NeptuneLogger(experiment_id="TEST-123")
|
||||
|
||||
neptune.Session.with_default_backend().get_project().get_experiments.assert_called_once_with(id="TEST-123")
|
||||
|
||||
experiment = logger.experiment
|
||||
assert logger.experiment_name == experiment.get_system_properties()["name"]
|
||||
assert logger.params == experiment.get_parameters()
|
||||
assert logger.properties == experiment.get_properties()
|
||||
assert logger.tags == experiment.get_tags()
|
||||
|
||||
|
||||
@patch("pytorch_lightning.loggers.neptune.neptune")
|
||||
def test_neptune_offline(neptune):
|
||||
logger = NeptuneLogger(offline_mode=True)
|
||||
|
||||
|
@ -29,48 +42,48 @@ def test_neptune_offline(neptune):
|
|||
assert logger.experiment == neptune.Session().get_project().create_experiment()
|
||||
|
||||
|
||||
@patch('pytorch_lightning.loggers.neptune.neptune')
|
||||
@patch("pytorch_lightning.loggers.neptune.neptune")
|
||||
def test_neptune_additional_methods(neptune):
|
||||
logger = NeptuneLogger(api_key='test', project_name='project')
|
||||
logger = NeptuneLogger(api_key="test", project_name="project")
|
||||
|
||||
created_experiment = neptune.Session.with_default_backend().get_project().create_experiment()
|
||||
|
||||
logger.log_metric('test', torch.ones(1))
|
||||
created_experiment.log_metric.assert_called_once_with('test', torch.ones(1))
|
||||
logger.log_metric("test", torch.ones(1))
|
||||
created_experiment.log_metric.assert_called_once_with("test", torch.ones(1))
|
||||
created_experiment.log_metric.reset_mock()
|
||||
|
||||
logger.log_metric('test', 1.0)
|
||||
created_experiment.log_metric.assert_called_once_with('test', 1.0)
|
||||
logger.log_metric("test", 1.0)
|
||||
created_experiment.log_metric.assert_called_once_with("test", 1.0)
|
||||
created_experiment.log_metric.reset_mock()
|
||||
|
||||
logger.log_metric('test', 1.0, step=2)
|
||||
created_experiment.log_metric.assert_called_once_with('test', x=2, y=1.0)
|
||||
logger.log_metric("test", 1.0, step=2)
|
||||
created_experiment.log_metric.assert_called_once_with("test", x=2, y=1.0)
|
||||
created_experiment.log_metric.reset_mock()
|
||||
|
||||
logger.log_text('test', 'text')
|
||||
created_experiment.log_metric.assert_called_once_with('test', 'text')
|
||||
logger.log_text("test", "text")
|
||||
created_experiment.log_metric.assert_called_once_with("test", "text")
|
||||
created_experiment.log_metric.reset_mock()
|
||||
|
||||
logger.log_image('test', 'image file')
|
||||
created_experiment.log_image.assert_called_once_with('test', 'image file')
|
||||
logger.log_image("test", "image file")
|
||||
created_experiment.log_image.assert_called_once_with("test", "image file")
|
||||
created_experiment.log_image.reset_mock()
|
||||
|
||||
logger.log_image('test', 'image file', step=2)
|
||||
created_experiment.log_image.assert_called_once_with('test', x=2, y='image file')
|
||||
logger.log_image("test", "image file", step=2)
|
||||
created_experiment.log_image.assert_called_once_with("test", x=2, y="image file")
|
||||
created_experiment.log_image.reset_mock()
|
||||
|
||||
logger.log_artifact('file')
|
||||
created_experiment.log_artifact.assert_called_once_with('file', None)
|
||||
logger.log_artifact("file")
|
||||
created_experiment.log_artifact.assert_called_once_with("file", None)
|
||||
|
||||
logger.set_property('property', 10)
|
||||
created_experiment.set_property.assert_called_once_with('property', 10)
|
||||
logger.set_property("property", 10)
|
||||
created_experiment.set_property.assert_called_once_with("property", 10)
|
||||
|
||||
logger.append_tags('one tag')
|
||||
created_experiment.append_tags.assert_called_once_with('one tag')
|
||||
logger.append_tags("one tag")
|
||||
created_experiment.append_tags.assert_called_once_with("one tag")
|
||||
created_experiment.append_tags.reset_mock()
|
||||
|
||||
logger.append_tags(['two', 'tags'])
|
||||
created_experiment.append_tags.assert_called_once_with('two', 'tags')
|
||||
logger.append_tags(["two", "tags"])
|
||||
created_experiment.append_tags.assert_called_once_with("two", "tags")
|
||||
|
||||
|
||||
def test_neptune_leave_open_experiment_after_fit(tmpdir):
|
||||
|
@ -79,12 +92,7 @@ def test_neptune_leave_open_experiment_after_fit(tmpdir):
|
|||
|
||||
def _run_training(logger):
|
||||
logger._experiment = MagicMock()
|
||||
trainer = Trainer(
|
||||
default_root_dir=tmpdir,
|
||||
max_epochs=1,
|
||||
limit_train_batches=0.05,
|
||||
logger=logger,
|
||||
)
|
||||
trainer = Trainer(default_root_dir=tmpdir, max_epochs=1, limit_train_batches=0.05, logger=logger,)
|
||||
trainer.fit(model)
|
||||
return logger
|
||||
|
||||
|
|
Loading…
Reference in New Issue