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

Added support for pathlib paths as a logdir using the recommended os.PathLike class. #5905

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mspils
Copy link

@mspils mspils commented Aug 30, 2022

  • Motivation for features / changes
    Most other Tensorflow functions accept Paths in other form than strings.
    This small change makes the plugin more consistent and users do not need to cast their Path objects to string manually.

  • Technical description of changes

  • Imported os
  • added another elif case for the type of writer:
    elif isinstance(writer, os.PathLike):
    self._writer = tf.compat.v2.summary.create_file_writer(os.fsdecode(writer))
  • Changed the documentation to fit this
  • Detailed steps to verify changes work correctly (as executed by you)
    Barely tested to be honest. Just ran the tutorial code here: https://www.tensorflow.org/tensorboard/hyperparameter_tuning_with_hparams
    with my version

  • Alternate designs / implementations considered
    Once all Tensorflow functions accept pathlikes instead of just strings the distinction between str and PathLike will be unnecessary.

Copy link
Member

@arcra arcra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. I'll check with the team, but I don't think there would be objections to this. Would you mind adding a small test for it? There seems to already be a test for using an explicit writer:
github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/hparams/_keras_test.py#L133

@mspils
Copy link
Author

mspils commented Sep 1, 2022

Sounds very reasonable.
I added a minimal test, that just checks if nothing crashes and that a logfile is created.

tensorboard/plugins/hparams/_keras.py Outdated Show resolved Hide resolved
tensorboard/plugins/hparams/_keras_test.py Outdated Show resolved Hide resolved
Copy link
Member

@arcra arcra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the suggestions Riley left, there's a test failing, because the error message needs to be updated in this test:
github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/hparams/_keras_test.py#L168

mspils and others added 3 commits September 22, 2022 14:34
additional linebreak

Co-authored-by: Riley Jones <78179109+rileyajones@users.noreply.github.com>
removed trailing whitespace

Co-authored-by: Riley Jones <78179109+rileyajones@users.noreply.github.com>
@mspils mspils requested a review from arcra September 22, 2022 12:45
@mspils
Copy link
Author

mspils commented Sep 22, 2022

Thanks for the Change requests.
All those requirements take some time to get used to, but seem very reasonable :)

@@ -62,10 +62,14 @@ def __init__(self, writer, hparams, trial_id=None):
summary_v2.hparams_pb(self._hparams, trial_id=self._trial_id)
if writer is None:
raise TypeError(
"writer must be a `SummaryWriter` or `str`, not None"
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick here but it would be nice to keep the formatting consistent

Suggested change
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None"
"writer must be a `SummaryWriter`, `str`, or `PathLike`, not None"

@@ -165,7 +174,7 @@ def test_reuse_failure(self):
def test_invalid_writer(self):
with self.assertRaisesRegex(
TypeError,
"writer must be a `SummaryWriter` or `str`, not None",
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

Suggested change
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None",
"writer must be a `SummaryWriter`, `str`, or `PathLike`, not None"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants