Repository: pytorch
Issue: OSError: could not find class definition when export torchscript module
Labels: oncall: jit

## 🐛 Bug

When I tried to export my pytorch model to torchscript, I got the following errors:

```
Traceback (most recent call last):
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/_utils_internal.py", line 46, in get_source_lines_and_file
    sourcelines, file_lineno = inspect.getsourcelines(obj)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/inspect.py", line 955, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/inspect.py", line 812, in findsource
    raise OSError('could not find class definition')
OSError: could not find class definition

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "export_tacotron2_ts.py", line 52, in <module>
    main()
  File "export_tacotron2_ts.py", line 46, in main
    jitted_model = torch.jit.script(model)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/__init__.py", line 1255, in script
    return torch.jit._recursive.recursive_script(obj)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 534, in recursive_script
    return create_script_module(nn_module, infer_methods_to_compile(nn_module))
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 296, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, cpp_module, stubs)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 340, in create_script_module_impl
    create_methods_from_stubs(concrete_type, stubs)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 259, in create_methods_from_stubs
    concrete_type._create_methods(defs, rcbs, defaults)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 574, in compile_unbound_method
    create_methods_from_stubs(concrete_type, (stub,))
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 259, in create_methods_from_stubs
    concrete_type._create_methods(defs, rcbs, defaults)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/_recursive.py", line 555, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/__init__.py", line 1281, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/jit/annotations.py", line 62, in get_signature
    source = dedent(''.join(get_source_lines_and_file(fn)[0]))
  File "/home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/_utils_internal.py", line 50, in get_source_lines_and_file
    "Make sure original .py files are available. Original error: {}").format(filename, e))
OSError: Can't get source for /home/xxxxx/anaconda3/envs/torch/lib/python3.7/site-packages/torch/cuda/__init__.py. TorchScript requires source access in order to carry out compilation. Make sure original .py files are available. Original error: could not find class definition
```

## Environment
PyTorch version: 1.4.0
Is debug build: False
CUDA used to build PyTorch: 10.0

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Clang version: Could not collect
CMake version: version 2.8.12.2

Python version: 3.7 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: 10.0.130

Nvidia driver version: 440.64
cuDNN version: Could not collect

Versions of relevant libraries:
[pip3] numpy==1.18.5
[pip3] torch==1.4.0
[pip3] torchvision==0.5.0
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               10.0.130                      0  
[conda] mkl                       2020.1                      217  
[conda] mkl-service               2.3.0            py37he904b0f_0  
[conda] mkl_fft                   1.1.0            py37h23d657b_0  
[conda] mkl_random                1.1.1            py37h0573a6f_0  
[conda] numpy                     1.18.5           py37ha1c710e_0  
[conda] numpy-base                1.18.5           py37hde5b4d6_0  
[conda] pytorch                   1.4.0           py3.7_cuda10.0.130_cudnn7.6.3_0    pytorch
[conda] torchvision               0.5.0                py37_cu100    pytorch

## Additional context

<!-- Add any other context about the problem here. -->


cc @suo @gmagogsfm