onnxruntime
9ad4d58c - Address github issue 29071 (#29158)

Commit
11 days ago
Address github issue 29071 (#29158) This pull request addresses a regression in ONNX Runtime's graph inlining logic, specifically ensuring that initializers with in-memory external data (OrtValues) are correctly transferred when inlining subgraphs (such as during constant folding of If nodes). It also adds comprehensive regression tests and supporting test data to prevent similar issues in the future. The most important changes are: **Bug Fixes and Core Logic:** * Fixed a bug in `Graph::InlineIfSubgraph` to ensure that OrtValues for initializers with in-memory external data are extracted from the source graph before erasing their entries, and correctly restored in the destination graph after inlining. This maintains the invariant that an initializer marked as "HasExternalDataInMemory" always has a corresponding OrtValue. [[1]](diffhunk://#diff-e231a92b40d89409cc8e82436be0a15bc87ef95c93b303b9feaeab6e50c8835cR6067-R6077) [[2]](diffhunk://#diff-e231a92b40d89409cc8e82436be0a15bc87ef95c93b303b9feaeab6e50c8835cL6085-R6097) **Testing and Regression Coverage:** * Added a regression test `InlineIfSubgraphTransfersOrtValues` to `graph_test.cc` to verify that OrtValues are properly transferred when inlining If subgraphs with large initializers, preventing crashes during model saving. * Added an end-to-end regression test `GH_Issue_29071_HasExternalDataInMemory` to ensure that loading and initializing a model with this pattern works as expected. * Included the necessary import for `graph_utils.h` in the test file to support new test logic. **Test Data:** * Added a Python script (`gh_issue_29071_if_constant_folding.py`) to generate the minimal ONNX model that reproduces the original bug, supporting ongoing regression testing. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Author
Parents
Loading