Skip to content

Commit

Permalink
Hparams: Set interval domain fields for float summary hparams. (#6574)
Browse files Browse the repository at this point in the history
Currently TF summary written hparams with `DATA_TYPE_FLOAT64` value type have no domain types.

#hparams
  • Loading branch information
yatbear authored Sep 14, 2023
1 parent c2aa68f commit 1dde0cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tensorboard/plugins/hparams/backend_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,23 @@ def _compute_hparam_info_from_values(self, name, values):
return None

if result.type == api_pb2.DATA_TYPE_STRING:
distinct_values = set(
distinct_string_values = set(
_protobuf_value_to_string(v)
for v in values
if _can_be_converted_to_string(v)
)
result.domain_discrete.extend(distinct_values)
result.domain_discrete.extend(distinct_string_values)

if result.type == api_pb2.DATA_TYPE_BOOL:
result.domain_discrete.extend([True, False])

if result.type == api_pb2.DATA_TYPE_FLOAT64:
# Always uses interval domain type for numeric hparam values.
distinct_float_values = sorted([v.number_value for v in values])
if distinct_float_values:
result.domain_interval.min_value = distinct_float_values[0]
result.domain_interval.max_value = distinct_float_values[-1]

return result

def _experiment_from_data_provider_hparams(
Expand Down
8 changes: 8 additions & 0 deletions tensorboard/plugins/hparams/backend_context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,18 @@ def test_experiment_with_session_tags(self):
hparam_infos: {
name: 'batch_size'
type: DATA_TYPE_FLOAT64
domain_interval {
min_value: 100.0
max_value: 300.0
}
},
hparam_infos: {
name: 'lr'
type: DATA_TYPE_FLOAT64
domain_interval {
min_value: 0.01
max_value: 0.05
}
},
hparam_infos: {
name: 'model_type'
Expand Down

0 comments on commit 1dde0cb

Please sign in to comment.