Repository: pytorch
Issue: [Feature request] Intuitive error message when input to Linear is not cudarized
Labels: module: error checking,triaged

If you have a question or would like help and support, please ask at our
[forums](https://discuss.pytorch.org/).

If you are submitting a feature request, please preface the title with [feature request].
If you are submitting a bug report, please fill in the following details.

## Issue description

I run a program. The result is:

```
  File "/toknas/hugh/condap4/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 55, in forward
    return F.linear(input, self.weight, self.bias)
  File "/toknas/hugh/condap4/lib/python3.6/site-packages/torch/nn/functional.py", line 1024, in linear
    return torch.addmm(bias, input, weight.t())
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 'mat1'
```

From inspection, I guess that argument 4 is probably argument 3, in `torch.addmm(bias, input, weight.t())`, and that there is some hidden 1st argument, which is why it's not 'argument 3'.

Thus I deduce that the problem is that the Linear's `weight` has not been converted to cuda, and thus that the `Linear` itself hasnt been converted to `cuda`. I spend ...  a while .. trying to figure out why.

In fact, I'm totally wrong. It's the input that is not cuda...

I reckon the error message is not very clear. I'm not sure how to fix pytorch to give a clearer message, but I reckon it would be clearer if the pytorch message said something like 'mismatch between Linear(is_cuda=True) and input tensor (is_cuda=False)'.  How to achieve this is not clear to me. I'm just reporting this preference :)

## Code example

```
import torch
from torch import nn

h = nn.Linear(2, 3)
h = h.cuda()
i = torch.rand(1, 2)
h(i)
```

output:
```
Traceback (most recent call last):
  File "tmp_prog/test.py", line 7, in <module>
    h(i)
  File "/toknas/hugh/condap4/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/toknas/hugh/condap4/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 55, in forward
    return F.linear(input, self.weight, self.bias)
  File "/toknas/hugh/condap4/lib/python3.6/site-packages/torch/nn/functional.py", line 1024, in linear
    return torch.addmm(bias, input, weight.t())
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 'mat1'
```

## System Info
Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```

```
Collecting environment information...
PyTorch version: 0.4.1
Is debug build: No
CUDA used to build PyTorch: 9.0.176

OS: Ubuntu 16.04.5 LTS
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
CMake version: version 3.5.1

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 9.0.176
GPU models and configuration: GPU 0: Tesla M60
Nvidia driver version: 384.130
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.5.1.10
/usr/lib/x86_64-linux-gnu/libcudnn.so.6.0.21
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.0.3
/usr/lib/x86_64-linux-gnu/libcudnn_static_v5.a
/usr/lib/x86_64-linux-gnu/libcudnn_static_v6.a
/usr/lib/x86_64-linux-gnu/libcudnn_static_v7.a

Versions of relevant libraries:
[pip] numpy (1.14.3)
[pip] torch (0.4.1)
[pip] torchtext (0.2.3)
[pip] torchvision (0.2.1)
[conda] pytorch                   0.4.1           py36_cuda9.0.176_cudnn7.1.2_1    pytorch
[conda] torchtext                 0.2.3                     <pip>
[conda] torchvision               0.2.1                    py36_1    pytorch
```

- PyTorch or Caffe2: pytorch 0.4.1
- How you installed PyTorch (conda, pip, source): conda
- Build command you used (if compiling from source): n/a
- OS: ubuntu 16.04
- PyTorch version: 0.4.1
- Python version: 3.6.6
- CUDA/cuDNN version: 
- GPU models and configuration:
- GCC version (if compiling from source):
- CMake version:
- Versions of any other relevant libraries: