-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Treat Nan/Infinity numeric hparam values as unset values. #6496
Conversation
@@ -304,6 +300,11 @@ def _compute_hparam_info_from_values(self, name, values): | |||
return None | |||
|
|||
if result.type == api_pb2.DATA_TYPE_STRING: | |||
distinct_values = set() | |||
for value in values: | |||
if _protobuf_value_type(value): |
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.
nit: Consider extracting into a separate named function, where you can use early returns, to reduce nesting, and so you can use a set comprehension here, like it was before.
Optional. This is fine too.
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.
Done.
False, otherwise. | ||
""" | ||
return not value.HasField("number_value") or ( | ||
not math.isnan(value.number_value) |
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.
nit: Consider using early returns, so the "short circuit" evaluation is more evident:
if not value.HasField("..."):
return True
val = value.number_value
return not math.isnan(val) and not math.isinf(val)
Again, optional.
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.
Done.
request = """ | ||
start_index: 0 | ||
slice_size: 10 | ||
allowed_statuses: [STATUS_UNKNOWN] |
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.
Is this just an arbitrary value that is irrelevant for the test? Can it be omitted, or is it a required field?
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.
Ya unfortunately it is necessary for the query to work. (allowed_status: [] will return no results).
#6496 broke the internal import due to missing BUILD dependency for json_format_compat_test.py.
…ensorflow#6496) ## Motivation for features / changes There are cases where users might log hparam numeric values that are NaN or Infinity. Recall, we use proto's Value message for logging and storing hparam values. While processing these values in the python layer of the Hparams plugin, we may run these Value message through json_format.MessageToJson, at which point the json_format library raises an error. The limitation is documented at https://protobuf.dev/reference/protobuf/google.protobuf/#value. "[A]ttempting to serialize NaN or Infinity results in error." ## Technical description of changes We now will try to avoid calling MessageToJson on these problematic hparam values. We instead chose to treat these as "unset" values -- equivalent to having not set an hparam value at all. It will mean the values will not contribute to the calculation of discrete domains. And it means that the values will appear blank in the hparams UI rather than appearing as "NaN". ## Alternate designs / implementations considered (or N/A) Given infinite amount of time: * Fix json_format to handle NaN and Infinity :O. * Change the hparams api.proto to use something other than proto's Value for representing hparam values. Other reasonable options: * Change the NaN numeric value to "NaN" string. This was my first choice but it unfortunately leads to other complications - for instance the plugin will raise errors when it encounters a "NaN" string for an hparam that is supposed to have a numeric value.
tensorflow#6496 broke the internal import due to missing BUILD dependency for json_format_compat_test.py.
Motivation for features / changes
There are cases where users might log hparam numeric values that are NaN or Infinity. Recall, we use proto's Value message for logging and storing hparam values. While processing these values in the python layer of the Hparams plugin, we may run these Value message through json_format.MessageToJson, at which point the json_format library raises an error.
The limitation is documented at https://protobuf.dev/reference/protobuf/google.protobuf/#value. "[A]ttempting to serialize NaN or Infinity results in error."
Technical description of changes
We now will try to avoid calling MessageToJson on these problematic hparam values. We instead chose to treat these as "unset" values -- equivalent to having not set an hparam value at all. It will mean the values will not contribute to the calculation of discrete domains. And it means that the values will appear blank in the hparams UI rather than appearing as "NaN".
Alternate designs / implementations considered (or N/A)
Given infinite amount of time:
Other reasonable options: