Conversation
…rtDevice` aliases
yuslepukhin
reviewed
Mar 9, 2026
skottmckay
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change replaces the Python-side PCI vendor ID constants in
onnxruntime_inference_collection.pywith apublic
OrtDeviceVendorIdenum, exports that enum fromonnxruntime.__init__, and continues using vendor-awareOrtDeviceconstruction for well-known aliases like"cuda","dml", and"cann".The goal is to make vendor IDs reusable across Python APIs without duplicating raw integer constants while still
fixing the plugin EP allocator lookup issue for
OrtValue.ortvalue_from_numpy(..., "cuda", ...).Problem
The Python wrapper now needs vendor IDs in more than one place.
Keeping them as standalone integer constants is workable for a narrow fix, but it does not give Python callers a
clear public API for vendor identity. As more APIs accept or return vendor IDs, users would have to either:
That is not a good public surface for something that is now part of regular Python device construction flows.
Why We Need This Change
Dynamic EP registration is intended to let a Python package gain hardware capability without requiring that hardware
support to be built into the package itself.
That only works if the Python-side device description matches the device identity used by dynamically registered EP
allocators and data transfers.
Without the underlying vendor-aware alias behavior:
CudaPluginExecutionProviderOrtValues withOrtValue.ortvalue_from_numpy(..., "cuda", 0)At the same time, without a public enum:
"gpu"/"npu"devicesExample Use Case
Our immediate use case is the CUDA plugin EP flow from Python.
We register
libonnxruntime_providers_cuda_plugin.sofrom Python and create sessions withCudaPluginExecutionProvider. That part works.Stage 4 of the plugin flow needs to create GPU-resident
OrtValues:Before the vendor-aware alias fix, that failed in a CPU-only Python package even after the CUDA plugin was
registered, because the Python wrapper constructed a generic GPU
OrtDevicewithout the NVIDIA vendor ID.With this change, Python also has a public enum for vendor IDs, so callers can write explicit vendor-aware code
when using generic device names:
Fix
The change does three things:
Replace the Python-side PCI vendor ID constants with an
IntEnumnamedOrtDeviceVendorId.Export
OrtDeviceVendorIdfromonnxruntime.__init__so it is part of the public Python API.Keep the vendor-aware alias behavior in
OrtDevice.make(...)so that the historical shorthand aliases:"cuda"->OrtDeviceVendorId.NVIDIA"dml"->OrtDeviceVendorId.MICROSOFT"cann"->OrtDeviceVendorId.HUAWEIuse the 4-argument
C.OrtDevice(...)constructor with an explicit vendor ID.Generic device names like
"gpu"and"npu"continue to behave as before unless the caller explicitly provides avendor ID, and callers can now use either an integer or
OrtDeviceVendorId.Why This Approach
An enum is the better public API here because it:
ortdevice.hIntEnumstill works naturally with the pybind layerThis keeps the original plugin fix intact while improving the Python API shape instead of just adding more module
constants.
Validation
Validated in the Python layer by:
"cuda","dml", and"cann"OrtDeviceVendorIdfrom the top-levelonnxruntimepackageOrtDevice.make("cuda", 0)resolves to the NVIDIA vendor ID via the enumpython -m compileallon the updated Python filesTargeted pytest execution could not be completed in this workspace because the local source tree does not provide an
importable
onnxruntime.capimodule without a built package.Notes
This PR keeps backward compatibility for existing Python call sites:
"cuda"continue to workvendor_idarguments can still be passed as integersonnxruntime.OrtDeviceVendorId