Fix dead dedup guard in GraphTransformerManager::Register (audit F10) - #29556
Merged
GopalakrishnanN merged 3 commits intoJul 30, 2026
Merged
Conversation
The std::find compared the incoming unique_ptr against the stored ones, which can never match, so duplicate transformer names were silently accepted and applied twice per level. Use a per-level name check (same name at different levels stays valid). Adds a regression test.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a non-functional duplicate-registration guard in GraphTransformerManager::Register so that duplicate transformer names at the same optimization level are correctly rejected, preventing accidental double-application of the same transformer within a level.
Changes:
- Replace the dead
std::findcheck (unique_ptr identity) with a per-levelName()uniqueness check inGraphTransformerManager::Register. - Add a unit test validating: same name + same level is rejected, while same name + different level is allowed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/core/optimizer/graph_transformer_mgr.cc | Fixes duplicate detection by checking transformer Name() uniqueness per level before inserting. |
| onnxruntime/test/optimizer/graph_transform_test.cc | Adds a regression test covering duplicate-name registration behavior across levels. |
xadupre
reviewed
Jul 7, 2026
Address review feedback that the per-level Name() scan in Register added quadratic cost. Reuse the existing transformers_info_ map (previously populated but unused for dedup) as an O(1) hash index keyed by (level, name), preserving per-level semantics: the same name may still be registered at different levels.
…-transformer-register-dedup
xadupre
approved these changes
Jul 30, 2026
GopalakrishnanN
deleted the
GopalakrishnanN/graph-transformer-register-dedup
branch
July 30, 2026 16:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GraphTransformerManager::Registerguarded against duplicate registration with astd::findoverlevel_to_transformer_map_[level](a container ofstd::unique_ptr<GraphTransformer>) looking for thetransformerunique_ptr about to be inserted. Since that unique_ptr is not yet in the container and owns a distinct pointer, the comparison can never match — the guard is dead code.As a result, a transformer registered with a duplicate name at the same level slips through: it is appended a second time to
level_to_transformer_map_[level]and applied twice per optimization pass, and the intended "already registered" error is never returned.Fix
Replace the dead identity check with a per-level name check backed by an O(1) hash lookup: each transformer's name is recorded in the existing
transformers_info_map keyed by(level, name), so a duplicate at the same level is rejected in constant time instead of scanning the transformers already registered at that level (avoiding the quadratic registration cost). This preserves the original per-level intent — the same transformer name at different levels remains valid (e.g.LayerNormFusionis registered at both Level1 and Level2 byGenerateTransformers), which a global-name check would have wrongly rejected.Tests
Adds
GraphTransformationTests.RegisterDuplicateTransformerNameFailsPerLevel:FAILOKVerified locally: the test fails on the pre-fix code (
duplicate_status.IsOK()wastrue, i.e. the duplicate was wrongly accepted) and passes with the fix. The fullGraphTransformationTestssuite remains green after the O(1) revision — re-verified on a RelWithDebInfo build (350 passed, 15 CUDA/WebGpu skipped, 0 failed), including the layernorm tests that register the same fusion at Level1 and Level2.Motivation and Context
Fixes the design-audit F10 finding — a non-functional safeguard that silently allowed duplicate transformer registration and double-application.