MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PrepareChunkEventProto

Function PrepareChunkEventProto

tensorflow/core/debug/debug_io_utils.cc:63–111  ·  view source on GitHub ↗

Creates an Event proto representing a chunk of a Tensor. This method only populates the field of the Event proto that represent the envelope information (e.g., timestamp, device_name, num_chunks, chunk_index, dtype, shape). It does not set the value.tensor field, which should be set by the caller separately.

Source from the content-addressed store, hash-verified

61// shape). It does not set the value.tensor field, which should be set by the
62// caller separately.
63Event PrepareChunkEventProto(const DebugNodeKey& debug_node_key,
64 const uint64 wall_time_us, const size_t num_chunks,
65 const size_t chunk_index,
66 const DataType& tensor_dtype,
67 const TensorShapeProto& tensor_shape) {
68 Event event;
69 event.set_wall_time(static_cast<double>(wall_time_us));
70 Summary::Value* value = event.mutable_summary()->add_value();
71
72 // Create the debug node_name in the Summary proto.
73 // For example, if tensor_name = "foo/node_a:0", and the debug_op is
74 // "DebugIdentity", the debug node_name in the Summary proto will be
75 // "foo/node_a:0:DebugIdentity".
76 value->set_node_name(debug_node_key.debug_node_name);
77
78 // Tag by the node name. This allows TensorBoard to quickly fetch data
79 // per op.
80 value->set_tag(debug_node_key.node_name);
81
82 // Store data within debugger metadata to be stored for each event.
83 third_party::tensorflow::core::debug::DebuggerEventMetadata metadata;
84 metadata.set_device(debug_node_key.device_name);
85 metadata.set_output_slot(debug_node_key.output_slot);
86 metadata.set_num_chunks(num_chunks);
87 metadata.set_chunk_index(chunk_index);
88
89 // Encode the data in JSON.
90 string json_output;
91 tensorflow::protobuf::util::JsonPrintOptions json_options;
92 json_options.always_print_primitive_fields = true;
93 auto status = tensorflow::protobuf::util::MessageToJsonString(
94 metadata, &json_output, json_options);
95 if (status.ok()) {
96 // Store summary metadata. Set the plugin to use this data as "debugger".
97 SummaryMetadata::PluginData* plugin_data =
98 value->mutable_metadata()->mutable_plugin_data();
99 plugin_data->set_plugin_name(DebugIO::kDebuggerPluginName);
100 plugin_data->set_content(json_output);
101 } else {
102 LOG(WARNING) << "Failed to convert DebuggerEventMetadata proto to JSON. "
103 << "The debug_node_name is " << debug_node_key.debug_node_name
104 << ".";
105 }
106
107 value->mutable_tensor()->set_dtype(tensor_dtype);
108 *value->mutable_tensor()->mutable_tensor_shape() = tensor_shape;
109
110 return event;
111}
112
113// Translates the length of a string to number of bytes when the string is
114// encoded as bytes in protobuf. Note that this makes a conservative estimate

Callers 2

WrapStringTensorAsEventsFunction · 0.85
WrapTensorAsEventsFunction · 0.85

Calls 5

set_tagMethod · 0.80
set_deviceMethod · 0.45
okMethod · 0.45
mutable_metadataMethod · 0.45
set_dtypeMethod · 0.45

Tested by

no test coverage detected