Implement Name Based partitioning and update documents (#28903)
This pull request introduces a new "name-based layer assignment" feature
for ONNX Runtime, allowing device assignment of model nodes based on
substring matching of node names, as an alternative to annotation-based
matching. The implementation ensures that name-based and
annotation-based assignment modes are mutually exclusive, and updates
documentation, configuration keys, and core logic to support this new
capability.
**Key changes:**
#### Name-based Layer Assignment Feature
- Added support for a new session option,
`session.name_based_layer_assignment`, which enables device assignment
using substring matching against node names (rather than metadata
annotations). The longest matching pattern wins, and all patterns are
treated as substrings (the `=` exact-match qualifier is disallowed in
this mode).
[[1]](diffhunk://#diff-10b3051b9e36eccfc7ca0f2d44ce78a9980ca573cde0f931ffd1456da2c681daR181-R218)
[[2]](diffhunk://#diff-62d211e77c575a2fec6492c9fbfe25743fac9d6d72be7c007e7f6eb8dbecc7e7R423-R437)
- Implemented the `SubstringMatcher` class and integrated it into the
`LayeringIndex` logic, enabling efficient substring-based rule matching
for node assignment. The matcher sorts patterns by length and returns
the first (longest) match.
[[1]](diffhunk://#diff-a8f614056d63b5b3325eea1d855afc96550c977c16d8fdba641012a79194b7b5R604-R627)
[[2]](diffhunk://#diff-b64b395fbb0afa67dcf493f97493f3df353486c3c8344df89f25df057ca3840fR88-R116)
#### Mutual Exclusivity and API Changes
- Enforced mutual exclusivity between annotation-based
(`session.layer_assignment_settings`) and name-based
(`session.name_based_layer_assignment`) assignment options. Attempting
to set both now results in an error, with clear messaging.
[[1]](diffhunk://#diff-a8f614056d63b5b3325eea1d855afc96550c977c16d8fdba641012a79194b7b5L338-L359)
[[2]](diffhunk://#diff-b64b395fbb0afa67dcf493f97493f3df353486c3c8344df89f25df057ca3840fR159-R177)
- Updated the `LayeringIndex::Create` API and related logic to accept
both configuration strings, select the active mode, and construct the
appropriate matcher.
[[1]](diffhunk://#diff-a8f614056d63b5b3325eea1d855afc96550c977c16d8fdba641012a79194b7b5L338-L359)
[[2]](diffhunk://#diff-b64b395fbb0afa67dcf493f97493f3df353486c3c8344df89f25df057ca3840fR186)
#### Documentation Updates
- Expanded the documentation to describe the new name-based assignment
feature, provide usage examples, highlight best practices for pattern
writing, and explain the mutual exclusivity and lack of subgraph
inheritance in name-based mode.
[[1]](diffhunk://#diff-10b3051b9e36eccfc7ca0f2d44ce78a9980ca573cde0f931ffd1456da2c681daR181-R218)
[[2]](diffhunk://#diff-10b3051b9e36eccfc7ca0f2d44ce78a9980ca573cde0f931ffd1456da2c681daL295-R357)
#### Core Logic and Maintenance
- Refactored the `LayeringIndex` and related methods to support both
matching modes, updating node assignment and update logic to branch
appropriately based on the selected mode.
[[1]](diffhunk://#diff-a8f614056d63b5b3325eea1d855afc96550c977c16d8fdba641012a79194b7b5L426-R485)
[[2]](diffhunk://#diff-a8f614056d63b5b3325eea1d855afc96550c977c16d8fdba641012a79194b7b5R537-R548)
- Added and documented the new configuration key
`kOrtSessionOptionsNameBasedLayerAssignment` in the public API headers.
These changes provide a more flexible and user-friendly way to partition
models across devices, especially for models with structured node names
but lacking explicit annotations.