[tfdbg2] Implement the to_json() methods of two data classes
- DebuggedDevice - DebuggedGraph These will be used by UIs like the existing to_json() methods such as ExecutionDigest.to_json() and GraphOpCreation.to_json(). PiperOrigin-RevId: 310159269 Change-Id: I4220ec66cd9b2375c844a02c19ad17f862e969f0
This commit is contained in:
parent
6b809d9f44
commit
c9aeeea2a8
@ -491,7 +491,13 @@ class DebuggedGraph(object):
|
|||||||
"""
|
"""
|
||||||
return self._op_consumers[src_op_name]
|
return self._op_consumers[src_op_name]
|
||||||
|
|
||||||
# TODO(cais): Implement to_json().
|
def to_json(self):
|
||||||
|
return {
|
||||||
|
"name": self.name,
|
||||||
|
"graph_id": self.graph_id,
|
||||||
|
"outer_graph_id": self._outer_graph_id,
|
||||||
|
"inner_graph_ids": self._inner_graph_ids,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DebuggedDevice(object):
|
class DebuggedDevice(object):
|
||||||
@ -517,7 +523,11 @@ class DebuggedDevice(object):
|
|||||||
def device_id(self):
|
def device_id(self):
|
||||||
return self._device_id
|
return self._device_id
|
||||||
|
|
||||||
# TODO(cais): Implement to_json().
|
def to_json(self):
|
||||||
|
return {
|
||||||
|
"device_name": self._device_name,
|
||||||
|
"device_id": self._device_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class GraphOpCreationDigest(BaseDigest):
|
class GraphOpCreationDigest(BaseDigest):
|
||||||
|
@ -660,6 +660,43 @@ class DataObjectsTest(test_util.TensorFlowTestCase):
|
|||||||
self.assertIsNone(json["output_tensor_ids"])
|
self.assertIsNone(json["output_tensor_ids"])
|
||||||
self.assertIsNone(json["debug_tensor_values"])
|
self.assertIsNone(json["debug_tensor_values"])
|
||||||
|
|
||||||
|
def testDebuggedDeviceToJons(self):
|
||||||
|
debugged_device = debug_events_reader.DebuggedDevice("/TPU:3", 4)
|
||||||
|
self.assertEqual(debugged_device.to_json(), {
|
||||||
|
"device_name": "/TPU:3",
|
||||||
|
"device_id": 4,
|
||||||
|
})
|
||||||
|
|
||||||
|
def testDebuggedGraphToJonsWitouthNameInnerOuterGraphIds(self):
|
||||||
|
debugged_graph = debug_events_reader.DebuggedGraph(
|
||||||
|
None,
|
||||||
|
"b1c2",
|
||||||
|
outer_graph_id=None,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
debugged_graph.to_json(), {
|
||||||
|
"name": None,
|
||||||
|
"graph_id": "b1c2",
|
||||||
|
"outer_graph_id": None,
|
||||||
|
"inner_graph_ids": [],
|
||||||
|
})
|
||||||
|
|
||||||
|
def testDebuggedGraphToJonsWithNameAndInnerOuterGraphIds(self):
|
||||||
|
debugged_graph = debug_events_reader.DebuggedGraph(
|
||||||
|
"loss_function",
|
||||||
|
"b1c2",
|
||||||
|
outer_graph_id="a0b1",
|
||||||
|
)
|
||||||
|
debugged_graph.add_inner_graph_id("c2d3")
|
||||||
|
debugged_graph.add_inner_graph_id("c2d3e4")
|
||||||
|
self.assertEqual(
|
||||||
|
debugged_graph.to_json(), {
|
||||||
|
"name": "loss_function",
|
||||||
|
"graph_id": "b1c2",
|
||||||
|
"outer_graph_id": "a0b1",
|
||||||
|
"inner_graph_ids": ["c2d3", "c2d3e4"],
|
||||||
|
})
|
||||||
|
|
||||||
def testGraphOpCreationDigestNoInputNoDeviceNameToJson(self):
|
def testGraphOpCreationDigestNoInputNoDeviceNameToJson(self):
|
||||||
op_creation_digest = debug_events_reader.GraphOpCreationDigest(
|
op_creation_digest = debug_events_reader.GraphOpCreationDigest(
|
||||||
1234,
|
1234,
|
||||||
|
Loading…
Reference in New Issue
Block a user