Skip to content

Commit f0097fc

Browse files
authored
Exclude EPContext Op from Common Subexpression Elimination graph optimization (microsoft#25296)
In the context of a model containing EPContext nodes, it's highly unlikely that two EPContext nodes will produce the same results. Furthermore, the EquivalenceClass constructor includes the node and all its attributes in the hash calculation, which can be particularly time-consuming when the "ep_cache_context" attribute contains a large binary blob. Therefore, we exclude EPContext op from CSE.
1 parent 15e75af commit f0097fc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

onnxruntime/core/optimizer/common_subexpression_elimination.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,13 @@ Status CommonSubexpressionElimination::ApplyImpl(Graph& graph, bool& modified, i
421421

422422
for (NodeIndex node_index : node_topology_list) {
423423
Node* node = graph.GetNode(node_index);
424-
if (node == nullptr)
424+
425+
// In the context of a model containing EPContext nodes, it's highly unlikely that two EPContext nodes will
426+
// produce the same results.
427+
// Furthermore, the EquivalenceClass constructor includes the node and all its attributes in the hash calculation,
428+
// which can be particularly time-consuming when the "ep_cache_context" attribute contains a large binary blob.
429+
// Therefore, EPContext nodes are excluded from this process.
430+
if (node == nullptr || node->OpType() == "EPContext")
425431
continue;
426432

427433
ORT_RETURN_IF_ERROR(Recurse(*node, modified, graph_level, logger));
@@ -471,7 +477,12 @@ Status CommonSubexpressionElimination::ApplyImpl(Graph& graph, bool& modified, i
471477

472478
for (NodeIndex node_index : node_topology_list) {
473479
Node* node = graph.GetNode(node_index);
474-
if (node == nullptr)
480+
// In the context of a model containing EPContext nodes, it's highly unlikely that two EPContext nodes will
481+
// produce the same results.
482+
// Furthermore, the EquivalenceClass constructor includes the node and all its attributes in the hash calculation,
483+
// which can be particularly time-consuming when the "ep_cache_context" attribute contains a large binary blob.
484+
// Therefore, EPContext nodes are excluded from this process.
485+
if (node == nullptr || node->OpType() == "EPContext")
475486
continue;
476487

477488
bool node_output_replaced = false;

0 commit comments

Comments
 (0)