From a506911208e1b9e5da23de1f432b45acccc8c46d Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Mon, 24 Feb 2020 15:14:29 -0800 Subject: [PATCH] No need to create a copy of graph proto when checking to see if there is fp16 input (#3061) * Don't create a copy of model proto when checking to see if there is fp16 input * PRcomments about making functions const * Loop through nodeargs in graph object to see if there are fp16 datatypes * Rename check to checking only inputs --- onnxruntime/core/session/inference_session.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/onnxruntime/core/session/inference_session.cc b/onnxruntime/core/session/inference_session.cc index 651a2eee18..cfdf85a32c 100644 --- a/onnxruntime/core/session/inference_session.cc +++ b/onnxruntime/core/session/inference_session.cc @@ -741,7 +741,7 @@ common::Status InferenceSession::InitializeSubgraphSessions(Graph& graph, Sessio return Status::OK(); } -static bool ModelUseFP16Helper(const onnx::TypeProto& type_proto) { +static bool ModelHasFP16InputsHelper(const onnx::TypeProto& type_proto) { switch (type_proto.value_case()) { case ::onnx::TypeProto::ValueCase::kTensorType: { if (type_proto.has_tensor_type()) { @@ -755,14 +755,14 @@ static bool ModelUseFP16Helper(const onnx::TypeProto& type_proto) { case ::onnx::TypeProto::ValueCase::kSequenceType: { if (type_proto.has_sequence_type()) { auto& sequence_type = type_proto.sequence_type(); - return ModelUseFP16Helper(sequence_type.elem_type()); + return ModelHasFP16InputsHelper(sequence_type.elem_type()); } break; } case ::onnx::TypeProto::ValueCase::kMapType: { if (type_proto.has_map_type()) { auto& map_type = type_proto.map_type(); - return ModelUseFP16Helper(map_type.value_type()); + return ModelHasFP16InputsHelper(map_type.value_type()); } break; } @@ -772,11 +772,9 @@ static bool ModelUseFP16Helper(const onnx::TypeProto& type_proto) { return false; } -static bool ModelUseFP16(const onnx::ModelProto& model_proto) { - auto& graph = model_proto.graph(); - auto& inputs = graph.input(); - for (auto& input : inputs) { - if (input.has_name() && input.has_type() && ModelUseFP16Helper(input.type())) { +static bool ModelHasFP16Inputs(const Graph& graph) { + for (auto& input : graph.GetInputs()) { + if (input->Exists() && ModelHasFP16InputsHelper(*(input->TypeAsProto()))) { return true; } } @@ -874,10 +872,10 @@ common::Status InferenceSession::Initialize() { is_inited_ = true; // and log telemetry - bool model_use_fp16 = ModelUseFP16(model_->ToProto()); + bool model_has_fp16_inputs = ModelHasFP16Inputs(graph); env.GetTelemetryProvider().LogSessionCreation(session_id_, model_->IrVersion(), model_->ProducerName(), model_->ProducerVersion(), model_->Domain(), model_->MainGraph().DomainToVersionMap(), model_->MainGraph().Name(), - model_->MetaData(), telemetry_.event_name_, execution_providers_.GetIds(), model_use_fp16); + model_->MetaData(), telemetry_.event_name_, execution_providers_.GetIds(), model_has_fp16_inputs); LOGS(*session_logger_, INFO) << "Session successfully initialized."; } catch (const NotImplementedException& ex) {