Skip to content
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

Uploader: Add test for completely empty GraphDef blob. #3509

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
30 changes: 30 additions & 0 deletions tensorboard/dataclass_compat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,36 @@ def test_graph_def_experimental_filter_graph_RuntimeWarning(self):
self.assertLen(new_events, 1)
self.assertProtoEquals(new_events[0], old_event)

def test_graph_def_experimental_filter_graph_empty(self):
# Simulate legacy graph event with an empty graph
old_event = event_pb2.Event()
old_event.step = 0
old_event.wall_time = 456.75
old_event.graph_def = b""

new_events = self._migrate_event(
old_event, experimental_filter_graph=True
)
# _migrate_event emits both the original event and the migrated event.
# The migrated event contains a default empty GraphDef.
self.assertLen(new_events, 2)
self.assertProtoEquals(new_events[0], old_event)

# We expect that parsing `b""` as a `GraphDef` produces the default
# 'empty' proto, just like `graph_pb2.GraphDef()`. Furthermore, we
# expect serializing that to produce `b""` again (as opposed to some
# other representation of the default proto, e.g. one in which default
# values are materialized).
# Here we extract the serialized graph_def from the migrated event,
# which is the result of such a deserialize/serialize cycle, to validate
# these expectations.
# This also demonstrates that empty `GraphDefs` are not rejected or
# ignored.
new_event = new_events[1]
tensor = tensor_util.make_ndarray(new_event.summary.value[0].tensor)
new_graph_def_bytes = tensor[0]
self.assertEqual(new_graph_def_bytes, b"")


if __name__ == "__main__":
tf.test.main()