Skip to content

Commit

Permalink
[TensorRT EP] Fix bug for no nodes in subgraph at GetCapability (micr…
Browse files Browse the repository at this point in the history
…osoft#18449)

It's possible that subgraph of the "If" control flow op has no nodes.
TRT EP should consider this kind of subgraph is fully supported by TRT.

The faster rcnn model mentioned in this issue
microsoft#17434 is the case.
  • Loading branch information
chilo-ms authored and kleiti committed Mar 22, 2024
1 parent 05566a0 commit e220693
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,10 @@ TensorrtExecutionProvider::GetCapability(const GraphViewer& graph,
if (sub_graphs.size() != 0) {
bool all_subgraphs_are_supported = true;
for (auto sub_graph : sub_graphs) {
// TRT EP should consider the empty subgraph is fully supported by TRT.
if (sub_graph->CreateGraphViewer()->NumberOfNodes() == 0) {
continue;
}
if (!AllNodesAssignedToSpecificEP(*(sub_graph->CreateGraphViewer()), kTensorrtExecutionProvider)) {
all_subgraphs_are_supported = false;
break;
Expand Down Expand Up @@ -1896,27 +1900,33 @@ TensorrtExecutionProvider::GetCapability(const GraphViewer& graph,
auto sub_graphs = graph.ParentNode()->GetSubgraphs();
for (auto sub_graph : sub_graphs) {
if (sub_graph.get() != &graph.GetGraph()) {
auto sub_graph_veiwer = sub_graph->CreateGraphViewer();
const int number_of_ort_subgraph_nodes = sub_graph_veiwer->NumberOfNodes();
auto sub_graph_viewer = sub_graph->CreateGraphViewer();
const int number_of_ort_subgraph_nodes = sub_graph_viewer->NumberOfNodes();
std::vector<size_t> subgraph_nodes_vector(number_of_ort_subgraph_nodes);
std::iota(std::begin(subgraph_nodes_vector), std::end(subgraph_nodes_vector), 0);
SubGraphCollection_t parser_subgraph_nodes_vector = {{subgraph_nodes_vector, false}};
bool subgraph_early_termination = false;

// Another subgraph of "If" control flow has been parsed by GetCapability before and all subgraph's nodes assigned to TRT EP.
if (AllNodesAssignedToSpecificEP(*sub_graph_veiwer, kTensorrtExecutionProvider)) {
// Another subgraph of "If" control flow op has no nodes.
// In this case, TRT EP should consider this empty subgraph is fully supported by TRT.
if (sub_graph_viewer->NumberOfNodes() == 0) {
all_subgraphs_are_supported = true;
break;
}
// Another subgraph of "If" control flow op has been parsed by GetCapability before and all subgraph's nodes assigned to TRT EP.
else if (AllNodesAssignedToSpecificEP(*sub_graph_viewer, kTensorrtExecutionProvider)) {
all_subgraphs_are_supported = true;
break;
}
// Another subgraph of "If" control flow has been parsed by GetCapability and not all subgraph's nodes assigned to TRT EP.
// (Note: GetExecutionProviderType() returns "" meaning node has not yet been assigned to any EPs)
else if (!AllNodesAssignedToSpecificEP(*sub_graph_veiwer, "")) {
else if (!AllNodesAssignedToSpecificEP(*sub_graph_viewer, "")) {
all_subgraphs_are_supported = false;
break;
}

// Another subgraph of "If" control flow has not yet been parsed by GetCapability.
subgraph_supported_nodes_vector = GetSupportedList(parser_subgraph_nodes_vector, 0, max_partition_iterations_, *sub_graph_veiwer, &subgraph_early_termination);
subgraph_supported_nodes_vector = GetSupportedList(parser_subgraph_nodes_vector, 0, max_partition_iterations_, *sub_graph_viewer, &subgraph_early_termination);
all_subgraphs_are_supported = IsSubGraphFullySupported(subgraph_supported_nodes_vector, number_of_ort_subgraph_nodes);
break;
}
Expand Down

0 comments on commit e220693

Please sign in to comment.