Skip to content

Commit

Permalink
Relax protobuf<5.0.0 restriction
Browse files Browse the repository at this point in the history
Instead of restricting `protobuf<5.0.0` due to the removal to
`including_default_value_fields` kwarg in `json_format.MessageToJson`
(replaced by `always_print_fields_with_nopresence`), we can instead
detect the currently installed protobuf version and use the appropriate
kwarg.

Contributes to #6808 and should resolve #6887.
  • Loading branch information
groszewn committed Aug 7, 2024
1 parent 32e9e95 commit 39460eb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tensorboard/pip_package/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ absl-py >= 0.4
grpcio >= 1.48.2
markdown >= 2.6.8
numpy >= 1.12.0
packaging
# NOTE: this version must be >= the protoc version in our WORKSPACE file.
# At the same time, any constraints we specify here must allow at least some
# version to be installed that is also compatible with TensorFlow's constraints:
# https://github.com/tensorflow/tensorflow/blob/25adc4fccb4b0bb5a933eba1d246380e7b87d7f7/tensorflow/tools/pip_package/setup.py#L101
# 4.24.0 had an issue that broke our tests, so we should avoid that release:
# https://github.com/protocolbuffers/protobuf/issues/13485
# 5.26.0 introduced a breaking change, so we restricted it for now. See issue #6808 for details.
protobuf >= 3.19.6, != 4.24.0, < 5.0.0
protobuf >= 3.19.6, != 4.24.0
setuptools >= 41.0.0 # Note: provides pkg_resources as well as setuptools
# A dependency of our vendored packages. This lower bound has not been correctly
# vetted, but I wanted to be the least restrictive we can, since it's not a new
Expand Down
16 changes: 12 additions & 4 deletions tensorboard/plugins/custom_scalar/custom_scalars_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
this plugin.
"""


from importlib.metadata import version as importlib_version
from packaging import version
import re

from google.protobuf import json_format
Expand Down Expand Up @@ -318,9 +319,16 @@ def layout_impl(self, ctx, experiment):
title_to_category[category.title] = category

if merged_layout:
return json_format.MessageToJson(
merged_layout, including_default_value_fields=True
)
current_protobuf_version = importlib_version("protobuf")
if version.parse(current_protobuf_version) < version.parse("5.0"):
return json_format.MessageToJson(
merged_layout, including_default_value_fields=True
)
else:
return json_format.MessageToJson(
merged_layout,
always_print_fields_with_no_presence=True,
)
else:
# No layout was found.
return {}
47 changes: 34 additions & 13 deletions tensorboard/plugins/hparams/hparams_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
this plugin.
"""


from importlib.metadata import version as importlib_version
from packaging import version
import json


Expand Down Expand Up @@ -116,14 +117,24 @@ def get_experiment_route(self, request):
request_proto = _parse_request_argument(
request, api_pb2.GetExperimentRequest
)
response_proto = get_experiment.Handler(
ctx,
self._context,
experiment_id,
request_proto,
).run()
current_protobuf_version = importlib_version("protobuf")
if version.parse(current_protobuf_version) < version.parse("5.0"):
response = json_format.MessageToJson(
response_proto, including_default_value_fields=True
)
else:
response = json_format.MessageToJson(
response_proto, always_print_fields_with_no_presence=True
)
return http_util.Respond(
request,
json_format.MessageToJson(
get_experiment.Handler(
ctx, self._context, experiment_id, request_proto
).run(),
including_default_value_fields=True,
),
response,
"application/json",
)
except error.HParamsError as e:
Expand All @@ -139,14 +150,24 @@ def list_session_groups_route(self, request):
request_proto = _parse_request_argument(
request, api_pb2.ListSessionGroupsRequest
)
response_proto = list_session_groups.Handler(
ctx,
self._context,
experiment_id,
request_proto,
).run()
current_protobuf_version = importlib_version("protobuf")
if version.parse(current_protobuf_version) < version.parse("5.0"):
response = json_format.MessageToJson(
response_proto, including_default_value_fields=True
)
else:
response = json_format.MessageToJson(
response_proto, always_print_fields_with_no_presence=True
)
return http_util.Respond(
request,
json_format.MessageToJson(
list_session_groups.Handler(
ctx, self._context, experiment_id, request_proto
).run(),
including_default_value_fields=True,
),
response,
"application/json",
)
except error.HParamsError as e:
Expand Down

0 comments on commit 39460eb

Please sign in to comment.