Account for Constant node being versioned in opset-11 (#1875)

* Account for Constant node versioning in opset-11

* Update

* PR feedback

* Minor nit
This commit is contained in:
Hariharan Seshadri 2019-09-23 17:11:24 -07:00 committed by GitHub
parent ca89387817
commit 49a4233bf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -642,6 +642,8 @@ Graph::Graph(GraphProto* graph_proto, const std::unordered_map<std::string, int>
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<std::string, int>
// Copy constant nodes _value to name_to_initial_tensor_
const gsl::not_null<TensorProto*>
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);
}