Skip to content

Commit ef4adf5

Browse files
EPCtx changes for dynamic model with reshape_input provider optional
1. Throw an ErrorMessage when user provide reshape_input with EPctx graph. 2. Do not Create dynamic_backend for EPctx graph. Update onnxruntime/core/providers/openvino/backend_manager.cc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7f86fad commit ef4adf5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

onnxruntime/core/providers/openvino/backend_manager.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ BackendManager::BackendManager(SessionContext& session_context,
8484
ptr_stream_t model_stream;
8585
std::unique_ptr<onnx::ModelProto> model_proto;
8686
if (subgraph_context_.is_ep_ctx_graph) {
87+
if (!session_context_.reshape.empty()) {
88+
std::string exception_str =
89+
"[OpenVINO-EP] reshape_input is not supported for EPContext graph";
90+
ORT_THROW(exception_str);
91+
}
8792
model_stream = ep_ctx_handle_.GetModelBlobStream(session_context_.so_context_file_path, subgraph);
8893
} else {
8994
model_proto = GetModelProtoFromFusedNode(fused_node, subgraph, logger);
@@ -125,6 +130,21 @@ BackendManager::BackendManager(SessionContext& session_context,
125130
LOGS_DEFAULT(INFO) << "[OpenVINO-EP] "
126131
<< "Backend created for graph " << subgraph_context_.subgraph_name;
127132
} else {
133+
// Do not create dynamic backend for EPCtx graph
134+
if (subgraph_context_.is_ep_ctx_graph) {
135+
LOGS_DEFAULT(INFO) << "[OpenVINO-EP] Starting backend initialization. "
136+
<< "Initializing backend for EPContext graph "
137+
<< subgraph_context_.subgraph_name;
138+
try {
139+
concrete_backend_ = BackendFactory::MakeBackend(model_proto,
140+
session_context_,
141+
subgraph_context_,
142+
shared_context_,
143+
model_stream);
144+
} catch (std::string const& msg) {
145+
ORT_THROW(msg);
146+
}
147+
}
128148
// Only cache model_proto in session context to rewrite the model with input shapes at runtime.
129149
// For dynamic backend creation
130150
model_proto_ = std::move(model_proto);
@@ -590,7 +610,7 @@ void BackendManager::Compute(OrtKernelContext* context) {
590610
// by rewriting the model to static shaped model at runtime based on input shape.
591611
// disable_dynamic_shapes should be set for devices that don't support dynamic shapes.
592612
bool need_dynamic_backend = subgraph_context_.has_dynamic_input_shape &&
593-
session_context_.disable_dynamic_shapes;
613+
session_context_.disable_dynamic_shapes && !subgraph_context_.is_ep_ctx_graph;
594614

595615
if (!need_dynamic_backend) {
596616
concrete_backend_->Infer(context);

0 commit comments

Comments
 (0)