onnxruntime
b59a9325 - Fix dead dedup guard in GraphTransformerManager::Register (audit F10) (#29556)

Commit
24 days ago
Fix dead dedup guard in GraphTransformerManager::Register (audit F10) (#29556) ### Description `GraphTransformerManager::Register` guarded against duplicate registration with a `std::find` over `level_to_transformer_map_[level]` (a container of `std::unique_ptr<GraphTransformer>`) looking for the `transformer` unique_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. `LayerNormFusion` is registered at both Level1 and Level2 by `GenerateTransformers`), which a global-name check would have wrongly rejected. ### Tests Adds `GraphTransformationTests.RegisterDuplicateTransformerNameFailsPerLevel`: - same name, same level → `FAIL` - same name, different level → `OK` Verified locally: the test **fails on the pre-fix code** (`duplicate_status.IsOK()` was `true`, i.e. the duplicate was wrongly accepted) and **passes with the fix**. The full `GraphTransformationTests` suite 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. --------- Co-authored-by: Gopalakrishnan Nallasamy <gopalakrishnan.nallasamy@microsoft.com>
Parents
Loading