Skip to content

Commit

Permalink
Update to output a warning level message if removing an initializer t…
Browse files Browse the repository at this point in the history
…hat is never used, and an info level message if removing an initializer that optimization has made redundant.
  • Loading branch information
skottmckay committed Jul 3, 2019
1 parent 4caa7c9 commit 75b1ae6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/onnxruntime/core/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ class Graph {
// NodeArgs that come from outer scope. Used when building a graph so that
// these don't get recorded as graph inputs in the GraphProto.
std::unordered_set<std::string> outer_scope_node_arg_names_;

int num_resolves_ = 0;
};

} // namespace onnxruntime
15 changes: 13 additions & 2 deletions onnxruntime/core/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ Status Graph::InferAndVerifySubgraphTypes(const Node& node, Graph& subgraph,
" inputs and requires ", num_required_subgraph_inputs,
" inputs. Either provide all subgraph inputs, or just the required inputs.");
}

subgraph_inputs = &required_subgraph_inputs;
num_subgraph_inputs = num_required_subgraph_inputs;
}
Expand Down Expand Up @@ -1871,6 +1871,8 @@ Status Graph::Resolve(bool no_proto_sync_required) {

ORT_RETURN_IF_ERROR(ForThisAndAllSubgraphs(all_subgraphs, finalize_func));

++num_resolves_;

return Status::OK();
}

Expand Down Expand Up @@ -2225,7 +2227,16 @@ void Graph::CleanUnusedInitializers() {
for (const auto& pv : name_to_initial_tensor_) {
const std::string& name = pv.first;
if (used_args.find(name) == end) {
LOGS_DEFAULT(INFO) << name << " exists in this graph's initializers but it is not used by any node";
// 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_DEFAULT(WARNING) << "Removing initializer '"
<< name << "'. It is not used by any node and should be removed from the model.";
} else {
LOGS_DEFAULT(INFO) << "Removing initializer '" << name << "'. It is no longer used by any node.";
}

erase_list.push_back(name);
}
}
Expand Down

0 comments on commit 75b1ae6

Please sign in to comment.