Fix aten.copy: wrap CastLike with Identity to prevent IR value aliasing#2875
Open
Fix aten.copy: wrap CastLike with Identity to prevent IR value aliasing#2875
Conversation
…sing Agent-Logs-Url: https://github.com/microsoft/onnxscript/sessions/452e0b6d-caee-4be8-8b46-2609a538fa73 Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ValueError on torch.onnx.export for ExportedProgram
Fix aten.copy: wrap CastLike with Identity to prevent IR value aliasing
Mar 31, 2026
justinchuby
approved these changes
Mar 31, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2875 +/- ##
=======================================
Coverage 71.96% 71.96%
=======================================
Files 239 239
Lines 29224 29224
Branches 2878 2878
=======================================
Hits 21031 21031
Misses 7216 7216
Partials 977 977 ☔ View full report in Codecov by Sentry. |
Collaborator
|
Actually we should probably fix the castlike evaluation logic to emit an identity also. |
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.
torch.onnx.exportraisedValueErrorwhen exporting anExportedProgramcontainingregister_buffer+ in-place copy (copy_), becauseaten_copy'sop.CastLike(src, self)returns the same IR value object assrcwhen both tensors share the same dtype — no new ONNX node is created. A subsequent unconditional rename of that value clobbered the original buffer placeholder name (e.g.b_prompt_feat→copy), causing initializer registration to fail.Change
onnxscript/function_libs/torch_lib/ops/core.py: Wrap theCastLikeresult inop.Identity()soaten_copyalways produces a fresh IR value, leaving the source value's name intact.This matches the existing pattern in
aten__to_copy, which already returnsop.Identity(self)for the same-dtype case.