Skip to content
Prev Previous commit
Preserve the order in sync required case
  • Loading branch information
yuslepukhin committed Aug 7, 2025
commit 0c2d91c0c1beec46ab8e22b8402c8544a922a757
9 changes: 6 additions & 3 deletions onnxruntime/core/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4396,6 +4396,7 @@ Status Graph::ProcessSubgraphsInMemoryData(ONNX_NAMESPACE::GraphProto& output_gr
// Filter in iterators for weights that are present in the name_to_initial_tensor_ map
// and preserve the order. This is needed for tests.
InlinedVector<InitializedTensorSet::const_iterator> initializers_to_process;
initializers_to_process.reserve(name_to_initial_tensor_.size());
for (const auto& tensor_proto : output_graph_proto.initializer()) {
auto hit = name_to_initial_tensor_.find(tensor_proto.name());
if (hit != name_to_initial_tensor_.end()) {
Expand All @@ -4419,9 +4420,11 @@ ONNX_NAMESPACE::GraphProto Graph::ToGraphProto() const {

InlinedVector<InitializedTensorSet::const_iterator> initializers_to_process;
initializers_to_process.reserve(name_to_initial_tensor_.size());
for (auto iter = name_to_initial_tensor_.cbegin(), end = name_to_initial_tensor_.cend();
iter != end; ++iter) {
initializers_to_process.push_back(iter);
for (const auto& tensor_proto : graph_proto_->initializer()) {
auto hit = name_to_initial_tensor_.find(tensor_proto.name());
if (hit != name_to_initial_tensor_.end()) {
initializers_to_process.push_back(hit);
}
}

ORT_THROW_IF_ERROR(RegenerateInitializersAndReplaceInMemory(initializers_to_process,
Expand Down
Loading