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

Onnxruntime fix #215960

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Onnxruntime fix #215960

wants to merge 2 commits into from

Conversation

chetant
Copy link

@chetant chetant commented Mar 23, 2025

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

Fixes #215955

When running a program compiled with onnxruntime that creates an Ort::Env, we'd get the following schema double registration errors:

Schema error: Trying to register schema with name Abs (domain:  version: 1) from file /tmp/onnx-20250108-35339-a6pxcu/onnx-1.17.0/onnx/defs/math/old.cc line 2743, but it is already registered from file /tmp/onnx-20250108-35339-a6pxcu/onnx-1.17.0/onnx/defs/math/old.cc line 2743

Schema error: Trying to register schema with name Add (domain:  version: 1) from file /tmp/onnx-20250108-35339-a6pxcu/onnx-1.17.0/onnx/defs/math/old.cc line 2627, but it is already registered from file /tmp/onnx-20250108-35339-a6pxcu/onnx-1.17.0/onnx/defs/math/old.cc line 2627

Schema error: Trying to register schema with name And (domain:  version: 1) from file /tmp/onnx-20250108-35339-a6pxcu/onnx-1.17.0/onnx/defs/logical/old.cc line 138, but it is already registered from file /tmp/onnx-20250108-35339-a6pxcu/onnx-1.17.0/onnx/defs/logical/old.cc line 138
...

As per https://onnxruntime.ai/docs/build/dependencies.html#use-preinstalled-packages

Each library can be built in different ways. For example, ONNX Runtime expects ONNX is built with “-DONNX_DISABLE_STATIC_REGISTRATION=ON”. If you have got a prebuilt ONNX library from somewhere, most likely it was not built in this way.

This creates a separate onnx build onnxnostaticreg (with the correct flags) specifically for onnxruntime and updates its dependency.

chetant added 2 commits March 22, 2025 22:03
Fixes the onnx dependency for onnxruntime by disabling static
registration in this package.
Previously using onnxruntime would throw exceptions on double
registrations (once from onnx, another from onnxruntime)
More details:
https://onnxruntime.ai/docs/build/dependencies.html#use-preinstalled-packages
@github-actions github-actions bot added the new formula PR adds a new formula to Homebrew/homebrew-core label Mar 23, 2025
args = %W[
-DBUILD_SHARED_LIBS=ON
-DCMAKE_INSTALL_RPATH=#{rpath}
-DONNX_DISABLE_STATIC_REGISTRATION=ON
Copy link
Member

Choose a reason for hiding this comment

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

Can we just rebuild onnx with this configuration instead?

Copy link
Author

@chetant chetant Mar 24, 2025

Choose a reason for hiding this comment

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

We can, and it will build, but any program linking with onnx only (and using nodes) will not work correctly, since it will skip over the schema registration at startup.

@cho-m
Copy link
Member

cho-m commented Mar 26, 2025

We don't want to introduce a conflicting formula that is only used as a dependency for a single formula.

There are 2 options I can think of:

  1. Use Fedora's workaround1 in onnx to specifically to handle onnxruntime.
  2. Let onnxruntime build its own copy of onnx and statically link it. In this case, should use protobuf-lite to avoid symbol conflicts in global registry, i.e. -Donnxruntime_USE_FULL_PROTOBUF=OFF

Debian is also trying to resolve this2. They did try ONNX_DISABLE_STATIC_REGISTRATION but ended up reverting due to failures running onnx tests.

Footnotes

  1. https://src.fedoraproject.org/rpms/onnx/blob/rawhide/f/0004-Add-fixes-for-use-with-onnxruntime.patch

  2. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1092898

@cho-m cho-m added the automerge-skip `brew pr-automerge` will skip this pull request label Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge-skip `brew pr-automerge` will skip this pull request new formula PR adds a new formula to Homebrew/homebrew-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using onnxruntime causes double registration exceptions
3 participants