Skip to content

Commit 543a6d2

Browse files
authored
hparams: fix type check bug (#6084)
Boolean typed values should be checked before integers. See https://stackoverflow.com/questions/8169001/why-is-bool-a-subclass-of-int for context.
1 parent 270c500 commit 543a6d2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tensorboard/plugins/hparams/summary.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ def session_start_pb(
126126
start_time_secs=start_time_secs,
127127
)
128128
for (hp_name, hp_val) in hparams.items():
129-
if isinstance(hp_val, (float, int)):
129+
# Boolean typed values need to be checked before integers since in Python
130+
# isinstance(True/False, int) returns True.
131+
if isinstance(hp_val, bool):
132+
session_start_info.hparams[hp_name].bool_value = hp_val
133+
elif isinstance(hp_val, (float, int)):
130134
session_start_info.hparams[hp_name].number_value = hp_val
131135
elif isinstance(hp_val, str):
132136
session_start_info.hparams[hp_name].string_value = hp_val
133-
elif isinstance(hp_val, bool):
134-
session_start_info.hparams[hp_name].bool_value = hp_val
135137
elif isinstance(hp_val, (list, tuple)):
136138
session_start_info.hparams[hp_name].string_value = str(hp_val)
137139
else:

0 commit comments

Comments
 (0)