Skip to content

Commit

Permalink
[fx] Do not add Proxy on Tensor (pytorch#133470)
Browse files Browse the repository at this point in the history
Summary: Switch to set_proxy_slot instead of set the proxy directly on the Tensor. We do not want to add Proxy to tensor objects, because Proxy cannot be deepcopied or pickeled and can cause problems when users want to deepcopy or pickle models.

Test Plan: CI

Differential Revision: D61277650

Pull Request resolved: pytorch#133470
Approved by: https://github.com/zou3519
  • Loading branch information
yushangdi authored and pytorchmergebot committed Aug 16, 2024
1 parent 8a5708b commit d9f17cf
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions torch/fx/experimental/proxy_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,23 +886,6 @@ def can_handle_tensor(x: Tensor) -> bool:
name=proxy_mode.tracer.graph._target_to_str(func.overloadpacket.__name__),
)

# This makes DCE marginally less likely to DCE inplace operations.
# It is not strictly necessary
# Kind of a hacky way to test if an op is in-place or not
if (
func.overloadpacket.__name__[-1] == "_"
and func.overloadpacket.__name__[0] != "_"
):
if isinstance(args[0], List):
# e.g., c10d::allreduce_ returns a list of tensors as the first element
# in the output.
for i, a in enumerate(args[0]):
a.proxy = proxy_out[0][i]
else:
assert isinstance(args[0], Tensor), type(args[0])
# Adding an undefined attribute to Tensor?
args[0].proxy = proxy_out # type: ignore[attr-defined]

with _enable_thunkify(proxy_mode.tracer):
out = func(*args, **kwargs)

Expand Down

0 comments on commit d9f17cf

Please sign in to comment.