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

Function AttrValueToJson

tensorflow/core/profiler/nvtx_utils.cc:108–188  ·  view source on GitHub ↗

TODO(benbarsdell): This is a bit crude and hacky (and inefficient).

Source from the content-addressed store, hash-verified

106
107// TODO(benbarsdell): This is a bit crude and hacky (and inefficient).
108string AttrValueToJson(const AttrValue& attr_value) {
109 switch (attr_value.value_case()) {
110 case AttrValue::kS:
111 return SummarizeAttrValue(attr_value);
112 case AttrValue::kI:
113 return strings::StrCat(attr_value.i());
114 case AttrValue::kF:
115 return strings::StrCat(attr_value.f());
116 case AttrValue::kB:
117 return attr_value.b() ? "true" : "false";
118 case AttrValue::kType:
119 return strings::StrCat("\"", DataTypeToNumpyString(attr_value.type()),
120 "\"");
121 case AttrValue::kShape: {
122 if (attr_value.shape().unknown_rank()) return "null";
123 return PartialTensorShape::DebugString(attr_value.shape());
124 }
125 case AttrValue::kTensor: {
126 const TensorProto& tensor_proto = attr_value.tensor();
127 const TensorShapeProto& proto_shape = tensor_proto.tensor_shape();
128 if (!TensorShape::IsValid(proto_shape)) {
129 return strings::StrCat("\"", tensor_proto.ShortDebugString(), "\"");
130 }
131 TensorShape shape(proto_shape);
132 const int64 N = shape.num_elements();
133 if (N > 1024 * 128) {
134 return strings::StrCat("\"", tensor_proto.ShortDebugString(), "\"");
135 }
136 return strings::StrCat("\"", SummarizeAttrValue(attr_value), "\"");
137 }
138 case AttrValue::kList: {
139 std::vector<string> pieces;
140 if (attr_value.list().s_size() > 0) {
141 return SummarizeAttrValue(attr_value);
142 } else if (attr_value.list().i_size() > 0) {
143 for (int i = 0; i < attr_value.list().i_size(); ++i) {
144 pieces.push_back(strings::StrCat(attr_value.list().i(i)));
145 }
146 } else if (attr_value.list().f_size() > 0) {
147 for (int i = 0; i < attr_value.list().f_size(); ++i) {
148 pieces.push_back(strings::StrCat(attr_value.list().f(i)));
149 }
150 } else if (attr_value.list().b_size() > 0) {
151 for (int i = 0; i < attr_value.list().b_size(); ++i) {
152 pieces.push_back(attr_value.list().b(i) ? "true" : "false");
153 }
154 } else if (attr_value.list().type_size() > 0) {
155 for (int i = 0; i < attr_value.list().type_size(); ++i) {
156 pieces.push_back(strings::StrCat(
157 "\"", DataTypeToNumpyString(attr_value.list().type(i)), "\""));
158 }
159 } else if (attr_value.list().shape_size() > 0) {
160 for (int i = 0; i < attr_value.list().shape_size(); ++i) {
161 pieces.push_back(
162 attr_value.list().shape(i).unknown_rank()
163 ? "null"
164 : TensorShape::DebugString(attr_value.list().shape(i)));
165 }

Callers 1

Calls 15

SummarizeAttrValueFunction · 0.85
DataTypeToNumpyStringFunction · 0.85
IsValidFunction · 0.85
unknown_rankMethod · 0.80
listMethod · 0.80
tensor_sizeMethod · 0.80
typeMethod · 0.65
StrCatFunction · 0.50
DebugStringFunction · 0.50
JoinFunction · 0.50
iMethod · 0.45
fMethod · 0.45

Tested by

no test coverage detected