Skip to content

feat: allow user-provided ort::Environment - #373

Merged
mtavenrath merged 3 commits into
rustnn:mainfrom
theHamsta:set-ortenv
Nov 8, 2026
Merged

mtavenrath merged 3 commits into
rustnn:mainfrom
theHamsta:set-ortenv

Conversation

@theHamsta

@theHamsta theHamsta commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Describe the user-visible and code-level changes.

The OrtEnvironment has to stay a singleton instead of a context option because having only one environment per process is a limitation of the ort crate https://github.com/pykeio/ort/blob/6ed2423cc08ca21d0b07f467b6e4387ef1bee2ce/src/environment.rs#L515-L517 (and probably also safer to have only one from a onnxruntime perspective).

This feature allows registering additional EPs (also in pywebnn rustnn/pywebnn#33) or to let the user define the path to the onnxruntime library, ort log level and ort log destination.

We could consider in another PR to bind ORT log level with our Rust log level and implement an ort logger that uses log. I believe ort using tracing for logging to simply using tracing_subscriber could get us logging.

Validation

  • make test
  • Relevant WPT or integration checks

Documentation

See docs/development/documentation-policy.md for which page belongs to which change.

  • Updated the rustdoc comments and docs pages that describe the changed behavior (or no documented behavior changed)
  • If backend converter/executor operator support changed, ran make docs-backend-ops and committed docs/development/backend-operator-support.md
  • make docs-api and make ci-docs pass if rustdoc or docs pages changed

Comment thread src/backends/ort.rs
})?;
let device =
env.devices()
.nth(self.device_idx)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

just relying on the enumeration being reproducible is a bit risky but so it was also before. Maybe the bounds on the types from ort crate would allow now to store the actual device.

The OrtEnvironment has to stay a singleton instead of a context option
because having only one environment per process is a limitation of the
`ort` crate https://github.com/pykeio/ort/blob/6ed2423cc08ca21d0b07f467b6e4387ef1bee2ce/src/environment.rs#L515-L517
(and probably also safer to have only one from a onnxruntime perspective).

This feature allows registering additional EPs also in pywebnn.
@mtavenrath
mtavenrath merged commit 5dedbd5 into rustnn:main Nov 8, 2026
11 checks passed
@theHamsta
theHamsta deleted the set-ortenv branch November 9, 2026 11:11
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.

2 participants