-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
hparams: allow setting trial ID #2442
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
from tensorboard.plugins.hparams import plugin_data_pb2 | ||
|
||
|
||
def hparams(hparams, start_time_secs=None): | ||
def hparams(hparams, trial_id=None, start_time_secs=None): | ||
# NOTE: Keep docs in sync with `hparams_pb` below. | ||
"""Write hyperparameter values for a single trial. | ||
|
||
|
@@ -46,6 +46,8 @@ def hparams(hparams, start_time_secs=None): | |
experiment, or the `HParam` objects themselves. Values should be | ||
Python `bool`, `int`, `float`, or `string` values, depending on | ||
the type of the hyperparameter. | ||
trial_id: An optional `str` ID for the set of hyperparameter values | ||
used in this trial. Defaults to a hash of the hyperparameters. | ||
start_time_secs: The time that this trial started training, as | ||
seconds since epoch. Defaults to the current time. | ||
|
||
|
@@ -55,12 +57,13 @@ def hparams(hparams, start_time_secs=None): | |
""" | ||
pb = hparams_pb( | ||
hparams=hparams, | ||
trial_id=trial_id, | ||
start_time_secs=start_time_secs, | ||
) | ||
return _write_summary("hparams", pb) | ||
|
||
|
||
def hparams_pb(hparams, start_time_secs=None): | ||
def hparams_pb(hparams, trial_id=None, start_time_secs=None): | ||
# NOTE: Keep docs in sync with `hparams` above. | ||
"""Create a summary encoding hyperparameter values for a single trial. | ||
|
||
|
@@ -70,6 +73,8 @@ def hparams_pb(hparams, start_time_secs=None): | |
experiment, or the `HParam` objects themselves. Values should be | ||
Python `bool`, `int`, `float`, or `string` values, depending on | ||
the type of the hyperparameter. | ||
trial_id: An optional `str` ID for the set of hyperparameter values | ||
used in this trial. Defaults to a hash of the hyperparameters. | ||
start_time_secs: The time that this trial started training, as | ||
seconds since epoch. Defaults to the current time. | ||
|
||
|
@@ -79,7 +84,7 @@ def hparams_pb(hparams, start_time_secs=None): | |
if start_time_secs is None: | ||
start_time_secs = time.time() | ||
hparams = _normalize_hparams(hparams) | ||
group_name = _derive_session_group_name(hparams) | ||
group_name = _derive_session_group_name(trial_id, hparams) | ||
|
||
session_start_info = plugin_data_pb2.SessionStartInfo( | ||
group_name=group_name, | ||
|
@@ -199,7 +204,11 @@ def _normalize_hparams(hparams): | |
return result | ||
|
||
|
||
def _derive_session_group_name(hparams): | ||
def _derive_session_group_name(trial_id, hparams): | ||
if trial_id is not None: | ||
if not isinstance(trial_id, str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the prefered way? https://six.readthedocs.io/#six.string_types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes; that’s probably better. Might as well fully support Python 2. |
||
raise TypeError("`trial_id` should be a `str`, but got: %r" % (trial_id,)) | ||
return trial_id | ||
# Use `json.dumps` rather than `str` to ensure invariance under string | ||
# type (incl. across Python versions) and dict iteration order. | ||
jparams = json.dumps(hparams, sort_keys=True, separators=(",", ":")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no action required: if we shipped this API as part of 1.14, and if a user don't use the kwarg, this change will break them, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct; you’re supposed to use use the kwarg.
(But we wouldn’t ship this as part of 1.14 anyway, because it’s a new
feature.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change these to be keyword-only arguments once we drop
Python 2 support, and likewise with
TBContext
and friends.