pytorch icon indicating copy to clipboard operation
pytorch copied to clipboard

Fix bugs about torch.fx.experimental.proxy_tensor.make_fx

Open fffrog opened this issue 1 year ago • 4 comments

Stack from ghstack (oldest at bottom):

  • -> #141022

Detailed description:

The codes below will raise an error

import torch
from torch.fx.experimental.proxy_tensor import make_fx

def func(a):
    b = a + 1
    c = b.view(-1)
    c.add_(1)
    return b

input = torch.randn(2)
out = make_fx(func)(input)

The error info are like below:

...
  File "/root/Git.d/pytorch/pytorch/torch/_dynamo/codegen.py", line 34, in <module>
    from .variables.torch_function import TensorWithTFOverrideVariable
  File "/root/Git.d/pytorch/pytorch/torch/_dynamo/variables/torch_function.py", line 185, in <module>
    populate_builtin_to_tensor_fn_map()
  File "/root/Git.d/pytorch/pytorch/torch/_dynamo/variables/torch_function.py", line 146, in populate_builtin_to_tensor_fn_map
    inp0 = torch.ones(1)
  File "/root/Git.d/pytorch/pytorch/torch/fx/experimental/proxy_tensor.py", line 1240, in __torch_function__
    return func(*args, **kwargs)
  File "/root/Git.d/pytorch/pytorch/torch/utils/_stats.py", line 21, in wrapper
    return fn(*args, **kwargs)
  File "/root/Git.d/pytorch/pytorch/torch/fx/experimental/proxy_tensor.py", line 1342, in __torch_dispatch__
    return proxy_call(self, func, self.pre_dispatch, args, kwargs)
  File "/root/Git.d/pytorch/pytorch/torch/fx/experimental/proxy_tensor.py", line 907, in proxy_call
    name=proxy_mode.tracer.graph._target_to_str(func.overloadpacket.__name__),
AttributeError: 'PythonKeyTracer' object has no attribute 'graph'
...

Solutions: Import torch._dynamo before dispatch_trace is called to avoid the context set before dispatch_trace from affecting the torch._dynamo import.

cc @ezyang @SherlockNoMad @EikanWang @jgong5 @wenzhe-nrv

fffrog avatar Nov 19 '24 14:11 fffrog

:link: Helpful Links

:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/141022

Note: Links to docs will display an error until the docs builds have been completed.

:heavy_exclamation_mark: 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

:white_check_mark: No Failures

As of commit 1e62e3d2caff1a7abd03feae49b8ba1fe0cdfb56 with merge base 93aef684d9c95e6f39dff98d2cccb2056b52e3c6 (image): :green_heart: Looks good so far! There are no failures yet. :green_heart:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

pytorch-bot[bot] avatar Nov 19 '24 14:11 pytorch-bot[bot]

@pytorchbot label "topic: not user facing"

fffrog avatar Nov 19 '24 14:11 fffrog

@pytorchbot merge

ezyang avatar Nov 20 '24 00:11 ezyang

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging Check the merge workflow status here

pytorchmergebot avatar Nov 20 '24 00:11 pytorchmergebot

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command For more information see pytorch-bot wiki.

pytorchmergebot avatar Nov 20 '24 06:11 pytorchmergebot

@pytorchbot merge

fffrog avatar Nov 20 '24 08:11 fffrog

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging Check the merge workflow status here

pytorchmergebot avatar Nov 20 '24 08:11 pytorchmergebot