Skip to content

Patch onnx v1.22.0 tensor.h to honour ONNX_NO_EXCEPTIONS - #32593

Closed
Ryan VanderMeulen (rvandermeulen) wants to merge 1 commit into
microsoft:mainfrom
rvandermeulen:onnx-patch-tensor-noexcept
Closed

Ryan VanderMeulen (rvandermeulen) wants to merge 1 commit into
microsoft:mainfrom
rvandermeulen:onnx-patch-tensor-noexcept

Conversation

@rvandermeulen

@rvandermeulen Ryan VanderMeulen (rvandermeulen) commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a hunk to cmake/patches/onnx/onnx.patch and its vcpkg mirror cmake/vcpkg-ports/onnx/binskim.patch routing the error callbacks in Tensor::elem_num() and Tensor::size_from_dim() through the existing [[noreturn]] throw_tensor_error() helper, which honours ONNX_NO_EXCEPTIONS. This is onnx/onnx#8220, merged upstream but not yet in a release; the hunk can be dropped when the onnx dependency moves past v1.22.0.

Motivation and Context

onnx v1.22.0 rewrote those two functions around safe_dim_product() with a callback that does a raw throw tensor_error(msg), bypassing onnx's ONNX_THROW_EX macro. That breaks any onnxruntime build with exceptions disabled as soon as the header is included. Fixes the build failure reported in onnx/onnx#8219 for onnxruntime consumers.

Copilot AI balanced review requested due to automatic review settings September 14, 2026 18:56
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

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.

🟡 Changes recommended

The vcpkg build path remains affected by the raw throw.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR patches ONNX v1.22.0 tensor error handling to honor ONNX_NO_EXCEPTIONS.

Changes:

  • Routes elem_num() and size_from_dim() errors through throw_tensor_error().
  • Leaves the vcpkg patch mirror uncovered.
File summaries
File Summary
cmake/patches/onnx/onnx.patch Adds the ONNX tensor exception-handling patch; the equivalent vcpkg hunk is still needed.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmake/patches/onnx/onnx.patch

Copilot AI left a comment

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.

🟢 Approval recommended

No unresolved issues were identified in the reviewed patches.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.

onnx v1.22.0 rewrote Tensor::elem_num() and Tensor::size_from_dim() around safe_dim_product() with an error callback that does a raw `throw tensor_error(msg)`, bypassing onnx's ONNX_THROW_EX macro. That breaks any onnxruntime build with exceptions disabled as soon as those headers are included.

Route both callbacks through the existing [[noreturn]] throw_tensor_error() helper, which honours ONNX_NO_EXCEPTIONS. This is onnx/onnx#8220 (merged upstream, fixes onnx/onnx#8219), carried in cmake/patches/onnx/onnx.patch and its vcpkg mirror cmake/vcpkg-ports/onnx/binskim.patch until the onnx dependency moves to a release that contains it.
@rvandermeulen

Copy link
Copy Markdown
Contributor Author

This was submitted before onnx v1.23.0 was cut. v1.23.0 includes onnx/onnx#8220, so if you'd rather bump the onnx dependency to v1.23.0 instead, this PR is superseded by that and can be closed.

@rvandermeulen

Copy link
Copy Markdown
Contributor Author

Edward Chen (@edgchen1) This is one of the related PRs from #32597, if you have a chance to take a look.

Edward Chen (edgchen1) pushed a commit that referenced this pull request Sep 28, 2026
…-minimal build (#32597)

### Description
Convert the raw `try`/`catch`/`throw` statements that a CPU-only,
non-minimal build still compiles to the `ORT_TRY` / `ORT_CATCH` /
`ORT_HANDLE_EXCEPTION` / `ORT_RETHROW` / `ORT_THROW` macros the rest of
the code base uses: `graph_partitioner`, `attention_fusion`,
`constant_folding`, `stft_decomposition`, `model_package_context`,
`ep_library_plugin`, `provider_bridge_ort`, and the `ORT_ENABLE_STREAM`
config reader/writer in `allocation_planner` (whose writer already used
`ORT_CATCH` but read the exception outside `ORT_HANDLE_EXCEPTION`).

`provider_bridge_ort.cc`'s 18 function-try-blocks have no macro
equivalent, so each becomes an `ORT_TRY` over the body followed by a
file-local `ORT_CATCH_LOG_RETURN_NULLPTR` that logs and returns
`nullptr`, the tail they all shared. `ProviderLibrary::Load`/`Get` keep
their unload-and-rethrow via `ORT_RETHROW`. The `allocation_planner`
handler that used `EXIT_ON_ERR` is expanded inline so its `return` stays
in the function rather than inside the handler lambda.

With exceptions enabled this is a spelling change with identical control
flow. With `onnxruntime_DISABLE_EXCEPTIONS` the result compiles and
links on Linux x64/aarch64, Windows x64/x86/arm64, macOS x64/arm64 and
Android arm/arm64/x64 (Firefox's CI, with #32591, #32592, #32593 and
#32595 applied alongside).

### Motivation and Context
Firefox builds ONNX Runtime with exceptions disabled and carries these
conversions as local patches, together with a hack that disables
`ORT_ENABLE_STREAM` only because of the `allocation_planner` sites.
Together with the other open PRs this leaves the
`onnxruntime_DISABLE_EXCEPTIONS` + `onnxruntime_MINIMAL_BUILD` coupling
as the only remaining obstacle to a non-minimal no-exceptions build.
@edgchen1

Copy link
Copy Markdown
Contributor

This was submitted before onnx v1.23.0 was cut. v1.23.0 includes onnx/onnx#8220, so if you'd rather bump the onnx dependency to v1.23.0 instead, this PR is superseded by that and can be closed.

I think we can just take ONNX 1.23. the ONNX version has been updated in main already with #32359.

@edgchen1

Copy link
Copy Markdown
Contributor

thanks for the PR. closing as we have already updated ONNX to 1.23 in main.

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