Skip to content

Commit 52ae7fd

Browse files
edgchen1lavanyax
authored andcommitted
Fix handling of nodes inserted by NHWC transformer. (microsoft#10904)
1 parent 17f7421 commit 52ae7fd

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

onnxruntime/core/framework/session_state.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -988,23 +988,18 @@ Status SessionState::LoadFromOrtFormat(const fbs::SessionState& fbs_session_stat
988988
// kernel hashes for model are in top level SessionState
989989
const auto& compiled_kernel_hashes = GetCompiledKernelHashes();
990990

991-
const bool original_nodes_should_exist =
992-
compiled_kernel_hashes.empty()
993-
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
994-
&& graph_.RuntimeOptimizationReplayCtx().num_replayed_optimizations == 0
995-
#endif // !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
996-
;
997-
998991
// process the nodes that existed when the model was created
999992
for (FbsSessionStateViewer::Index i = 0, end = fbs_session_state_viewer.GetNumNodeKernelInfos(); i < end; ++i) {
1000993
const auto node_kernel_info = fbs_session_state_viewer.GetNodeKernelInfo(i);
1001994

1002995
Node* const node = graph_.GetNode(node_kernel_info.node_index);
1003996
if (node == nullptr) {
1004-
// this is OK if we have compiled kernels/replayed runtime optimizations and the original node was replaced.
997+
#if defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD)
998+
// this is OK if we have compiled kernels and the original node was replaced.
1005999
// if not the model is invalid.
1006-
ORT_RETURN_IF(original_nodes_should_exist,
1000+
ORT_RETURN_IF(compiled_kernel_hashes.empty(),
10071001
"Can't find node with index ", node_kernel_info.node_index, ". Invalid ORT format model.");
1002+
#endif // defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD)
10081003
continue;
10091004
}
10101005

onnxruntime/core/session/inference_session.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,9 @@ Status AssignNodesToEpsFromHashesImpl(Graph& graph, const fbs::SessionState& fbs
12801280
for (const auto& node : graph.Nodes()) {
12811281
if (node.GetExecutionProviderType().empty()) {
12821282
auto kernel_hash = utils::GetHashValueFromStaticKernelHashMap(node.OpType(), node.SinceVersion());
1283+
if (!kernel_hash.has_value()) {
1284+
kernel_hash = utils::GetInternalNhwcOpHash(node);
1285+
}
12831286
if (kernel_hash.has_value()) {
12841287
ORT_RETURN_IF_ERROR(set_node_ep(node.Index(), kernel_hash.value()));
12851288
}

0 commit comments

Comments
 (0)