pytorch
6ae06e49 - Inductor: fix incorrect result of inplace unsqueeze (#94797)

Commit
3 years ago
Inductor: fix incorrect result of inplace unsqueeze (#94797) This pr aims to fix the incorrect result in the following test case. ``` @torch._dynamo.optimize("inductor") def fn(a): unsqueeze_ = torch.ops.aten.unsqueeze_.default(a, 0) return unsqueeze_ args = [ ((1, 1, 1, 12, 11, 3), (396, 396, 396, 33, 3, 1), torch.int64, "cpu") ] args = [rand_strided(sh, st, dt, dev) for (sh, st, dt, dev) in args] with torch.no_grad(): out = fn(*args) # expected result: (396, 396, 396, 396, 33, 3, 1) torch.Size([1, 1, 1, 1, 12, 11, 3]) print(args[0].stride(), args[0].shape) # incorrect result: (396, 396, 396, 396, 396, 396, 33, 3, 1) torch.Size([1, 1, 1, 1, 1, 1, 12, 11, 3]) ``` **Root cause** 1. [fake_tensor](https://github.com/pytorch/pytorch/blob/master/torch/_dynamo/variables/builder.py#L140) is changed during [tracer.run](https://github.com/pytorch/pytorch/blob/master/torch/_dynamo/convert_frame.py#L311), then it will [pass incorrect inputs to inductor](https://github.com/pytorch/pytorch/blob/master/torch/_dynamo/output_graph.py#L670). 2. example_inputs are changed during [propagate](https://github.com/pytorch/pytorch/blob/master/torch/_inductor/mkldnn.py#L509) Pull Request resolved: https://github.com/pytorch/pytorch/pull/94797 Approved by: https://github.com/jgong5, https://github.com/jansel
Author
Committer
Parents
Loading