-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Language bindings for model compatibility API #25878
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac0b138
Initial draft of language bindings for model compatibility API
439995d
Add basic unit test case for C++ API
bdd191e
Add documentation for enum (should fix PR build), add C# API test
623098a
Documentation fixes for managed method
189d3ff
Adding Python unit test
f345b7f
Applying lintunner fix
15bc5ff
PR feedback (doc fixes, line wrapping)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/EpCompatibilityTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // not supported on mobile platforms | ||
| #if !(ANDROID || IOS) | ||
|
|
||
| namespace Microsoft.ML.OnnxRuntime.Tests; | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using Xunit; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class EpCompatibilityTests | ||
| { | ||
| private readonly OrtEnv ortEnvInstance = OrtEnv.Instance(); | ||
|
|
||
| private IReadOnlyList<OrtEpDevice> GetDevices() | ||
| { | ||
| var epDevices = ortEnvInstance.GetEpDevices(); | ||
| Assert.NotNull(epDevices); | ||
| Assert.NotEmpty(epDevices); | ||
| return epDevices; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetEpCompatibility_InvalidArgs() | ||
| { | ||
| Assert.Throws<ArgumentException>(() => ortEnvInstance.GetModelCompatibilityForEpDevices(null, "info")); | ||
| Assert.Throws<ArgumentException>(() => ortEnvInstance.GetModelCompatibilityForEpDevices(new List<OrtEpDevice>(), "info")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetEpCompatibility_SingleDeviceCpuProvider() | ||
| { | ||
| var devices = GetDevices(); | ||
| var someInfo = "arbitrary-compat-string"; | ||
|
|
||
| // Use CPU device | ||
| var cpu = devices.First(d => d.EpName == "CPUExecutionProvider"); | ||
| Assert.NotNull(cpu); | ||
| var selected = new List<OrtEpDevice> { cpu }; | ||
| var status = ortEnvInstance.GetModelCompatibilityForEpDevices(selected, someInfo); | ||
|
|
||
| // CPU defaults to not applicable in this scenario | ||
| Assert.Equal(OrtCompiledModelCompatibility.EP_NOT_APPLICABLE, status); | ||
| } | ||
| } | ||
| #endif |
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
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
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
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
46 changes: 46 additions & 0 deletions
46
onnxruntime/test/python/onnxruntime_test_python_ep_compatibility.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
||
| # Licensed under the MIT License. | ||
|
|
||
| import os | ||
| import platform | ||
| import sys | ||
| import unittest | ||
|
|
||
| from onnxruntime.capi.onnxruntime_pybind11_state import ( | ||
| OrtCompiledModelCompatibility, | ||
| get_ep_devices, | ||
| get_model_compatibility_for_ep_devices, | ||
| ) | ||
|
|
||
| # handle change from python 3.8 and on where loading a dll from the current directory needs to be explicitly allowed. | ||
| if platform.system() == "Windows" and sys.version_info.major >= 3 and sys.version_info.minor >= 8: # noqa: YTT204 | ||
| os.add_dll_directory(os.getcwd()) | ||
|
|
||
|
|
||
| class TestEpCompatibility(unittest.TestCase): | ||
| def test_invalid_args(self): | ||
| # empty devices | ||
| with self.assertRaises(RuntimeError): | ||
| get_model_compatibility_for_ep_devices([], "info") | ||
| # None compatibility info should raise TypeError before native call | ||
| with self.assertRaises(TypeError): | ||
| get_model_compatibility_for_ep_devices(get_ep_devices(), None) # type: ignore[arg-type] | ||
|
|
||
| def test_basic_smoke(self): | ||
| devices = list(get_ep_devices()) | ||
| if not devices: | ||
| self.skipTest("No EP devices available in this build") | ||
|
|
||
| # Always select CPUExecutionProvider; skip if not present. | ||
| cpu_devices = [d for d in devices if getattr(d, "ep_name", None) == "CPUExecutionProvider"] | ||
| if not cpu_devices: | ||
| self.skipTest("CPUExecutionProvider not available in this build") | ||
| selected = [cpu_devices[0]] | ||
|
|
||
| # API requires all devices belong to the same EP; we pass only one. | ||
| status = get_model_compatibility_for_ep_devices(selected, "arbitrary-compat-string") | ||
| self.assertEqual(status, OrtCompiledModelCompatibility.EP_NOT_APPLICABLE) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.