Skip to content

Collision avoidence for op registration. - #12505

Open
xkszltl wants to merge 1 commit into
microsoft:mainfrom
xkszltl:reg
Open

Collision avoidence for op registration.#12505
xkszltl wants to merge 1 commit into
microsoft:mainfrom
xkszltl:reg

Conversation

@xkszltl

@xkszltl xkszltl commented Aug 8, 2022

Copy link
Copy Markdown
Contributor

When linked with shared onnx libs, its static registration already did the work, and ort should not re-reg again.
Instead of hard-coding who's responsible for the job, now we check and reg if missing.
Call to map() inside Schema() will ensure init is done exactly once and is before probing.
If not all domains are there for whatever reason, ort will still cover that up.

This change also removes the need to disable that with extra -D in ort build and avoid unnecessary divergence.

@skottmckay

Copy link
Copy Markdown
Contributor

This change also removes the need to disable that with extra -D in ort build and avoid unnecessary divergence.

What was being set with the 'extra -D'?


// Call once to trigger schema static registration.
// Note: This is not transactional and can still collide with concurrent calls from other libs.
if (!OpSchemaRegistry::Schema("Add")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is __ONNX_DISABLE_STATIC_REGISTRATION set by default so that this call doesn't trigger registration of all schemas?

What's the reason we need to do this at the ORT level vs. ONNX gracefully handling multiple calls to schema registration? The check for an semi-arbitrary operator name feels a little hacky.

@xkszltl xkszltl Oct 17, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is __ONNX_DISABLE_STATIC_REGISTRATION set by default so that this call doesn't trigger registration of all schemas?

ONNX_DISABLE_STATIC_REGISTRATION is off by default, AFAIK it's just a backdoor for whoever need to load a subset of opset manually, for memory or collision avoidence.

What's the reason we need to do this at the ORT level vs. ONNX gracefully handling multiple calls to schema registration?

You'll need to ask them (i.e. onnx and protobuf) for sure.
But clearly the static/shared protobuf discussion didn't move much forward in the past few years.
And google themselves is always doing that monorepo + everything-static thing, so I'm not expecting this to end well in a foreseeable future.

The check for an semi-arbitrary operator name feels a little hacky.

Yes, so I picked the very basic Add.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you specify ONNX_DISABLE_STATIC_REGISTRATION when creating the shared onnx library you're linking against, is the change in ORT required?

I'm trying to understand why we need to add this hack to ORT given it's not necessary in the typical usage of ORT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be a breaking change to onnx behavior as no op would be registered, making onnx itself unusable in normal cases.

@xkszltl

xkszltl commented Oct 17, 2022

Copy link
Copy Markdown
Contributor Author

What was being set with the 'extra -D'?

ONNX_DISABLE_STATIC_REGISTRATION in cmake, or the corresponding __ONNX_DISABLE_STATIC_REGISTRATION to compiler.

When linked with shared onnx libs, its static registration already did the work, and ort should not re-reg again.
Instead of hard-coding who's responsible for the job, now we check and reg if missing.
Call to `map()` inside `Schema()` will ensure init is done exactly once and is before probing.
If not all domains are there for whatever reason, ort will still cover that up.

This change also removes the need to disable that with extra `-D` in ort build and avoid unnecessary divergence.
@xkszltl

xkszltl commented Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

ping on this one

@patrikhuber

Copy link
Copy Markdown

This is an issue for vcpkg users, preventing a "clean" workflow, see here: microsoft/vcpkg#36850. Users of onnxruntime have to create a custom workaround (called "custom triplet") to build onnx with ONNX_DISABLE_STATIC_REGISTRATION. I suspect other package managers will have the same issue.
More users getting caught by this: microsoft/vcpkg#49060.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants