Repository: pytorch
Issue: Conversion error from pytorch model to libtorch model
Labels: oncall: jit,Stale

### 🐛 Describe the bug

When a pytorch model is serialized into a libtorch model by torch.jit.trace(), member variables will be serialized into constants, resulting in all subsequent operations with lvalues as member variables being filtered.

```
class CausalConv1d(nn.Conv1d):
    def __init__(self,
                 in_channels,
                 out_channels,
                 kernel_size,
                 stride=1,
                 dilation=1,
                 groups=1,
                 bias=True):
        super(CausalConv1d, self).__init__(
            in_channels,
            out_channels,
            kernel_size,
            stride=stride,
            padding=0,
            dilation=dilation,
            groups=groups,
            bias=bias)

        self.left_padding = dilation * (kernel_size - 1)
        self.buffer = torch.zeros([1, self.in_channels, self.left_padding])

    def forward(self, input, end_flag):
        x = torch.cat((self.buffer, input), 2)

        self.buffer = x[:, :, input.shape[2]:]    #disappeared
        self.buffer = self.buffer * end_flag[0]   #disappeared

        return super(CausalConv1d, self).forward(x)
```
```
class CausalConv1d(Module):
  __parameters__ = ["bias", "weight_g", "weight_v", ]
  __buffers__ = []
  bias : Tensor
  weight_g : Tensor
  weight_v : Tensor
  training : bool
  _is_full_backward_hook : Optional[bool]
  def forward(self: __torch__.___torch_mangle_0.CausalConv1d,
    argument_1: Tensor,
    end_flag: Tensor,
    weight: Tensor) -> Tensor:
    _0 = self.bias

    # CONSTANTS.c1 is self.buffer, the following 2 operations are disappeared
    x = torch.cat([CONSTANTS.c1, argument_1], 2)

    input = torch._convolution(x, weight, _0, [1], [0], [1], False, [0], 1, False, False, True, True)
    return input
```


As you can see in the code above, I created self.buffer in Class CausalConv1d, then I operated on self.buffer in the forward() function. However the self.buffer variable was serialized into a constant, which i need to use in the following process. Resulting _self.buffer = x[:, :, input.shape[2]:]_ and _self.buffer = self.buffer * end_flag[0]_ disappeared in the target libtorch model.





### Versions

## Environment
Collecting environment information...
PyTorch version: 1.8.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.10.2
Libc version: glibc-2.26

Python version: 3.7.10 (default, Mar 23 2021, 15:34:20)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-3.10.107-1-tlinux2_kvm_guest-0049-x86_64-with-debian-buster-sid
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.20.3
[pip3] torch==1.8.0+cpu
[pip3] torchaudio==0.8.0
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.9.0+cpu
[conda] Could not collect