Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] Be compatible with the latest protobuf #23260

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion onnxruntime/core/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,12 @@ Graph::Graph(const Model& owning_model,

// Remove sparse_initializers from protobuf to save memory as they are converted to dense now
graph_proto_->mutable_sparse_initializer()->Clear();
#if GOOGLE_PROTOBUF_VERSION < 5026000
const int sparse_num_cleared = graph_proto_->sparse_initializer().ClearedCount();
for (int i = 0; i < sparse_num_cleared; ++i) {
delete graph_proto_->mutable_sparse_initializer()->ReleaseCleared();
}
#endif
}
#endif

Expand Down Expand Up @@ -3646,15 +3648,16 @@ void Graph::CleanAllInitializedTensors() noexcept {
#if !defined(DISABLE_SPARSE_TENSORS)
sparse_tensor_names_.clear();
#endif

// Clearing RepeatedPtrFields does not free objects' memory. The memory is retained
// and can be reused. Need to explicitly release the cleared objects and free the
// memory.
graph_proto_->mutable_initializer()->Clear();
#if GOOGLE_PROTOBUF_VERSION < 5026000
const int num_cleared = graph_proto_->initializer().ClearedCount();
for (int i = 0; i < num_cleared; i++) {
delete graph_proto_->mutable_initializer()->ReleaseCleared();
}
#endif
}

const ONNX_NAMESPACE::TensorProto* Graph::GetConstantInitializer(const std::string& initializer_name,
Expand Down
Loading