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
This commit is contained in:
Ryan Lai 2020-02-24 15:14:29 -08:00 committed by GitHub
parent dae9a31719
commit a506911208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {