onnxruntime
0bae67df - [Optimizer] Fix ConstantFolding crash with missing optional outputs (#27620)

Commit
8 days ago
[Optimizer] Fix ConstantFolding crash with missing optional outputs (#27620) ### Description Fix crash in ConstantFolding when nodes have missing optional outputs. ConstantFolding previously iterated over `node->OutputDefs()` and attempted to resolve an OrtValue index for every output. However, some operators (e.g. `Unique`) have optional outputs that may not exist in the graph (`NodeArg::Exists() == false`). `OptimizerExecutionFrame` only registers OrtValues for outputs that actually exist when building the name→index map. When ConstantFolding requested an index for a missing optional output, `GetMLValueIndex()` returned `-1`. This invalid index was inserted into `fetch_mlvalue_idxs` and later caused an assertion in `ExecutionFrame::GetMLValue()` during session initialization. This PR fixes the issue by: * Skipping outputs where `NodeArg::Exists() == false` * Preventing invalid indices from entering `fetch_mlvalue_idxs` * Skipping constant folding for the node if an output index cannot be resolved * Maintaining correct mapping between fetch indices and the original output indices --- ### Motivation and Context The failure is reproducible with the model attached in #26505. Before this fix: * session initialization fails with `ORT_ENABLE_BASIC` * disabling `ConstantFolding` allows the model to load After this fix: * the model loads successfully with `ORT_ENABLE_BASIC` * invalid indices are no longer inserted into `fetch_mlvalue_idxs` Fixes #26505
Author
Parents
Loading