Repository: pytorch
Issue: copy.deepcopy not working properly for jit.TopLevelTracedModule
Labels: oncall: jit,days

## 🐛 Bug

When trying to deep-copy jit scripted/traced module, parameters are not copied properly. Instead, they are created with `grad_fn=<CloneBackward>`, mirroring to original parameter tensors. Not sure if it is bug but looks quite strange. On the contrary, deep-copy of say `nn.Linear` module works fine, introducing completely independent modules.

## To Reproduce

```
import torch
from torch.nn import Parameter, Module
import copy


class MyLinear(Module):
    def __init__(self, in_dim, out_dim):
        super().__init__()
        self.wt = Parameter(torch.zeros(out_dim, in_dim))

    def forward(self, x):
        return torch.ops.aten.linear(x, self.wt)

if __name__ == '__main__':
    x = torch.randn(100, 5)
    py_mod = MyLinear(5, 2)
    mod = torch.jit.script(py_mod)
    # mod = torch.jit.trace_module(py_mod, {'forward': (x,)})  # trace_module has same flaw
    mod2 = copy.deepcopy(mod)
    print("MOD1", [p.grad for p in mod.parameters()])
    print("MOD2", [p.grad for p in mod2.parameters()])  # non-leaf node warning
    loss = mod2(x).sum()
    loss.backward()
    print("MOD1", [p.grad for p in mod.parameters()])  # filled gradients here
    print("MOD2", [p.grad for p in mod2.parameters()])
```
## Expected behavior

Since loss is calculated using `mod2`, it is expected that `mod2` will have its parameters as leaves and with filled gradients.
But what I get is the following:
```
MOD1 [None]
MOD2 [None]
traced_mod_copy.py:21: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the gradient for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.
  print("MOD2", [p.grad for p in mod2.parameters()])  # non-leaf node warning
traced_mod_copy.py:25: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the gradient for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.
  print("MOD2", [p.grad for p in mod2.parameters()])
MOD1 [tensor([[-11.4494, -14.2499,  10.3231,  14.4365, -12.1881],
        [-11.4494, -14.2499,  10.3231,  14.4365, -12.1881]])]
MOD2 [None]
```

## Environment

```
PyTorch version: 1.6.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
OS: Microsoft Windows Server 2016 Datacenter
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.16.5
Python version: 3.7 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Versions of relevant libraries:
[pip3] msgpack-numpy==0.4.3
[pip3] numpy==1.18.1
[conda] Could not collect
```


cc @gmagogsfm