Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds tensorboard hparams logging test #2342

Merged
merged 10 commits into from
Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/loggers/test_tensorboard.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import os
from argparse import Namespace
from packaging import version

import pytest
import torch
import yaml
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator

from pytorch_lightning import Trainer
from pytorch_lightning.loggers import TensorBoardLogger
from tests.base import EvalModelTemplate


@pytest.mark.skipif(version.parse(torch.__version__) < version.parse('1.5.0'),
reason='Minimal PT version is set to 1.5')
def test_tensorboard_hparams_reload(tmpdir):
model = EvalModelTemplate()

trainer = Trainer(max_epochs=1, default_root_dir=tmpdir)
trainer.fit(model)

folder_path = trainer.logger.log_dir

# make sure yaml is there
with open(os.path.join(folder_path, 'hparams.yaml')) as file:
# The FullLoader parameter handles the conversion from YAML
# scalar values to Python the dictionary format
yaml_params = yaml.load(file, Loader=yaml.FullLoader)
assert yaml_params['b1'] == 0.5
assert len(yaml_params.keys()) == 10

# verify artifacts
assert len(os.listdir(os.path.join(folder_path, 'checkpoints'))) == 1

# verify tb logs
event_acc = EventAccumulator(folder_path)
event_acc.Reload()

hparams_data = b'\x12\x84\x01"\x0b\n\tdrop_prob"\x0c\n\nbatch_size"\r\n\x0bin_features"' \
b'\x0f\n\rlearning_rate"\x10\n\x0eoptimizer_name"\x0b\n\tdata_root"\x0e\n' \
b'\x0cout_features"\x0c\n\nhidden_dim"\x04\n\x02b1"\x04\n\x02b2'

assert event_acc.summary_metadata['_hparams_/experiment'].plugin_data.plugin_name == 'hparams'
assert event_acc.summary_metadata['_hparams_/experiment'].plugin_data.content == hparams_data


def test_tensorboard_automatic_versioning(tmpdir):
Expand Down