Skip to content

Conversation

@adrianlizarraga
Copy link
Contributor

Description

Cherry-pick the following PRs into the ORT 1.23.1 branch:

Motivation and Context

adrianlizarraga and others added 11 commits September 23, 2025 15:38
### Description
<!-- Describe your changes. -->
This fixes somewhat contrived edgecases that are present in our tests
  - input propagates to output
  - output is produced by an initializer.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Python API upcoming PR does not pass tests without it.
### Description
<!-- Describe your changes. -->
This pull request introduces several enhancements to ONNX Runtime's
Python and C++ APIs, focusing on improved device and memory information
handling, synchronization stream support, and tensor copy functionality.
It adds new Python bindings for device/memory types, exposes more
detailed session input/output metadata, and provides a Python-accessible
tensor copy API. The changes also refactor and extend the C++ API for
better stream and memory info management.

Key changes include:

### Device and Memory Information Enhancements

* Added Python bindings for `OrtMemoryInfoDeviceType`,
`OrtDeviceMemoryType`, and expanded `OrtDevice` to expose the memory
type via a new `mem_type` method. The `OrtMemoryInfo` Python class now
supports both legacy and new V2 constructors and exposes additional
properties such as device memory type and vendor ID.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1801-R1810)
[[2]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1839)
[[3]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eL1941-R2005)
* Extended the Python `InferenceSession` object to provide access to
input/output `OrtMemoryInfo` and `OrtEpDevice` objects through new
properties and methods.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR2702-R2729)
[[2]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR202-R213)
[[3]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR591-R593)
[[4]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR607-R609)

### Synchronization Stream and Execution Provider Device Support

