Repository: pytorch
Issue: [FX] [BUG] Tensor.{inplace_method}_(.) is eliminated as dead code
Labels: triaged,module: fx

## To Reproduce

Steps to reproduce the behavior:

```python
import torch
from torch import fx


class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.a = torch.nn.Parameter(torch.tensor(0.))

    def forward(self, x):
        x.mul_(self.a)
        return x


model = Model()
print(model(torch.tensor(1).float()))

tracer = fx.Tracer()
graph = tracer.trace(model)
graph.eliminate_dead_code()

fx_model = fx.GraphModule(model, graph)

print(fx_model(torch.tensor(1).float()))

```

I would expect the two `print` outputs to be the same but what I get is

```
tensor(0., grad_fn=<MulBackward0>)
tensor(1.)
```

Using `mul` instead of `mul_` makes the example work as expected. And I've also confirmed a different variation for `add` vs `add_`.

If I pull the `mul_` out into a separate function the problem disappears:

```python
import torch
from torch import fx

def func(x, a):
    return x.mul_(a)

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.a = torch.nn.Parameter(torch.tensor(0.))

    def forward(self, x):
        x = func(x, self.a)
        return x


model = Model()
print(model(torch.tensor(1).float()))

tracer = fx.Tracer()
graph = tracer.trace(model)
graph.eliminate_dead_code()

fx_model = fx.GraphModule(model, graph)

print(fx_model(torch.tensor(1).float()))
```
The above prints:

```
tensor(0., grad_fn=<MulBackward0>)
tensor(0., grad_fn=<MulBackward0>)
```

## Real life example

I encountered this with the NormFree nets from timm. See [here](https://github.com/rwightman/pytorch-image-models/blob/65419f60cc389f197ed555e1fc3b7f986708a683/timm/models/nfnet.py#L391).

## Environment

```
PyTorch version: 1.10.0+cu113
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.8.10 (default, Sep 28 2021, 16:10:42)  [GCC 9.3.0] (64-bit runtime)
Python platform: Linux-5.11.0-40-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce RTX 3090
Nvidia driver version: 460.91.03
cuDNN version: Probably one of the following:
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn.so.8
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.0
[pip3] torch==1.10.0+cu113
[pip3] torchvision==0.11.1+cu113
[conda] Could not collect
```


cc @ezyang