diff --git a/onnxruntime/core/framework/session_state.cc b/onnxruntime/core/framework/session_state.cc index aa9ec44f71..fdd54d913e 100644 --- a/onnxruntime/core/framework/session_state.cc +++ b/onnxruntime/core/framework/session_state.cc @@ -688,6 +688,19 @@ void SessionState::ResolveMemoryPatternFlag() { break; } } + + // For subgraphs, the implicit inputs need to meet the same crieria + // as the explicit inputs for memory pattern to be enabled + if (graph_viewer_->IsSubgraph()) { + const auto* parent_node = graph_viewer_->ParentNode(); + + for (auto* implicit_input : parent_node->ImplicitInputDefs()) { + if (!implicit_input->HasTensorOrScalarShape()) { + enable_mem_pattern_ = false; + break; + } + } + } } }