Skip to content

Commit

Permalink
log hyperparams if there is something to log
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitgr7 committed Dec 16, 2021
1 parent cec2d79 commit 7841f40
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pytorch_lightning/core/mixins/hparams_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HyperparametersMixin:

def __init__(self) -> None:
super().__init__()
self._log_hyperparams = True
self._log_hyperparams = False

def save_hyperparameters(
self,
Expand Down
2 changes: 0 additions & 2 deletions tests/loggers/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ def log_metrics(self, metrics, step):
log_metric_names = [(s, sorted(m.keys())) for s, m in logger.history]
if logger_class == TensorBoardLogger:
expected = [
(0, ["hp_metric"]),
(0, ["epoch", "train_some_val"]),
(0, ["early_stop_on", "epoch", "val_loss"]),
(0, ["hp_metric"]),
(1, ["epoch", "test_loss"]),
]
assert log_metric_names == expected
Expand Down
5 changes: 2 additions & 3 deletions tests/loggers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def training_step(self, batch, batch_idx):
trainer = Trainer(max_steps=2, log_every_n_steps=1, logger=logger, default_root_dir=tmpdir)
trainer.fit(model)
assert trainer.state.finished, f"Training failed with {trainer.state}"
assert logger.hparams_logged == model.hparams
assert logger.metrics_logged != {}
assert logger.after_save_checkpoint_called
assert logger.finalized_status == "success"
Expand All @@ -133,11 +132,11 @@ def training_step(self, batch, batch_idx):
trainer.fit(model)
assert trainer.state.finished, f"Training failed with {trainer.state}"

assert logger1.hparams_logged == model.hparams
assert logger1.hparams_logged is None
assert logger1.metrics_logged != {}
assert logger1.finalized_status == "success"

assert logger2.hparams_logged == model.hparams
assert logger2.hparams_logged is None
assert logger2.metrics_logged != {}
assert logger2.finalized_status == "success"

Expand Down
5 changes: 4 additions & 1 deletion tests/models/test_hparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ def test_adding_datamodule_hparams(tmpdir, model, data):
# Merged hparams were logged
merged_hparams = copy.deepcopy(org_model_hparams)
merged_hparams.update(org_data_hparams)
mock_logger.log_hyperparams.assert_called_with(merged_hparams)
if merged_hparams:
mock_logger.log_hyperparams.assert_called_with(merged_hparams)
else:
mock_logger.log_hyperparams.assert_not_called()


def test_no_datamodule_for_hparams(tmpdir):
Expand Down

0 comments on commit 7841f40

Please sign in to comment.