Repository: pytorch
Issue: Pytorch report INTERNAL ASSERT FAILED at ..\torch\csrc\jit\ir.cpp:1529 when use torch.jit.script to convert to model
Labels: oncall: jit

## 🐛 Bug

came across same error as https://github.com/pytorch/pytorch/issues/34707#issue-580449872

output of collect_env.py is:

Collecting environment information...
PyTorch version: 1.4.0
Is debug build: False
CUDA used to build PyTorch: 10.0
ROCM used to build PyTorch: N/A

OS:
GCC version: (GCC) 5.1.0
Clang version: 3.4.2 (tags/RELEASE_34/dot2-final)
CMake version: version 3.9.2

Python version: 3.8 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration:
GPU 0: Tesla P40
GPU 1: Tesla P40
GPU 2: Tesla P40
GPU 3: Tesla P40
GPU 4: Tesla P40
GPU 5: Tesla P40
GPU 6: Tesla P40
GPU 7: Tesla P40

Nvidia driver version: 418.40.04
cuDNN version: /usr/local/cuda-8.0/lib64/libcudnn.so.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.1
[pip3] pytorch-ranger==0.1.1
[pip3] pytorch-wpe==0.0.0
[pip3] torch==1.4.0
[pip3] torch-complex==0.2.0
[pip3] torch-optimizer==0.0.1a15
[pip3] torchaudio==0.4.0
[pip3] warprnnt-pytorch==0.1
[conda] blas 1.0 mkl
[conda] cudatoolkit 10.0.130 0
[conda] mkl 2020.2 256
[conda] mkl-service 2.3.0 py38he904b0f_0
[conda] mkl_fft 1.2.0 py38h23d657b_0
[conda] mkl_random 1.1.1 py38h0573a6f_0
[conda] numpy 1.19.1 py38hbc911f0_0
[conda] numpy-base 1.19.1 py38hfa32c7d_0
[conda] pytorch 1.4.0 py3.8_cuda10.0.130_cudnn7.6.3_0 pytorch
[conda] pytorch-ranger 0.1.1 pypi_0 pypi
[conda] pytorch-wpe 0.0.0 pypi_0 pypi
[conda] torch-complex 0.2.0 pypi_0 pypi
[conda] torch-optimizer 0.0.1a15 pypi_0 pypi
[conda] torchaudio 0.4.0 pypi_0 pypi
[conda] warprnnt-pytorch 0.1 pypi_0 pypi

Sorry for hiding data security related info
Hope for some advice

-------------------------
Error info and stack here:
-------------------------

script_model = torch.jit.script(target_model)
File "conda_env/lib/python3.8/site-packages/torch/jit/init.py", line 1255, in script
return torch.jit._recursive.recursive_script(obj)
File "conda_env/lib/python3.8/site-packages/torch/jit/_recursive.py", line 534, in recursive_script
return create_script_module(nn_module, infer_methods_to_compile(nn_module))
File "conda_env/lib/python3.8/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 "conda_env/lib/python3.8/site-packages/torch/jit/_recursive.py", line 340, in create_script_module_impl
create_methods_from_stubs(concrete_type, stubs)
File "conda_env/lib/python3.8/site-packages/torch/jit/_recursive.py", line 259, in create_methods_from_stubs
concrete_type._create_methods(defs, rcbs, defaults)
RuntimeError: values[i]->type()->isSubtypeOf(value_type) INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1579061855666/work/torch/csrc/jit/ir.cpp:1529, please report a bug to PyTorch. (createDict at /opt/conda/conda-bld/pytorch_1579061855666/work/torch/csrc/jit/ir.cpp:1529)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f959c0ea627 in conda_env/lib/python3.8/site-packages/torch/lib/libc10.so)
frame #1: torch::jit::Graph::createDict(std::shared_ptrc10::Type const&, std::shared_ptrc10::Type const&, c10::ArrayReftorch::jit::Value*, c10::ArrayReftorch::jit::Value*) + 0x54f (0x7f95a1eeb96f in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #2: + 0x3e4121e (0x7f95a20a821e in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #3: + 0x3e42f52 (0x7f95a20a9f52 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #4: + 0x3e4e5b6 (0x7f95a20b55b6 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #5: + 0x3e4f2ef (0x7f95a20b62ef in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #6: + 0x3e55681 (0x7f95a20bc681 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #7: + 0x3e58394 (0x7f95a20bf394 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #8: + 0x3e59575 (0x7f95a20c0575 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #9: + 0x3e23f14 (0x7f95a208af14 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #10: torch::jit::Function::ensure_defined() + 0xca (0x7f95a21616ea in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #11: torch::jit::script::CompilationUnit::define(c10::optionalc10::QualifiedName const&, std::vector<torch::jit::script::Def, std::allocatortorch::jit::script::Def > const&, std::vector<std::shared_ptrtorch::jit::script::Resolver, std::allocator<std::shared_ptrtorch::jit::script::Resolver > > const&, torch::jit::script::Self const*, bool) + 0x5c8 (0x7f95a2089ad8 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #12: + 0x77bbbe (0x7f95cda9cbbe in conda_env/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #13: + 0x28b8a7 (0x7f95cd5ac8a7 in conda_env/lib/python3.8/site-packages/torch/lib/libtorch_python.so)

-----------
further info
-----------
target_model includes a transformer encoder, a transformer decder and a ctc part,

torch.jit.script(target_model.encoder)
torch.jit.script(target_model.decoder)
torch.jit.script(target_model.ctc)

all work well...

cc @gmagogsfm