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

Align Rust API with C API and broaden functionality #15655

Closed
wants to merge 4 commits into from

Conversation

mcf06
Copy link

@mcf06 mcf06 commented Apr 24, 2023

Description

The original onnxruntime-rs has evolved both into the newly added Rust API bindings in ms/onnxruntime/rust and, separately, into a version by @seddonm1 that much more tightly mirrors the C API and includes significant additional functionality, such as IoBinding support.

This Draft PR is an effort to incorporate much of the work by @seddonm1 into ms/onnxruntime, while also including improvements from ms/onnxruntime, particularly around safety and Environment and Session management. Some reworking was done of the safety constructs in ms/onnxruntime to fit within the framework of OrtValues as first-class structs. Feedback from the community is greatly appreciated.

Motivation and Context

  • Represent OrtValue as its own struct, and allow direct use with Session::run().
  • Provide safe containers to separately address OrtValues that do and do not own their own data.
  • Allow use of Sessions across thread boundaries.
  • Add support for IoBinding, Metadata, more compute hardware

Safely handling OrtValues that own their data memory:

  • For graph inputs / outputs that have a fixed shape, MutableOrtValue / MutableOrtValueTyped couples the OrtValue to an ArrayViewMut that views the OrtValue's data memory. This allows seamless, repeated reads / writes to the OrtValue's data using the ndarray API, while preventing tensor shape changes that would require a new OrtValue. Easy to use with IoBindings and Session::run_with_iobinding().
  • For graph outputs with variable shape, OrtValues may be viewed with OrtValue::array_view() or array_view_mut().

Safely handling OrtValues that do not own their data memory:

  • For graph inputs with variable shape, NdArrayOrtValue transiently creates an OrtValue from an &ndarray::Array, borrowing the Array for the life of the OrtValue. Easy to use with Session::run_with_arrays(), a light wrapper around Session::run().

@mcf06
Copy link
Author

mcf06 commented Apr 24, 2023

@microsoft-github-policy-service agree company="3M"

@simgt
Copy link

simgt commented Feb 28, 2024

Hi @mcf06 – What's the status of this PR?

I caught up with the other thread, I'd be super interested in having these changes available on the "official" binding. In the mean time pykeio/ort seems to contain everything in this PR with more additions.

@Chiichen Chiichen mentioned this pull request Jul 28, 2024
6 tasks
@mcf06
Copy link
Author

mcf06 commented Jul 28, 2024

It looks like much of the community support around rust bindings for onnxruntime has coalesced around pykeio/ort, which I'm happy to see, so I'm going to close this draft PR.

@mcf06 mcf06 closed this Jul 28, 2024
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