Commit d8f0318
Add API to get ep graph partitioning info (#26781)
### Description
- Adds API functions to get information about the subgraphs/nodes
assigned to the EPs in the session.
- `Session_GetEpGraphAssignmentInfo`: Returns a list of "subgraphs",
each with information about the assigned EP and nodes.
- Note: App must enable session configuration
`"session.record_ep_graph_assignment_info"` to signal ORT to collect
this information. If not enabled, API returns empty results.
- `EpAssignedSubgraph_GetEpName`: Returns the name of the EP to which
the subgraph is assigned
- `EpAssignedSubgraph_GetNodes`: Returns a list of assigned nodes
- `EpAssignedNode_GetName`: Returns the assigned node's name
- `EpAssignedNode_GetDomain`: Returns the assigned node's domain
- `EpAssignedNode_GetOperatorType`: Returns the assigned node's operator
type
- Also adds C++ and Python bindings
#### Structure of returned information
The API returns a list of "subgraphs". Each subgraph has the following
information:
- Subgraph info:
- EP name: The name of the execution provider to which this subgraph is
assigned.
- nodes: Name and operator type of each node. Ex: `[{"multiply", "Mul"},
...]`
Python example program (taken from unit tests):
```python
def test_get_graph_provider_assignment_info(self):
"""
Tests querying for information about the nodes assigned to the CPU EP.
"""
# Create session options that enables recording EP graph partitioning info.
session_options = onnxrt.SessionOptions()
session_options.add_session_config_entry("session.record_ep_graph_assignment_info", "1")
session = onnxrt.InferenceSession(get_name("add_mul_add.onnx"), sess_options=session_options)
# Query session for information on each subgraph assigned to an EP.
ep_subgraphs = session.get_provider_graph_assignment_info()
# Check that all 3 nodes are assigned to CPU EP (each in its own subgraph)
self.assertEqual(len(ep_subgraphs), 3)
for ep_subgraph in ep_subgraphs:
self.assertEqual(ep_subgraph.ep_name, "CPUExecutionProvider")
self.assertEqual(len(ep_subgraph.get_nodes()), 1)
# Serialize each node to an identifier (concatenates operator type and node name)
node_ids: list[str] = [f"{n.op_type}/{n.name}" for s in ep_subgraphs for n in s.get_nodes()]
# Should have 1 Mul and 2 Adds.
self.assertEqual(len(node_ids), 3)
self.assertIn("Add/add_0", node_ids)
self.assertIn("Add/add_1", node_ids)
self.assertIn("Mul/mul_0", node_ids)
```
C++ program (taken from unit test):
```c++
// Check the ep graph partitioning (Mul on plugin EP, others on CPU EP).
// Model has 3 subgraphs (in no particular order):
// - Subgraph 1: Add assigned to CPU EP.
// - Subgraph 2: Mul assigned to plugin EP.
// - Subgraph 3: Add assigned to CPU EP.
std::vector<Ort::ConstEpAssignedSubgraph> ep_subgraphs = session.GetEpGraphAssignmentInfo();
ASSERT_EQ(ep_subgraphs.size(), 3);
for (Ort::ConstEpAssignedSubgraph ep_subgraph : ep_subgraphs) {
std::string ep_name = ep_subgraph.EpName();
ASSERT_TRUE(ep_name == Utils::example_ep_info.ep_name || ep_name == kCpuExecutionProvider);
const std::vector<Ort::ConstEpAssignedNode> ep_nodes = ep_subgraph.GetNodes();
ASSERT_GE(ep_nodes.size(), 1); // All of these subgraphs just have one node.
if (ep_name == kCpuExecutionProvider) {
std::string op_type = ep_nodes[0].OpType();
std::string node_name = ep_nodes[0].Name();
ASSERT_EQ(op_type, "Add");
ASSERT_TRUE(node_name == "add_0" || node_name == "add_1");
} else {
ASSERT_TRUE(ep_name == Utils::example_ep_info.ep_name);
std::string op_type = ep_nodes[0].OpType();
std::string node_name = ep_nodes[0].Name();
ASSERT_EQ(op_type, "Mul");
ASSERT_EQ(node_name, "mul_0");
}
}
```
### 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: Copilot <175728472+Copilot@users.noreply.github.com>1 parent bbd3850 commit d8f0318
File tree
17 files changed
+687
-7
lines changed- include/onnxruntime/core/session
- onnxruntime
- core
- framework
- session
- python
- test
- autoep
- python
17 files changed
+687
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
340 | 342 | | |
341 | 343 | | |
342 | 344 | | |
| |||
7016 | 7018 | | |
7017 | 7019 | | |
7018 | 7020 | | |
| 7021 | + | |
| 7022 | + | |
| 7023 | + | |
| 7024 | + | |
| 7025 | + | |
| 7026 | + | |
| 7027 | + | |
| 7028 | + | |
| 7029 | + | |
| 7030 | + | |
| 7031 | + | |
| 7032 | + | |
| 7033 | + | |
| 7034 | + | |
| 7035 | + | |
| 7036 | + | |
| 7037 | + | |
| 7038 | + | |
| 7039 | + | |
| 7040 | + | |
| 7041 | + | |
| 7042 | + | |
| 7043 | + | |
| 7044 | + | |
| 7045 | + | |
| 7046 | + | |
| 7047 | + | |
| 7048 | + | |
| 7049 | + | |
| 7050 | + | |
| 7051 | + | |
| 7052 | + | |
| 7053 | + | |
| 7054 | + | |
| 7055 | + | |
| 7056 | + | |
| 7057 | + | |
| 7058 | + | |
| 7059 | + | |
| 7060 | + | |
| 7061 | + | |
| 7062 | + | |
| 7063 | + | |
| 7064 | + | |
| 7065 | + | |
| 7066 | + | |
| 7067 | + | |
| 7068 | + | |
| 7069 | + | |
| 7070 | + | |
| 7071 | + | |
| 7072 | + | |
| 7073 | + | |
| 7074 | + | |
| 7075 | + | |
| 7076 | + | |
| 7077 | + | |
| 7078 | + | |
| 7079 | + | |
| 7080 | + | |
| 7081 | + | |
| 7082 | + | |
| 7083 | + | |
| 7084 | + | |
| 7085 | + | |
| 7086 | + | |
| 7087 | + | |
| 7088 | + | |
| 7089 | + | |
| 7090 | + | |
| 7091 | + | |
| 7092 | + | |
| 7093 | + | |
| 7094 | + | |
| 7095 | + | |
| 7096 | + | |
| 7097 | + | |
| 7098 | + | |
| 7099 | + | |
| 7100 | + | |
| 7101 | + | |
| 7102 | + | |
| 7103 | + | |
| 7104 | + | |
| 7105 | + | |
| 7106 | + | |
| 7107 | + | |
| 7108 | + | |
| 7109 | + | |
| 7110 | + | |
| 7111 | + | |
| 7112 | + | |
| 7113 | + | |
| 7114 | + | |
| 7115 | + | |
7019 | 7116 | | |
7020 | 7117 | | |
7021 | 7118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1164 | 1164 | | |
1165 | 1165 | | |
1166 | 1166 | | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
1167 | 1200 | | |
1168 | 1201 | | |
1169 | 1202 | | |
| |||
1665 | 1698 | | |
1666 | 1699 | | |
1667 | 1700 | | |
1668 | | - | |
1669 | 1701 | | |
1670 | 1702 | | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
1671 | 1709 | | |
1672 | 1710 | | |
1673 | 1711 | | |
| |||
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
750 | 805 | | |
751 | 806 | | |
752 | 807 | | |
| |||
1756 | 1811 | | |
1757 | 1812 | | |
1758 | 1813 | | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
1759 | 1831 | | |
1760 | 1832 | | |
1761 | 1833 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
426 | 427 | | |
427 | 428 | | |
428 | 429 | | |
| 430 | + | |
429 | 431 | | |
430 | 432 | | |
431 | 433 | | |
| |||
444 | 446 | | |
445 | 447 | | |
446 | 448 | | |
| 449 | + | |
447 | 450 | | |
448 | 451 | | |
449 | 452 | | |
| |||
518 | 521 | | |
519 | 522 | | |
520 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
521 | 530 | | |
522 | 531 | | |
523 | 532 | | |
| |||
1018 | 1027 | | |
1019 | 1028 | | |
1020 | 1029 | | |
| 1030 | + | |
1021 | 1031 | | |
1022 | 1032 | | |
1023 | 1033 | | |
| |||
1034 | 1044 | | |
1035 | 1045 | | |
1036 | 1046 | | |
| 1047 | + | |
1037 | 1048 | | |
1038 | 1049 | | |
1039 | 1050 | | |
| |||
1280 | 1291 | | |
1281 | 1292 | | |
1282 | 1293 | | |
1283 | | - | |
| 1294 | + | |
| 1295 | + | |
1284 | 1296 | | |
1285 | 1297 | | |
1286 | 1298 | | |
| |||
1290 | 1302 | | |
1291 | 1303 | | |
1292 | 1304 | | |
| 1305 | + | |
1293 | 1306 | | |
1294 | 1307 | | |
1295 | 1308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| |||
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
43 | | - | |
| 49 | + | |
| 50 | + | |
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
47 | | - | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
| |||
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
0 commit comments