pytorch
186192bb - [Dynamo] Fix bugs when calling tensor.data and tensor.layout (#89257)

Commit
2 years ago
[Dynamo] Fix bugs when calling tensor.data and tensor.layout (#89257) Fix bugs in [7k github models](https://github.com/pytorch/torchdynamo/issues/1884). * Legacy code still use ```tensor.data```, I think we can use ```tensor.detach``` to rewrite, not sure if there is anything I didn't anticipate. * Support ```tensor.layout```. The root cause of these issues are: dynamo wraps unimplemented ```tensor.x``` call into ```GetAttrVariable(TensorVariable, x)```, but this op was not inserted into FX graph. Hence, during the fake tensor propagation, it throws ```KeyError: 'example_value` ```. For these two popular attributes, Dynamo should support them anyway. However, if dynamo should support ___all___ ```tensor.x``` call and not fallback to ```GetAttrVariable```, I think it's debatable. If I turn off fake tensor propagation, it works well even not including this fix. So I'm curious if we should improve the fake propagation to cover similar cases. cc @mlazos @soumith @voznesenskym @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @chunyuan-w @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire @jansel @eellison ``` Traceback (most recent call last): File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/convert_frame.py", line 404, in _compile out_code = transform_code_object(code, transform) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/bytecode_transformation.py", line 341, in transform_code_object transformations(instructions, code_options) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/convert_frame.py", line 392, in transform tracer.run() File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 1523, in run super().run() File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 389, in run and self.step() File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 359, in step getattr(self, inst.opname)(inst) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 193, in wrapper return inner_fn(self, inst) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 865, in CALL_FUNCTION_KW self.call_function(fn, args, kwargs) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/symbolic_convert.py", line 301, in call_function self.push(fn.call_function(self, args, kwargs)) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/variables/torch.py", line 407, in call_function tensor_variable = wrap_fx_proxy( File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/variables/builder.py", line 636, in wrap_fx_proxy return wrap_fx_proxy_cls( File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/variables/builder.py", line 676, in wrap_fx_proxy_cls example_value = get_fake_value(proxy.node, tx) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/utils.py", line 1024, in get_fake_value args, kwargs = torch.fx.node.map_arg((node.args, node.kwargs), visit) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 613, in map_arg return map_aggregate(a, lambda x: fn(x) if isinstance(x, Node) else x) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 621, in map_aggregate t = tuple(map_aggregate(elem, fn) for elem in a) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 621, in <genexpr> t = tuple(map_aggregate(elem, fn) for elem in a) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 627, in map_aggregate return immutable_dict((k, map_aggregate(v, fn)) for k, v in a.items()) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 627, in <genexpr> return immutable_dict((k, map_aggregate(v, fn)) for k, v in a.items()) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 631, in map_aggregate return fn(a) File "/scratch/ybliang/work/repos/pytorch/torch/fx/node.py", line 613, in <lambda> return map_aggregate(a, lambda x: fn(x) if isinstance(x, Node) else x) File "/scratch/ybliang/work/repos/pytorch/torch/_dynamo/utils.py", line 1022, in visit return n.meta["example_value"] KeyError: 'example_value\n\nfrom user code:\n File "./generated/test_BayesWatch_pytorch_prunes.py", line 108, in forward\n return torch.zeros([x.size()[0], self.channels, x.size()[2] // self.spatial, x.size()[3] // self.spatial], dtype=x.dtype, layout=x.layout, device=x.device)\n\nSet torch._dynamo.config.verbose=True for more information\n\n\nYou can suppress this exception and fall back to eager by setting:\n torch._dynamo.config.suppress_errors = True\n' ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/89257 Approved by: https://github.com/jansel
Author
Committer
Parents
Loading