ArrayRef length issue when export pytorch model to onnx

Hi

I have some problem converting my pytorch model into onnx. My input to the model is a list(since I define my own data loader collate_fn), where length of the list is the batch size and each element in the list is a custom tuple of elements. My output is a tensor with shape: batchsize x height x width

The code converting model to onnx:

# Export the model
torch.onnx.export(model, # model being run
cuda(X), # model input (or a tuple for multiple inputs)
“final.onnx”, # where to save the model (can be a file or file-like object)
export_params=True, # store the trained parameter weights inside the model file
opset_version=9, # the ONNX version to export the model to
do_constant_folding=True, # whether to execute constant folding for optimization
input_names = [‘input’], # the model’s input names
output_names = [‘pred_traj_tensor’], # the model’s output names
dynamic_axes={‘input’ : {0 : ‘batch_size’}, # variable lenght axes
‘pred_traj_tensor’ : {0 : ‘batch_size’}}, verbose=True)

Runtime Error:

File “/home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/onnx/utils.py”, line 144, in _optimize_graph
torch._C._jit_pass_onnx_peephole(graph, _export_onnx_opset_version, fixed_batch_size)
RuntimeError: ArrayRef: invalid index Index = 0; Length = 0 (at at /opt/conda/conda-bld/pytorch_1579022034529/work/c10/util/ArrayRef.h:197)

Really don’t know how to debug further. Any help is greatly appreciated !

Here is the detailed stack trace.

Traceback (most recent call last): File "learning_algorithms/prediction/datasets/apollo_vehicle_trajectory_dataset/convert_onnx.py", line 113, in 'pred_traj_tensor' : {0 : 'batch_size'}}) File "/home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/onnx/__init__.py", line 148, in export strip_doc_string, dynamic_axes, keep_initializers_as_inputs) File "/home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/onnx/utils.py", line 66, in export dynamic_axes=dynamic_axes, keep_initializers_as_inputs=keep_initializers_as_inputs) File "/home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/onnx/utils.py", line 418, in _export fixed_batch_size=fixed_batch_size) File "/home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/onnx/utils.py", line 298, in _model_to_graph fixed_batch_size=fixed_batch_size, params_dict=params_dict) File "/home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/onnx/utils.py", line 144, in _optimize_graph torch._C._jit_pass_onnx_peephole(graph, _export_onnx_opset_version, fixed_batch_size) RuntimeError: ArrayRef: invalid index Index = 0; Length = 0 (at at /opt/conda/conda-bld/pytorch_1579022034529/work/c10/util/ArrayRef.h:197) frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7fb2baa2c627 in /home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/lib/libc10.so) frame #1: + 0x6f484b (0x7fb2ed63184b in /home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/lib/libtorch_python.so) frame #2: + 0x7003ec (0x7fb2ed63d3ec in /home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/lib/libtorch_python.so) frame #3: torch::jit::PeepholeOptimizeONNX(std::shared_ptr&, int, bool) + 0x125 (0x7fb2ed642985 in /home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/lib/libtorch_python.so) frame #4: + 0x6b496c (0x7fb2ed5f196c in /home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/lib/libtorch_python.so) frame #5: + 0x28c076 (0x7fb2ed1c9076 in /home/weide/anaconda3/envs/fuel-py36/lib/python3.6/site-packages/torch/lib/libtorch_python.so) frame #36: __libc_start_main + 0xe7 (0x7fb30ac9ab97 in /lib/x86_64-linux-gnu/libc.so.6)

Hi @weidezhang, seems like an ONNX bug. I would suggest raising an issue on the pytorch repo.

created: https://github.com/pytorch/pytorch/issues/39762

Hi @eellison, could you help me to see who is able to look at the issue on github ? I have updated the details(model and test script) on github.