Reject duplicate model-local functions (#32750)
This pull request improves the handling of model-local function
identifiers in ONNX Runtime by enforcing uniqueness and adding tests to
verify the new behavior. The main changes include detecting and
rejecting duplicate function identifiers during model loading and
construction, and adding unit tests to ensure this enforcement works as
intended.
**Function Identifier Uniqueness Enforcement:**
- Added checks in `Model::Model(const std::string& graph_name, ...)` and
`Model::Model(ModelProto&& model_proto, ...)` (in
`onnxruntime/core/graph/model.cc`) to detect duplicate model-local
function identifiers and throw an error if duplicates are found. This
prevents ambiguous function resolution and potential runtime errors.
[[1]](diffhunk://#diff-27dfc51b4b723d56e08b54409b60a5d7a689f3908c2208385449435ad3db9641R142-R148)
[[2]](diffhunk://#diff-27dfc51b4b723d56e08b54409b60a5d7a689f3908c2208385449435ad3db9641L280-R285)
**Testing and Validation:**
- Introduced a helper function `MakeIdentityFunction` and two new unit
tests in `onnxruntime/test/framework/function_test.cc`:
- `RejectDuplicateFunctionIdentifiersFromModelProto` verifies that
loading a model with duplicate function identifiers fails as expected.
- `RejectDuplicateFunctionIdentifiersFromFunctionVector` checks that
constructing a model from a vector of functions with duplicate
identifiers throws an exception.
These changes ensure that models with ambiguous function definitions are
caught early, improving reliability and maintainability.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>