Commit 66c9f1c
authored
Make sure TRT EPs can loads models when initializers in memory (#26721)
This PR moves the conversion of initializers in-memory from Graph
constructor to early in graph transform before the partitioning. This is
done to avoid conversion when subgraphs are constructed.
It also addresses bugs in TRT and NV TRT providers.
Addresses issue: #26653
**Graph Initializer Conversion and Handling:**
* Added a new method `Graph::ConvertInitializersIntoOrtValues()` to
convert all graph TensorProto initializers into OrtValues and create
in-memory external data references, separating this logic from graph
construction and making it reusable.
(`include/onnxruntime/core/graph/graph.h`,
`onnxruntime/core/graph/graph.cc`)
[[1]](diffhunk://#diff-aaea1507ec81a94c72a1fa72ce320df712156b665f7798573be3f7e439bb4c37R1457-R1463)
[[2]](diffhunk://#diff-e231a92b40d89409cc8e82436be0a15bc87ef95c93b303b9feaeab6e50c8835cR3416-R3447)
* Removed the previous lambda for converting large tensor initializers
within the graph constructor, delegating this responsibility to the new
method above for clearer separation of concerns.
(`onnxruntime/core/graph/graph.cc`)
[[1]](diffhunk://#diff-e231a92b40d89409cc8e82436be0a15bc87ef95c93b303b9feaeab6e50c8835cL1234-L1255)
[[2]](diffhunk://#diff-e231a92b40d89409cc8e82436be0a15bc87ef95c93b303b9feaeab6e50c8835cL1275-L1276)
[[3]](diffhunk://#diff-e231a92b40d89409cc8e82436be0a15bc87ef95c93b303b9feaeab6e50c8835cL1353-R1327)
**Provider Interface Enhancements:**
* Introduced move assignment operators for `GraphProto` and
`TensorProto` in both the provider interface (`ProviderHost`) and
wrapper structs, allowing for more efficient object transfers and
assignment.
(`onnxruntime/core/providers/shared_library/provider_interfaces.h`,
`onnxruntime/core/providers/shared_library/provider_wrappedtypes.h`)
[[1]](diffhunk://#diff-d62681d5e83139cfbc272f32afc4ff897dbfd84a709f02a932666e18240fa094L442-R457)
[[2]](diffhunk://#diff-d62681d5e83139cfbc272f32afc4ff897dbfd84a709f02a932666e18240fa094L495-R511)
[[3]](diffhunk://#diff-bf62a34e53927025e7a7bcf7f294532a366ec4ee069bbe541fcdc87e3b1eaa8fL178-R179)
[[4]](diffhunk://#diff-bf62a34e53927025e7a7bcf7f294532a366ec4ee069bbe541fcdc87e3b1eaa8fL244-R248)
* Added iterator interfaces (`TensorProto_ConstIterator`,
`TensorProto_Iterator`) and corresponding methods to `TensorProtos` for
clean iteration over initializer lists, improving code readability and
maintainability.
(`onnxruntime/core/providers/shared_library/provider_interfaces.h`,
`onnxruntime/core/providers/shared_library/provider_wrappedtypes.h`)
[[1]](diffhunk://#diff-d62681d5e83139cfbc272f32afc4ff897dbfd84a709f02a932666e18240fa094L73-R93)
[[2]](diffhunk://#diff-d62681d5e83139cfbc272f32afc4ff897dbfd84a709f02a932666e18240fa094L524-R545)
[[3]](diffhunk://#diff-bf62a34e53927025e7a7bcf7f294532a366ec4ee069bbe541fcdc87e3b1eaa8fL286-R295)
**Execution Provider Logic Simplification:**
* Refactored how initializers are processed in the NVExecutionProvider,
using the new initializer conversion and iteration logic to simplify
handling of external and in-memory data, and ensuring correct assignment
and ownership of user-provided weights.
(`onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.cc`)
[[1]](diffhunk://#diff-b7114b8cae911bdd2c3523a09019f9a9b9f9d7cce4fdd50b282603c81a6137aaL1657-R1658)
[[2]](diffhunk://#diff-b7114b8cae911bdd2c3523a09019f9a9b9f9d7cce4fdd50b282603c81a6137aaR1709-R1733)
[[3]](diffhunk://#diff-b7114b8cae911bdd2c3523a09019f9a9b9f9d7cce4fdd50b282603c81a6137aaR2558-R2587)
**Other Minor Improvements:**
* Improved const-correctness and interface consistency for size and
iterator methods in `TensorProtos`.
(`onnxruntime/core/providers/shared_library/provider_interfaces.h`,
`onnxruntime/core/providers/shared_library/provider_wrappedtypes.h`)
[[1]](diffhunk://#diff-d62681d5e83139cfbc272f32afc4ff897dbfd84a709f02a932666e18240fa094L524-R545)
[[2]](diffhunk://#diff-bf62a34e53927025e7a7bcf7f294532a366ec4ee069bbe541fcdc87e3b1eaa8fL286-R295)1 parent 838cf03 commit 66c9f1c
File tree
10 files changed
+220
-144
lines changed- include/onnxruntime/core/graph
- onnxruntime
- core
- graph
- providers
- nv_tensorrt_rtx
- tensorrt
- session
- test/ir
10 files changed
+220
-144
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1454 | 1454 | | |
1455 | 1455 | | |
1456 | 1456 | | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
1457 | 1464 | | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | | - | |
| 1465 | + | |
| 1466 | + | |
1463 | 1467 | | |
1464 | 1468 | | |
1465 | 1469 | | |
| |||
1633 | 1637 | | |
1634 | 1638 | | |
1635 | 1639 | | |
1636 | | - | |
1637 | | - | |
1638 | | - | |
1639 | | - | |
1640 | | - | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
1644 | | - | |
1645 | | - | |
1646 | | - | |
1647 | 1640 | | |
1648 | 1641 | | |
1649 | 1642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1233 | 1233 | | |
1234 | 1234 | | |
1235 | 1235 | | |
1236 | | - | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | | - | |
1258 | 1236 | | |
1259 | 1237 | | |
1260 | 1238 | | |
| |||
1274 | 1252 | | |
1275 | 1253 | | |
1276 | 1254 | | |
1277 | | - | |
1278 | | - | |
1279 | 1255 | | |
1280 | 1256 | | |
1281 | 1257 | | |
| |||
1352 | 1328 | | |
1353 | 1329 | | |
1354 | 1330 | | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
| 1331 | + | |
1374 | 1332 | | |
1375 | 1333 | | |
1376 | 1334 | | |
| |||
3762 | 3720 | | |
3763 | 3721 | | |
3764 | 3722 | | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
| 3733 | + | |
| 3734 | + | |
| 3735 | + | |
| 3736 | + | |
| 3737 | + | |
| 3738 | + | |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
3765 | 3755 | | |
3766 | 3756 | | |
3767 | 3757 | | |
| |||
Lines changed: 36 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1669 | 1669 | | |
1670 | 1670 | | |
1671 | 1671 | | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
1676 | | - | |
| 1672 | + | |
| 1673 | + | |
1677 | 1674 | | |
1678 | 1675 | | |
1679 | 1676 | | |
| |||
1720 | 1717 | | |
1721 | 1718 | | |
1722 | 1719 | | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
1727 | | - | |
1728 | 1720 | | |
1729 | 1721 | | |
1730 | 1722 | | |
1731 | 1723 | | |
1732 | | - | |
1733 | | - | |
| 1724 | + | |
1734 | 1725 | | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
| 1726 | + | |
1738 | 1727 | | |
1739 | | - | |
1740 | | - | |
1741 | | - | |
1742 | | - | |
1743 | | - | |
1744 | | - | |
1745 | | - | |
1746 | | - | |
| 1728 | + | |
| 1729 | + | |
1747 | 1730 | | |
1748 | | - | |
1749 | | - | |
1750 | | - | |
1751 | | - | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
1752 | 1743 | | |
1753 | 1744 | | |
1754 | 1745 | | |
1755 | 1746 | | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
1756 | 1751 | | |
1757 | | - | |
1758 | 1752 | | |
1759 | 1753 | | |
1760 | 1754 | | |
| |||
2582 | 2576 | | |
2583 | 2577 | | |
2584 | 2578 | | |
2585 | | - | |
2586 | 2579 | | |
2587 | 2580 | | |
2588 | | - | |
2589 | | - | |
2590 | | - | |
| 2581 | + | |
2591 | 2582 | | |
2592 | | - | |
2593 | | - | |
2594 | | - | |
2595 | | - | |
2596 | | - | |
2597 | | - | |
2598 | | - | |
2599 | | - | |
| 2583 | + | |
2600 | 2584 | | |
2601 | | - | |
2602 | | - | |
2603 | | - | |
2604 | | - | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
2605 | 2597 | | |
2606 | 2598 | | |
2607 | 2599 | | |
2608 | | - | |
2609 | 2600 | | |
2610 | 2601 | | |
2611 | 2602 | | |
| |||
Lines changed: 24 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
80 | 94 | | |
81 | 95 | | |
82 | 96 | | |
| |||
439 | 453 | | |
440 | 454 | | |
441 | 455 | | |
442 | | - | |
| 456 | + | |
| 457 | + | |
443 | 458 | | |
444 | 459 | | |
445 | 460 | | |
| |||
492 | 507 | | |
493 | 508 | | |
494 | 509 | | |
495 | | - | |
| 510 | + | |
| 511 | + | |
496 | 512 | | |
497 | 513 | | |
498 | 514 | | |
| |||
521 | 537 | | |
522 | 538 | | |
523 | 539 | | |
524 | | - | |
| 540 | + | |
525 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
526 | 546 | | |
527 | 547 | | |
528 | 548 | | |
| |||
0 commit comments