fix: normalize cache key dtype to prevent initializer name collisions#2888
Merged
gramalingam merged 2 commits intomainfrom Apr 14, 2026
Merged
fix: normalize cache key dtype to prevent initializer name collisions#2888gramalingam merged 2 commits intomainfrom
gramalingam merged 2 commits intomainfrom
Conversation
When a Python int literal (e.g. `1`) is used in both untyped positions (like a Gather index, where the ONNX schema type variable is unbound) and typed positions (like Add with an INT64 tensor), the constant cache created two entries: (1, None) and (1, INT64). Both generated the same initializer name 'const_1_i64' but as different ir.Value objects, causing register_initializer to raise ValueError. Fix: before cache lookup, normalize dtype=None to the default ONNX dtype for the Python type (_PYTHON_TYPE_TO_DTYPE: int->INT64, float->FLOAT). This merges both entries into a single cache key and reuses the same ir.Value. Applied to both scalar and sequence (list/tuple) branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: G Ramalingam <grama@microsoft.com>
justinchuby
approved these changes
Apr 14, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2888 +/- ##
==========================================
+ Coverage 72.24% 72.30% +0.05%
==========================================
Files 241 241
Lines 29650 29678 +28
Branches 2914 2916 +2
==========================================
+ Hits 21421 21459 +38
+ Misses 7235 7227 -8
+ Partials 994 992 -2 ☔ View full report in Codecov by Sentry. |
Signed-off-by: G Ramalingam <grama@microsoft.com>
justinchuby
approved these changes
Apr 14, 2026
justinchuby
pushed a commit
that referenced
this pull request
Apr 17, 2026
…#2888) When a Python int literal (e.g. `1`) is used in both untyped positions (like a Gather index, where the ONNX schema type variable is unbound) and typed positions (like Add with an INT64 tensor), the constant cache created two entries: (1, None) and (1, INT64). Both generated the same initializer name 'const_1_i64' but as different ir.Value objects, causing register_initializer to raise ValueError. Fix: before cache lookup, normalize dtype=None to the default ONNX dtype for the Python type (_PYTHON_TYPE_TO_DTYPE: int->INT64, float->FLOAT). This merges both entries into a single cache key and reuses the same ir.Value. Applied to both scalar and sequence (list/tuple) branches. --------- Signed-off-by: G Ramalingam <grama@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
When a Python int literal (e.g.
1) is used in both untyped positions (like a Gather index, where the ONNX schema type variable is unbound) and typed positions (like Add with an INT64 tensor), the constant cache created two entries: (1, None) and (1, INT64). Both generated the same initializer name 'const_1_i64' but as different ir.Value objects, causing register_initializer to raise ValueError.Fix: before cache lookup, normalize dtype=None to the default ONNX dtype for the Python type (_PYTHON_TYPE_TO_DTYPE: int->INT64, float->FLOAT). This merges both entries into a single cache key and reuses the same ir.Value. Applied to both scalar and sequence (list/tuple) branches.