Repository: pytorch
Issue: DataParallel does not work with sparse parameters
Labels: triaged,module: data parallel

## 🐛 Bug

DataParallel does not work with sparse parameters.
The root issue is located in the model replication part of DataParallel.
I have a fix proposal for this and can make a pull request : https://github.com/madlag/pytorch/commit/a64aacd4168ac73f50ee9e6ed16cfdca8e22af1d
(this fixes completely DataParallel for version 1.4)

## To Reproduce

Steps to reproduce the behavior:

Run the following code on a machine with at least 2 gpus : 
```
import torch
import torch.nn
import torch.sparse
import torch.nn.parallel.replicate as replicate

class MyModule(torch.nn.Module):
    def __init__(self):
        super().__init__()
        indices = torch.LongTensor([[0,1,2],[0,0,0]])
        values = torch.tensor([0.0,0.0,0.0])
        t = torch.sparse.FloatTensor(indices, values, [3,3])
        self.p = torch.nn.Parameter(t)

m = MyModule().cuda()
replicate(m, [0,1])
```

You will get this error message :
```
Traceback (most recent call last):
  File "test_data_parallel.py", line 15, in <module>
    replicate(m, [0,1])
  File "/home/lagunas/ml/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/replicate.py", line 92, in replicate
    param_copies = _broadcast_coalesced_reshape(params, devices, False)
  File "/home/lagunas/ml/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/replicate.py", line 71, in _broadcast_coalesced_reshape
    tensor_copies = Broadcast.apply(devices, *tensors)
RuntimeError: Could not run 'aten::view' with arguments from the 'SparseCUDATensorId' backend. 'aten::view' is only available for these backends: [CUDATensorId, QuantizedCPUTensorId, VariableTensorId, CPUTensorId, MkldnnCPUTensorId].
```

## Expected behavior

The expected behaviour should be to replicate correctly the model containing sparse parameter.

## Environment

PyTorch 1.4, with two GPUS.

```Collecting environment information...
PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: 10.0

OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.10.2

Python version: 3.7
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: 
GPU 0: GeForce RTX 2080 Ti
GPU 1: GeForce GTX 1080

Nvidia driver version: 430.26
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] numpy==1.16.4
[pip] numpydoc==0.9.1
[pip] torch==1.4.0
[pip] torch-scatter==1.4.0
[pip] torch-sparse==0.4.3
[pip] torchfile==0.1.0
[pip] torchvision==0.5.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2019.4                      243  
[conda] mkl-service               2.0.2            py37h7b6447c_0  
[conda] mkl_fft                   1.0.12           py37ha843d7b_0  
[conda] mkl_random                1.0.2            py37hd81dba3_0  
[conda] pytorch                   1.4.0           py3.7_cuda10.0.130_cudnn7.6.3_0    pytorch
[conda] torch-scatter             1.4.0                    pypi_0    pypi
[conda] torch-sparse              0.4.3                    pypi_0    pypi
[conda] torchfile                 0.1.0                      py_0    conda-forge
[conda] torchvision               0.5.0                py37_cu100    pytorch
```