Repository: pytorch
Issue: 'torch::jit::script::ErrorReport' from 'torch::jit::load('modelpath') in Visual Studio 2017
Labels: oncall: jit

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->
I exported one model([StructureFlow](https://github.com/RenYurui/StructureFlow))  via torch.jit.script or torch.jit.trace. When I try to import it in C++(VS2017) an error occurs during loading model.
The model was trained & exported in python on Linux  and I tried to import it in  C++(VS2017 on Windows10).
The model includes  normal nn layers and some  CUDA functions(.cu)  registered with TorchScript according to the [tutorials](https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html).
And firstly, the CUDA functions are built using setuptools( by nvcc compiler) before training or testing the model.
In Python, the model works well but I can't load it in C++.
And I can load other exported models normally but can't load this CUDA function-included one.

## To Reproduce
<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
Steps to reproduce the behavior:
1.  register cuda function with torchscript  in <resample2d_cuda_new.cc>=>ok
```
#include <ATen/ATen.h>
#include <torch/torch.h>
#include <torch/script.h>
#include "resample2d_kernel_new.cuh"

void resample2d_cuda_forward(
    const at::Tensor& input1,
    const at::Tensor& input2,
    const at::Tensor& output,
    int64_t  kernel_size,
    int64_t  dilation) {
      resample2d_kernel_forward_new(input1, input2, output, kernel_size, dilation);
    return;
}
void resample2d_cuda_backward(
    const at::Tensor& input1,
    const at::Tensor& input2,
    const at::Tensor& gradOutput,
    const at::Tensor& gradInput1,
    const at::Tensor& gradInput2,
    int64_t kernel_size,
    int64_t dilation) {
        resample2d_kernel_backward_new(input1, input2, gradOutput, gradInput1, gradInput2, kernel_size, dilation);
    return;
}
//torch script register
 static auto registry =
  torch::RegisterOperators("my_ops::resample2d_cuda_forward", &resample2d_cuda_forward)
  .op("my_ops::resample2d_cuda_backward", &resample2d_cuda_backward);
```
2. build cuda functions using setuptools in <setup.py> => ok
```
import os
import torch

from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
cxx_args = ['-std=c++14']
nvcc_args = [
    '-gencode', 'arch=compute_60,code=sm_60',
    '-gencode', 'arch=compute_61,code=sm_61',
    '-gencode', 'arch=compute_70,code=sm_70',
]
setup(
    name='resample2d_cuda',
    ext_modules=[
        CUDAExtension('resample2d_cuda', [            
            'resample2d_cuda_new.cc',
            'resample2d_kernel_new.cu'
        ], extra_compile_args={'cxx': cxx_args, 'nvcc': nvcc_args})
    ],
    cmdclass={
        'build_ext': BuildExtension
    })
```

3. export model and save .pt files  => ok

```
traced_script_module = torch.jit.trace(self.f_gen, input_cat)
or
traced_script_module  = torch.jit.script(self.f_gen, input_cat)
```

4. importing model in VS2017 (Windows 10) => failed
 ```
 torch::jit::script::Module module;	
	try {
		module = torch::jit::load(model_path, torch::kCUDA);
		std::cout << "model2 ok\n";
	}
       catch (const c10::Error& e) {
		std::cerr << "error loading the model\n";
		return -1;
	}
```

5. Error messages

```
Unhandled Exception(0x00007FFFB848A799, StructureFlow_LT15_DBG.exe): 
Microsoft C++exception: torch::jit::ErrorReport, Error at memory location x0000002C407121A0.
```
[captured screen of the exception & call stacks ](https://drive.google.com/file/d/1aC_P_iWBlFw8npl4G5dgQLyqhq8wlHu8/view?usp=sharing)

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->
the model is loaded.
## Environment
Python envs:
```
PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.4 LTS
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
CMake version: Could not collect

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.1.243
GPU models and configuration: GPU 0: TITAN Xp
Nvidia driver version: 440.82
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5

Versions of relevant libraries:
[pip] numpy==1.18.1
[pip] torch==1.4.0
[pip] torchvision==0.5.0
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               10.1.243             h6bb024c_0  
[conda] mkl                       2020.1                      217  
[conda] mkl-service               2.3.0            py36he904b0f_0  
[conda] mkl_fft                   1.0.15           py36ha843d7b_0  
[conda] mkl_random                1.1.0            py36hd6b4f25_0  
[conda] numpy                     1.18.1           py36h4f9e942_0  
[conda] numpy-base                1.18.1           py36hde5b4d6_1  
[conda] pytorch                   1.4.0           py3.6_cuda10.1.243_cudnn7.6.3_0    pytorch
[conda] torchvision               0.5.0                py36_cu101    pytorch
```
 C++ envs:
```
libtorch 1.4.0 and 1.5.1  (both have same error)
Visutal Studio 2017 (C++14)
GPU models : GTX-1070
```
## Additional context
<!-- Add any other context about the problem here. -->
I share my exported models(.pt files exported by torch.jit.script  and torch.jit.trace) to reproduce the error.
[model1](https://drive.google.com/file/d/1ragU1kDvMVWuRceeiscf4r2BqdfME2yC/view?usp=sharing)
[model2](https://drive.google.com/file/d/1DKWZjqQnj-qWu-xJ-SY6d1PgYiP5D4UG/view?usp=sharing)

cc @suo @gmagogsfm