* Introduced Python bindings for `OrtSyncStream`, including creation via
`OrtEpDevice.create_sync_stream()` and retrieval of device-specific
`OrtMemoryInfo` via `OrtEpDevice.memory_info()`.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1890-R1938)
[[2]](diffhunk://#diff-44e70fbe60cba71c94f1a46ec2b1facaa8e9475232dad6df5ecbea301e76d475R34-R44)
* Refactored the C++ API to generalize `SyncStream` handling, allowing
for unowned streams and improved type safety.
[[1]](diffhunk://#diff-17f64e8b38fcdcd25e90abcabeec4b420956b15fe63868a5d0b270c376bde209L1066-R1084)
[[2]](diffhunk://#diff-cc93f5f9d8078d3d3af14c9bb4c0c59e25a99f3ec75d7772ea20111ed7eb6ddeL672-R677)

### Tensor Copy Functionality

* Added a new Python-level `copy_tensors` function and corresponding C++
binding, enabling efficient copying of tensor data between `OrtValue`
objects, optionally using a synchronization stream.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1588-R1599)
[[2]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR1155-R1163)
[[3]](diffhunk://#diff-44e70fbe60cba71c94f1a46ec2b1facaa8e9475232dad6df5ecbea301e76d475R84)

### Miscellaneous Improvements and Fixes

* Changed the return type of the `OrtValue.data_ptr` method in the
Python binding from `int64_t` to `uintptr_t` for better cross-platform
compatibility.
[[1]](diffhunk://#diff-666c9002698d1bbd4215237231e5be98d7b33e5054f018dce952407027bd0473L336-R336)
[[2]](diffhunk://#diff-666c9002698d1bbd4215237231e5be98d7b33e5054f018dce952407027bd0473L347-R347)
* Minor improvements to error messages and device type handling in the
Python API (e.g., for `OrtDevice`).
[[1]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR1176)
[[2]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR1219-R1221)
* Included necessary C++ includes for plugin stream support.

These changes collectively improve the flexibility and introspection
capabilities of ONNX Runtime's device, memory, and execution provider
interfaces, and make advanced features available to Python users.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Depends on: #26021
<!-- Describe your changes. -->

Add support for `MemcpyFromHost` and `MemcpyToHost` ops with plugin EPs.

- Add CPU EP fallback kernels for the memcpy ops. These are generic
implementations using a data transfer manager.
- Update `SessionState::PopulateKernelCreateInfo()` to fall back to CPU
memcpy kernels if a node's assigned provider doesn't have them.
- Update `MemcpyTransformer` to determine whether providers are
CPU-based or compatible with other providers by looking at the device
type instead of matching against a hardcoded list of provider types.
This accommodates plugin EPs, where the provider type can't be
hardcoded.

<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Allow plugin EPs to work with models where memcpy ops are required
(i.e., models where connected nodes are not fully assigned to the plugin
EP).
…lity (#26132)

### Description
In current TRT RTX EP/ TRT EP implementation, when constructing the
`IndexedSubGraph`, for some cases, it will include the node's unused
output as the SubGraph's output. So, it will return the incorrect
`IndexedSubGraph` from its GetCapability to ORT.
Add the logic to prevent adding the unused node's output.

With this fix, we can avoid generating the incorrect EPContext model
where the EPContext node has unused output.
@adrianlizarraga adrianlizarraga merged commit ceaf9f4 into rel-1.23.1 Sep 24, 2025
74 of 75 checks passed
@adrianlizarraga adrianlizarraga deleted the adrianl/rel-1.23.1-cherrypick-1-redo branch September 24, 2025 15:15
TedThemistokleous added a commit to ROCm/onnxruntime that referenced this pull request Oct 17, 2025
* ORT 1.23.1 cherrypick 1 [REDO] (microsoft#26140)

### Description
Cherry-pick the following PRs into the ORT 1.23.1 branch:

- Fix Attention GQA implementation on CPU
- **MANUAL MERGE**: see
microsoft#26057
  - main merge date: Sept 15, 11:33am
  - pr: microsoft#25966
  - commit: d530b29
- Address edge GetMemInfo edge cases
  - main merge date: Sept 16, 10:32am
  - pr: microsoft#26021
  - commit: d251f3a
- Implement new Python APIs
  - main merge date: Sept 17, 11:44am
  - pr: microsoft#25999
  - commit: abc63e8
- MemcpyFromHost and MemcpyToHost support for plugin EPs
- **MERGE CONFLICT** on file
onnxruntime/test/optimizer/transpose_optimizer_test.cc. Conflicts with
microsoft#25689
  - main merge date: Sept 23, 10:42am
  - pr: microsoft#26088
  - commit: 4545732
- [TRT RTX EP] Fix bug for generating the correct subgraph in
GetCapability microsoft#26132
  - main merge date: Sept 23, 8:54pm
  - pr: microsoft#26132
  - commit: 72e56e7


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

---------

Co-authored-by: Dmitri Smirnov <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
Co-authored-by: Chi Lo <[email protected]>

* ORT 1.23.1 cherrypick 2 (microsoft#26182)

### Description
Adds the following commits to the `rel-1.23.1` branch for ORT 1.23.1:


- add session_id_ to LogEvaluationStart/Stop, LogSessionCreationStart
  - main merge date: July 31, 1:05am
  - pr: microsoft#25590
  - commit: e753643
- [build] fix WebAssembly build on macOS/arm64
  - main merge date: Aug 5, 8:07am
  - pr: microsoft#25653
  - commit: 53f152b
- [CPU] MoE Kernel (microsoft#25958)
  - main merge date: Sept 10, 4:54pm
  - pr: microsoft#25958
  - commit: 930e640
- [CPU] Block-wise QMoE kernel for CPU
  - main merge date: Sept 15, 8:32am
  - pr: microsoft#26009
  - commit: 5d17734
- [C#] Implement missing APIs
  - main merge date: Sept 24, 10:50am
  - pr: microsoft#26101
  - commit: 35dcab5
- Regenerate test model with ONNX IR < 12
  - main merge date: Sept 24, 2:50pm
  - pr: microsoft#26149
  - commit: 88f2652
- [CPU] Fix compilation errors because of unused variables
  - main merge date: Sept 25, 1:21pm
  - pr: microsoft#26147
  - commit: 42fcd71
- [EP ABI] Check if nodes specified in GetCapability() have already been
assigned
  - main merge date: Sept 26, 1:24am
  - pr: microsoft#26156
  - commit: 67d3ba0
- [QNN EP] Add dynamic option to set HTP performance mode
  - main merge date: Sept 26, 11:55am
  - pr: microsoft#26135
  - commit: 6cc40fd

---------

Co-authored-by: xieofxie <[email protected]>
Co-authored-by: hualxie <[email protected]>
Co-authored-by: Yulong Wang <[email protected]>
Co-authored-by: Akshay Sonawane <[email protected]>
Co-authored-by: Dmitri Smirnov <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
Co-authored-by: quic-tirupath <[email protected]>
Co-authored-by: quic-ashwshan <[email protected]>

---------

Co-authored-by: Adrian Lizarraga <[email protected]>
Co-authored-by: Dmitri Smirnov <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
Co-authored-by: Chi Lo <[email protected]>
Co-authored-by: xieofxie <[email protected]>
Co-authored-by: hualxie <[email protected]>
Co-authored-by: Yulong Wang <[email protected]>
Co-authored-by: Akshay Sonawane <[email protected]>
Co-authored-by: quic-tirupath <[email protected]>
Co-authored-by: quic-ashwshan <[email protected]>
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.

7 participants