Skip to content

Commit 211d5fa

Browse files
authored
Check for non-empty ep_nodes before resizing index_to_ep_node in EpGraph::CreateImpl(). (microsoft#26001)
### Description <!-- Describe your changes. --> Check for non-empty `ep_nodes` before resizing `index_to_ep_node` in `EpGraph::CreateImpl()`. In this code: https://github.com/microsoft/onnxruntime/blob/502416772611825f2e80fb14a865ebf72670689d/onnxruntime/core/graph/ep_api_types.cc#L663-L683 If there are no nodes to process, the values of `min_node_index` and `max_node_index` will not be updated and this assertion in `IndexToEpNodeMap::Resize()` will fail. https://github.com/microsoft/onnxruntime/blob/502416772611825f2e80fb14a865ebf72670689d/onnxruntime/core/graph/ep_api_types.cc#L538 ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Fix debug assertion failure in [`If.ConditionalBranchesOnlyContainConstantNodes_ThenBranchExecution`](https://github.com/microsoft/onnxruntime/blob/502416772611825f2e80fb14a865ebf72670689d/onnxruntime/test/providers/cpu/controlflow/if_test.cc#L406-L411) when running unit test with a plugin EP (see microsoft#25689).
1 parent e3ea71a commit 211d5fa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

onnxruntime/core/graph/ep_api_types.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,11 @@ Status EpGraph::CreateImpl(std::unique_ptr<EpGraph> ep_graph, const GraphViewer&
680680
}
681681

682682
// Iterate through nodes again and update the map of NodeIndex to EpNode*
683-
index_to_ep_node.Resize(min_node_index, max_node_index);
684-
for (std::unique_ptr<EpNode>& ep_node : ep_nodes) {
685-
index_to_ep_node.SetEpNode(ep_node->GetInternalNode().Index(), ep_node.get());
683+
if (!ep_nodes.empty()) {
684+
index_to_ep_node.Resize(min_node_index, max_node_index);
685+
for (std::unique_ptr<EpNode>& ep_node : ep_nodes) {
686+
index_to_ep_node.SetEpNode(ep_node->GetInternalNode().Index(), ep_node.get());
687+
}
686688
}
687689

688690
// If this is a subgraph, add the OrtValueInfo and OrtValue objects that come from the outer scope.

0 commit comments

Comments
 (0)