Skip to content

Commit

Permalink
set boolean hparam domains to be [True, False] and improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
yatbear committed Sep 15, 2023
1 parent e04d117 commit 8809428
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tensorboard/plugins/hparams/backend_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ def _compute_hparam_info_from_values(self, name, values):
result.differs = len(distinct_string_values) > 1

if result.type == api_pb2.DATA_TYPE_BOOL:
result.domain_discrete.extend([True, False])
distinct_bool_values = set(v.bool_value for v in values)
result.domain_discrete.extend(distinct_bool_values)
result.differs = len(distinct_bool_values) > 1

if result.type == api_pb2.DATA_TYPE_FLOAT64:
Expand Down
49 changes: 35 additions & 14 deletions tensorboard/plugins/hparams/backend_context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,43 +224,48 @@ def test_experiment_with_experiment_tag_include_metrics(self):
def test_experiment_with_session_tags(self):
self.session_1_start_info_ = """
hparams: [
{key: 'batch_size' value: {number_value: 100}},
{key: 'batch_size' value: {number_value: 1024}},
{key: 'eval.timeout' value: {bool_value: false}},
{key: 'lr' value: {number_value: 0.01}},
{key: 'model_type' value: {string_value: 'CNN'}}
{key: 'model_type' value: {string_value: 'CNN'}},
{key: 'optimizer_type' value: {string_value: 'momentum'}},
{key: 'use_batch_norm' value: {bool_value: true}}
]
"""
self.session_2_start_info_ = """
hparams:[
{key: 'batch_size' value: {number_value: 200}},
{key: 'batch_size' value: {number_value: 1024}},
{key: 'eval.timeout' value: {bool_value: false}},
{key: 'lr' value: {number_value: 0.02}},
{key: 'model_type' value: {string_value: 'LATTICE'}}
{key: 'model_type' value: {string_value: 'LATTICE'}},
{key: 'optimizer_type' value: {string_value: 'momentum'}}
]
"""
self.session_3_start_info_ = """
hparams:[
{key: 'batch_size' value: {number_value: 300}},
{key: 'batch_size' value: {number_value: 1024}},
{key: 'eval.timeout' value: {bool_value: false}},
{key: 'lr' value: {number_value: 0.05}},
{key: 'model_type' value: {string_value: 'CNN'}}
{key: 'model_type' value: {string_value: 'CNN'}},
{key: 'optimizer_type' value: {string_value: 'momentum'}},
{key: 'use_batch_norm' value: {bool_value: false}}
]
"""
expected_exp = """
hparam_infos: {
name: 'batch_size'
type: DATA_TYPE_FLOAT64
domain_interval {
min_value: 100.0
max_value: 300.0
min_value: 1024
max_value: 1024
}
differs: true
differs: false
}
hparam_infos: {
name: 'eval.timeout'
type: DATA_TYPE_BOOL
domain_discrete: {
values: [{bool_value: false}]
values: [{bool_value: true}, {bool_value: false}]
}
differs: false
}
Expand All @@ -282,6 +287,22 @@ def test_experiment_with_session_tags(self):
}
differs: true
}
hparam_infos: {
name: 'optimizer_type'
type: DATA_TYPE_STRING
domain_discrete: {
values: [{string_value: 'momentum'}]
}
differs: false
}
hparam_infos: {
name: 'use_batch_norm'
type: DATA_TYPE_BOOL
domain_discrete: {
values: [{bool_value: true}, {bool_value: false}]
}
differs: true
}
metric_infos: {
name: {group: '', tag: 'accuracy'}
}
Expand Down Expand Up @@ -366,12 +387,12 @@ def test_experiment_with_session_tags_different_hparam_types(self):
def test_experiment_with_session_tags_bool_types(self):
self.session_1_start_info_ = """
hparams:[
{key: 'batch_size' value: {bool_value: true}}
{key: 'use_batch_norm' value: {bool_value: true}}
]
"""
self.session_2_start_info_ = """
hparams:[
{key: 'batch_size' value: {bool_value: true}}
{key: 'use_batch_norm' value: {bool_value: true}}
]
"""
self.session_3_start_info_ = """
Expand All @@ -380,10 +401,10 @@ def test_experiment_with_session_tags_bool_types(self):
"""
expected_exp = """
hparam_infos: {
name: 'batch_size'
name: 'use_batch_norm'
type: DATA_TYPE_BOOL
domain_discrete: {
values: [{bool_value: true}]
values: [{bool_value: true}, {bool_value: false}]
}
differs: false
}
Expand Down

0 comments on commit 8809428

Please sign in to comment.