Repository: pytorch
Issue: Misleading Error Message from nn.RNN when Passing Incorrect Data Type
Labels: module: rnn,triaged

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->
When using `nn.RNN`, I forgot to cast my output (from `nn.functional.one_hot`) to a float before passing into the RNN. However, I was prompted with the error message `RuntimeError: expected scalar type Long but found Float`, but I *did* passed in a long.

## To Reproduce

Steps to reproduce the behavior:

1. Execute the following script and it should produce the error message below.
```py
from torch.nn import RNN
from torch import rand
model = RNN(128,64,batch_first=True)
model(rand(32, 192, 128).long())
```
<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
```
RuntimeError                              Traceback (most recent call last)
<ipython-input-27-2b9757299ee1> in <module>
      2 from torch import rand
      3 model = RNN(128,64,batch_first=True)
----> 4 model(rand(32, 192, 128).long())

~/.conda/envs/torch/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1100         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1101                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102             return forward_call(*input, **kwargs)
   1103         # Do not call functions when jit is used
   1104         full_backward_hooks, non_full_backward_hooks = [], []

~/.conda/envs/torch/lib/python3.9/site-packages/torch/nn/modules/rnn.py in forward(self, input, hx)
    266         _impl = _rnn_impls[self.mode]
    267         if batch_sizes is None:
--> 268             result = _impl(input, hx, self._flat_weights, self.bias, self.num_layers,
    269                            self.dropout, self.training, self.bidirectional, self.batch_first)
    270         else:

RuntimeError: expected scalar type Long but found Float
```
2. To confirm it isn't caused by something else, executing the following script produces no errors.
```py
from torch.nn import RNN
from torch import rand
model = RNN(128,64,batch_first=True)
model(rand(32, 192, 128).float())
```

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->
The error message should say something like `expected scalar type Float but found Long`, as that is what actually caused the error.

## Environment

Collecting environment information...
PyTorch version: 1.10.0
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: 10.0.0-4ubuntu1 
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.9.7 (default, Sep 16 2021, 13:09:58)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.11.0-40-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 11.2.152
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3080 Ti
Nvidia driver version: 470.82.00
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.20.3
[pip3] torch==1.10.0
[pip3] torchaudio==0.10.0
[pip3] torchtext==0.11.0
[pip3] torchvision==0.11.1
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] mkl                       2021.3.0           h06a4308_520  
[conda] mkl-service               2.4.0            py39h7f8727e_0  
[conda] mkl_fft                   1.3.0            py39h42c9631_2  
[conda] mkl_random                1.2.2            py39h51133e4_0  
[conda] numpy                     1.20.3           py39hf144106_0  
[conda] numpy-base                1.20.3           py39h74d4b33_0  
[conda] pytorch                   1.10.0          py3.9_cuda11.3_cudnn8.2.0_0    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                0.10.0               py39_cu113    pytorch
[conda] torchtext                 0.11.0                   pypi_0    pypi
[conda] torchvision               0.11.1               py39_cu113    pytorch


cc @zou3519