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

Function WrapStringTensorAsEvents

tensorflow/core/debug/debug_io_utils.cc:128–181  ·  view source on GitHub ↗

Breaks a string Tensor (represented as a TensorProto) as a vector of Event protos.

Source from the content-addressed store, hash-verified

126// Breaks a string Tensor (represented as a TensorProto) as a vector of Event
127// protos.
128Status WrapStringTensorAsEvents(const DebugNodeKey& debug_node_key,
129 const uint64 wall_time_us,
130 const size_t chunk_size_limit,
131 TensorProto* tensor_proto,
132 std::vector<Event>* events) {
133 const protobuf::RepeatedPtrField<string>& strs = tensor_proto->string_val();
134 const size_t num_strs = strs.size();
135 const size_t chunk_size_ub = chunk_size_limit > 0
136 ? chunk_size_limit
137 : std::numeric_limits<size_t>::max();
138
139 // E.g., if cutoffs is {j, k, l}, the chunks will have index ranges:
140 // [0:a), [a:b), [c:<end>].
141 std::vector<size_t> cutoffs;
142 size_t chunk_size = 0;
143 for (size_t i = 0; i < num_strs; ++i) {
144 // Take into account the extra bytes in proto buffer.
145 if (StringValMaxBytesInProto(strs[i]) > chunk_size_ub) {
146 return errors::FailedPrecondition(
147 "string value at index ", i, " from debug node ",
148 debug_node_key.debug_node_name,
149 " does not fit gRPC message size limit (", chunk_size_ub, ")");
150 }
151 if (chunk_size + StringValMaxBytesInProto(strs[i]) > chunk_size_ub) {
152 cutoffs.push_back(i);
153 chunk_size = 0;
154 }
155 chunk_size += StringValMaxBytesInProto(strs[i]);
156 }
157 cutoffs.push_back(num_strs);
158 const size_t num_chunks = cutoffs.size();
159
160 for (size_t i = 0; i < num_chunks; ++i) {
161 Event event = PrepareChunkEventProto(debug_node_key, wall_time_us,
162 num_chunks, i, tensor_proto->dtype(),
163 tensor_proto->tensor_shape());
164 Summary::Value* value = event.mutable_summary()->mutable_value(0);
165
166 if (cutoffs.size() == 1) {
167 value->mutable_tensor()->mutable_string_val()->Swap(
168 tensor_proto->mutable_string_val());
169 } else {
170 const size_t begin = (i == 0) ? 0 : cutoffs[i - 1];
171 const size_t end = cutoffs[i];
172 for (size_t j = begin; j < end; ++j) {
173 value->mutable_tensor()->add_string_val(strs[j]);
174 }
175 }
176
177 events->push_back(std::move(event));
178 }
179
180 return Status::OK();
181}
182
183// Encapsulates the tensor value inside a vector of Event protos. Large tensors
184// are broken up to multiple protos to fit the chunk_size_limit. In each Event

Callers 1

WrapTensorAsEventsFunction · 0.85

Calls 8

StringValMaxBytesInProtoFunction · 0.85
FailedPreconditionFunction · 0.85
PrepareChunkEventProtoFunction · 0.85
maxFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45
dtypeMethod · 0.45
SwapMethod · 0.45

Tested by

no test coverage detected