Skip to content

Commit

Permalink
[build] Be compatible with the latest protobuf (#23260)
Browse files Browse the repository at this point in the history
Resolve #21308
  • Loading branch information
snnn committed Jan 8, 2025
1 parent 939de11 commit f40c96e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions onnxruntime/core/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1286,9 +1286,9 @@ Graph::Graph(const Model& owning_model,
ORT_ENFORCE(p.second, "Duplicate sparse_tensor_initializer: '", tensor->name(), "' Model is invalid.");
}

#if GOOGLE_PROTOBUF_VERSION < 5026000
// 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();
Expand Down Expand Up @@ -3648,11 +3648,11 @@ void Graph::CleanAllInitializedTensors() noexcept {
#if !defined(DISABLE_SPARSE_TENSORS)
sparse_tensor_names_.clear();
#endif
#if GOOGLE_PROTOBUF_VERSION < 5026000
// 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();
Expand Down

0 comments on commit f40c96e

Please sign in to comment.