diff --git a/onnxruntime/core/graph/graph.cc b/onnxruntime/core/graph/graph.cc index de6edf28d2..0593205810 100644 --- a/onnxruntime/core/graph/graph.cc +++ b/onnxruntime/core/graph/graph.cc @@ -71,8 +71,8 @@ static Status MergeShapeInfo(const std::string& output_name, // target.shape() was empty. 'assert' just in case that ever changes. assert(utils::HasShape(source) && utils::HasShape(target)); LOGS(logger, WARNING) << "Error merging shape info for output. '" << output_name - << "' source:" << source.shape() << " target:" << target.shape() - << ". Falling back to lenient merge."; + << "' source:" << source.shape() << " target:" << target.shape() + << ". Falling back to lenient merge."; ONNX_NAMESPACE::UnionShapeInfo(source.shape(), target); } else { @@ -1710,13 +1710,14 @@ common::Status Graph::TypeCheckInputsAndInitializers() { const TensorProto* tensor_proto = initializer_pair.second; TypeProto tensor_type; tensor_type.mutable_tensor_type()->set_elem_type(tensor_proto->data_type()); - auto inferred_type = DataTypeUtils::ToType(tensor_type); - auto existing_type = node_arg->Type(); - if (nullptr == existing_type) - node_arg->SetType(inferred_type); - else if (inferred_type != existing_type) { - return Status(ONNXRUNTIME, FAIL, - "Type Error: Value of initializer " + name + " does not match its type."); + auto initializer_type = DataTypeUtils::ToType(tensor_type); + auto nodearg_type = node_arg->Type(); + if (nullptr == nodearg_type) + node_arg->SetType(initializer_type); + else if (initializer_type != nodearg_type) { + return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, + "Type Error: Data in initializer '", name, "' has element type ", *initializer_type, + " but usage of initializer in graph expects ", *nodearg_type); } // Set shape accordingly. @@ -1811,7 +1812,7 @@ Status Graph::VerifyNodeAndOpMatch() { if (node.op_ && node.op_->HasFunction()) { auto onnx_function_proto = node.op_->GetFunction(); auto func_ptr = onnxruntime::make_unique(*this, node.Index(), *onnx_function_proto, - logger_); + logger_); function_container_.emplace_back(std::move(func_ptr)); node.SetFunctionBody(*function_container_.back()); } @@ -2408,12 +2409,12 @@ void Graph::CleanUnusedInitializers() { // on the first call to Graph::Resolve we are removing unnecessary initializers that should be removed // from the model. // on later calls we are removing initializers that optimizations have made redundant. - if (num_resolves_ == 0) { - LOGS(logger_, WARNING) << "Removing initializer '" - << name << "'. It is not used by any node and should be removed from the model."; - } else { - LOGS(logger_, INFO) << "Removing initializer '" << name << "'. It is no longer used by any node."; - } + if (num_resolves_ == 0) { + LOGS(logger_, WARNING) << "Removing initializer '" + << name << "'. It is not used by any node and should be removed from the model."; + } else { + LOGS(logger_, INFO) << "Removing initializer '" << name << "'. It is no longer used by any node."; + } erase_list.push_back(name); } @@ -2619,7 +2620,7 @@ Status Graph::SetGraphInputsOutputs() { name + " must be either specified in graph inputs or graph initializers."); } } else { - // If arg_input is of an initializer, we remove it from graph_inputs_excluding_initializers_ + // If arg_input is of an initializer, we remove it from graph_inputs_excluding_initializers_ // whose initial content has both initializers and non-initializers. auto input_pos = std::find(graph_inputs_excluding_initializers_.begin(), graph_inputs_excluding_initializers_.end(),