Repository: pytorch
Issue: Casting real parameter to complex during forward produces warning on backward
Labels: module: autograd,triaged,module: complex,complex_autograd

## 🐛 Bug

If I have a `Parameter` with `real` `dtype` but need to cast it as `complex` in the forward pass (in order to have variable types matching), then I get a `UserWarning`  during the backward:

```
/home/luc/anaconda3/envs/ckm/lib/python3.7/site-packages/torch/autograd/__init__.py:156: UserWarning: Casting complex values to real discards the imaginary part (Triggered internally at  /opt/conda/conda-bld/pytorch_1634272092750/work/aten/src/ATen/native/Copy.cpp:244.)
  allow_unreachable=True, accumulate_grad=True)  # allow_unreachable flag
```


## To Reproduce

```
import torch

def loss(x, w, alpha):
    b = torch.tensor([1 + 1.j], dtype=torch.complex64)
    return (torch.linalg.norm(torch.exp(1.j * torch.tensor([x @ w]) @ alpha) - b)).pow(2)

def main():
    x = torch.nn.Parameter(torch.randn((1,), dtype=torch.float), requires_grad=True)
    alpha = torch.nn.Parameter(torch.tensor([1], dtype=torch.float), requires_grad=True)
    w = torch.tensor([1], requires_grad=False, dtype=torch.float)

    optim = torch.optim.Adam([x], lr=0.1)
    for i in range(1000):
        optim.zero_grad()
        loss_res = loss(x, w, alpha.to(torch.complex64))
        loss_res.backward()
        optim.step()

main()
```

## Expected behavior

I am not sure if the warning should be disabled by default because I can see when there could actually be a mistake and the warning would be desirable. But I think there should be a way to prevent the  warning from occuring as this is the desired behavior.

## Environment

```
Collecting environment information...
PyTorch version: 1.10.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.2 LTS (beaver-osp1-gilly X33) (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.17

Python version: 3.7.10 (default, Jun  4 2021, 14:48:32)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-89-generic-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.21.1
[pip3] torch==1.10.0
[pip3] torchaudio==0.10.0
[pip3] torchvision==0.11.1
[conda] blas                      1.0                         mkl  
[conda] cpuonly                   2.0                           0    pytorch
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.2.0           h06a4308_296  
[conda] mkl-service               2.3.0            py37h27cfd23_1  
[conda] mkl_fft                   1.3.0            py37h42c9631_2  
[conda] mkl_random                1.2.1            py37ha9443f7_2  
[conda] numpy                     1.21.1                   pypi_0    pypi
[conda] numpy-base                1.20.1           py37h7d8b39e_0  
[conda] pytorch                   1.10.0              py3.7_cpu_0    pytorch
[conda] pytorch-mutex             1.0                         cpu    pytorch
[conda] torchaudio                0.10.0                 py37_cpu  [cpuonly]  pytorch
[conda] torchvision               0.11.1                 py37_cpu  [cpuonly]  pytorch
```



cc @ezyang @albanD @zou3519 @gqchen @pearu @nikitaved @soulitzer @Lezcano @Varal7 @anjali411 @dylanbespalko @mruberry