pytorch/torch/export
Pian Pawakapan 90ddb33141 [export] specialize for aten.to (#149235)
Changes decomposition behavior of `aten.to` to respect the aliasing/non-aliasing behavior in eager, and to specialize to the input/conversion dtype & device.

Before change: we always decompose `aten.to` into `_to_copy`, regardless of aliasing behavior. This leads us to ban mutations on the result of `_to_copy` when aliased, since we can't guarantee correct program semantics. This meant users had to explicitly call `.clone()` before mutating. In the special cases where we don’t ban mutations (e.g. dtype conversion), we add runtime assertions on the input & conversion dtype/devices in the decomposed program (see https://github.com/pytorch/pytorch/pull/142420).

After change: we decompose to the aliasing/non-aliasing behavior that matches eager, allowing mutations in all cases. We also add dtype/device assertions for all `aten.to` ops, starting in the pre-dispatch graph, basically specializing the program to the dtype/devices.

Differential Revision: D71229547

Pull Request resolved: https://github.com/pytorch/pytorch/pull/149235
Approved by: https://github.com/tugsbayasgalan
2025-04-03 05:20:10 +00:00
..
experimental PEP585 update - torch/export (#145165) 2025-01-19 20:56:55 +00:00
passes PEP585: More UP006 fixes (#146392) 2025-02-20 06:18:13 +00:00
__init__.py [pytree] Register normal class to register_dataclass (#147752) 2025-04-01 23:28:20 +00:00
_draft_export.py [export] Beef up guard_added logs (#149465) 2025-03-20 23:02:07 +00:00
_remove_auto_functionalized_pass.py remove allow-untyped-defs from torch/export/_remove_auto_functionalized_pass.py (#144230) 2025-01-06 22:23:19 +00:00
_remove_effect_tokens_pass.py Fakify torchbind objects in compile_fx and add tests for SigridTransformsInstanceTorchBind (#149529) 2025-03-21 18:58:28 +00:00
_safeguard.py Flip default value for mypy disallow_untyped_defs [6/11] (#127843) 2024-06-08 18:49:29 +00:00
_swap.py PEP585 update - torch/export (#145165) 2025-01-19 20:56:55 +00:00
_trace.py [export] specialize for aten.to (#149235) 2025-04-03 05:20:10 +00:00
_tree_utils.py PEP585 update - torch/export (#145165) 2025-01-19 20:56:55 +00:00
_unlift.py Suppress more warnings (#149833) 2025-04-01 05:33:04 +00:00
custom_obj.py [Export] Introduce class_fqn into CustomObjArgument (#118158) 2024-01-25 18:44:25 +00:00
custom_ops.py Fix subclass access custom op bug (#149698) 2025-03-21 19:42:56 +00:00
decomp_utils.py Re-land exclude upsample_bilinear2d.vec and nearest2d.vec from default export decomposition table (#147153) 2025-02-19 23:03:29 +00:00
dynamic_shapes.py infer dynamic shapes through additional inputs (#150144) 2025-04-01 21:13:39 +00:00
exported_program.py [export] specialize for aten.to (#149235) 2025-04-03 05:20:10 +00:00
graph_signature.py pretty print graph signature (#149710) 2025-03-21 21:31:58 +00:00
unflatten.py [dynamo] add dynamo disable reasons to codebase (#150440) 2025-04-02 04:26:48 +00:00