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

[WIP] Upgrade Protobuf to v21.1 to accept Python Protobuf 4.21 #4242

Closed
wants to merge 19 commits into from

Conversation

jcwchen
Copy link
Member

@jcwchen jcwchen commented Jun 1, 2022

Description
Upgrade Protobuf to v21.1 to accept Python Protobuf 4.21

After upgrading to Protobuf 21. for building ONNX, ONNX with older Python Protobuf (<=3.20) will behave differently from ONNX with Python Protobuf (4.21): the output order for ONNX ModelProto will be different. To keep consistent behavior, the minimum supported Protobuf versiob would be 4.21 after this upgrade.

Motivation and Context
Closes #4239.

Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
@jcwchen jcwchen added build Issues related to ONNX builds and packages CI pipelines Issues related to the CI pipeline dependencies Pull requests that update a dependency file labels Jun 1, 2022
@jcwchen jcwchen requested a review from a team as a code owner June 1, 2022 22:52
@jcwchen jcwchen marked this pull request as draft June 1, 2022 22:52
@jcwchen jcwchen added the run release CIs Use this label to trigger release tests in CI label Jun 1, 2022
@jcwchen jcwchen closed this Jun 1, 2022
@jcwchen jcwchen reopened this Jun 1, 2022
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: jcwchen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: jcwchen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
@jcwchen jcwchen changed the title [WIP] Upgrade Protobuf to 3.19.0 to accept Protobuf 4.21 [WIP] Upgrade Protobuf to v21.1 to accept Python Protobuf 4.21 Jun 7, 2022
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
@jcwchen jcwchen marked this pull request as ready for review June 7, 2022 18:54
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
mkdir build_source && cd build_source
cmake ../cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_PROTOBUF_PATH -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
cmake ../cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_PROTOBUF_PATH -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=$BUILD_TYPE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider Python apps sharing messages with C++ using a native extension (see https://developers.google.com/protocol-buffers/docs/reference/python-generated#sharing-messages and #4274 (comment))?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Xavier for the reminder! Yes it seems that the option PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp should be added.

Just try to understand more context: so current ONNX does not rely on this option with Protobuf 4.21.0+ (Sharing Messages Between Python and C++), but it would be useful for your PR #4274?

Copy link
Contributor

@xadupre xadupre Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, every C++ function exposes with pybind11 receives an onnx graph as a serialized buffer and not the graph itself. (like check_model, shape_inference). I think this serialization / deserialization) has a significant cost and should be avoided. With the current version, removing any serialization in check_model would make it 2 or 3 times faster.

Copy link
Contributor

@xadupre xadupre Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation of protobuf is not really clear about that mechanism. I wonder if this flag should be used when building protobuf for python as well as the version linked with onnx. Default version of protobuf is:

>>> import google.protobuf.internal.api_implementation as api
>>> api.Type()
'upb'

So even if PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp for onnx, it does not change the fact the python version is still using another one. Python sharing messages with C++ won't work.

Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
@jcwchen jcwchen marked this pull request as draft July 20, 2022 22:10
@@ -1,3 +1,3 @@
numpy >= 1.16.6 # TODO: update once TensorFlow 2.6 is end of life
protobuf >= 3.12.2, <= 3.20.1
protobuf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protobuf>=3.12.2 ?

)

echo "Build protobuf from source on Windows."
Invoke-WebRequest -Uri https://github.com/protocolbuffers/protobuf/releases/download/v3.16.0/protobuf-cpp-3.16.0.tar.gz -OutFile protobuf.tar.gz -Verbose
Invoke-WebRequest -Uri https://github.com/protocolbuffers/protobuf/releases/download/v21.1/protobuf-cpp-3.21.1.tar.gz -OutFile protobuf.tar.gz -Verbose
Copy link
Contributor

@xadupre xadupre Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/v21.1/ ?

@CarlosRDomin
Copy link

This is great! Out of curiosity, is there an ETA to mainline this change? Anything we can do to help expedite it? :)

@jcwchen
Copy link
Member Author

jcwchen commented Aug 3, 2022

This is great! Out of curiosity, is there an ETA to mainline this change? Anything we can do to help expedite it? :)

Good question. I hold on this PR because upstream frameworks like PyTorch and TensorFlow are still using Protobuf 3. It's safer to upgrade ONNX's Protobuf version after they have updated theirs. IIUC, TensorFlow will probably upgrade their Protobuf version in next quarter (reference), but I don't know when PyTorch will do so. Therefore at this moment I don't have concrete ETA that when ONNX will upgrade Protobuf, but ONNX will do so right after both PyTorch and TensorFlow have upgraded their Protobuf.

@bruprod
Copy link

bruprod commented Nov 22, 2022

This is great! Out of curiosity, is there an ETA to mainline this change? Anything we can do to help expedite it? :)

This is great! Out of curiosity, is there an ETA to mainline this change? Anything we can do to help expedite it? :)

Good question. I hold on this PR because upstream frameworks like PyTorch and TensorFlow are still using Protobuf 3. It's safer to upgrade ONNX's Protobuf version after they have updated theirs. IIUC, TensorFlow will probably upgrade their Protobuf version in next quarter (reference), but I don't know when PyTorch will do so. Therefore at this moment I don't have concrete ETA that when ONNX will upgrade Protobuf, but ONNX will do so right after both PyTorch and TensorFlow have upgraded their Protobuf.

Hi :) Is there any update on the timeline for this PR? As far as I have seen TF and Pytorch already closed your linked PRs.

@jcwchen
Copy link
Member Author

jcwchen commented Nov 22, 2022

Hi :) Is there any update on the timeline for this PR? As far as I have seen TF and Pytorch already closed your linked PRs.

Although the linked PRs are closed, IIUC both PyTorch and TF are still using old Protobuf version. Recently ONNX has just upgraded its Protobuf to 3.20.2: #4629 for the upcoming ONNX 1.13 release. So this PR will be considered again for the next ONNX 1.14 release, which won't happen soon.

@jcwchen
Copy link
Member Author

jcwchen commented Mar 9, 2023

To faster resolve merge conflict issue, I have another new PR to achieve this: #4956. Please comment there if anyone has concern or thought. I will close this one. Thanks!

@jcwchen jcwchen closed this Mar 9, 2023
@jcwchen jcwchen deleted the jcw/protobuf4 branch March 9, 2023 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues related to ONNX builds and packages CI pipelines Issues related to the CI pipeline dependencies Pull requests that update a dependency file run release CIs Use this label to trigger release tests in CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade Protobuf to make ONNX compatible with Protobuf 4.21+
4 participants