Fix aten.copy: wrap CastLike with Identity to prevent IR value aliasing#2875
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>
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. |
|
Actually we should probably fix the castlike evaluation logic to emit an identity also. |
|
@copilot: |
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.