From 49a4233bf337ae354e1402c1e8f8078d9017c2a4 Mon Sep 17 00:00:00 2001 From: Hariharan Seshadri Date: Mon, 23 Sep 2019 17:11:24 -0700 Subject: [PATCH] Account for Constant node being versioned in opset-11 (#1875) * Account for Constant node versioning in opset-11 * Update * PR feedback * Minor nit --- onnxruntime/core/graph/graph.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index da7e21d7fc..88e0cc3d73 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -642,6 +642,8 @@ Graph::Graph(GraphProto* graph_proto, const std::unordered_map ORT_ENFORCE(graph_proto != nullptr, "graph_proto cannot be null"); ArgNameToTypeMap name_to_type_map; + // Process 'Constant' nodes + // Put the 'TensorProto' stored in the 'Constant' nodes attribute into the graphs initializer list for (auto& node : graph_proto_->node()) { if (node.op_type() != kConstant) { continue; @@ -650,7 +652,13 @@ Graph::Graph(GraphProto* graph_proto, const std::unordered_map // Copy constant nodes _value to name_to_initial_tensor_ const gsl::not_null tensor{graph_proto_->add_initializer()}; - *tensor = node.attribute(0).t(); + const AttributeProto& constant_attribute = node.attribute(0); + // TODO: Add support for parsing 'sparse_value' attribute from a 'Constant' node + // Discussion surrounding handling the SparseTensorProto must be had. + // An easy way is to implement a method that converts a SparseTensorproto into a TensorProto + // to use the same downstream flow, but that is going to impact peak memory usage and probably a smarter way is required. + ORT_ENFORCE(constant_attribute.has_t(), "Only 'value' attribute is supported within a 'Constant' node in ORT"); + *tensor = constant_attribute.t(); *(tensor->mutable_name()) = node.output(0); }