torch.onnx.export is throwing RuntimeError: prim::TupleUnpack not matched to tuple construct
Labels: module: onnx, triaged

### 🐛 Describe the bug

I want to export my SSD model to onnx format, so I modified my model with a new helper function below to dump the onnx. 

```
def save_onnx_model(model,device):
   dummy_input = torch.rand(32,3,800,800, dtype = torch.float16, requires_grad=False, device = device)

   input_names = ['modelInput']
   output_names = ['Out0', 'Out1', 'Out2', 'Out3', 'Out4', 'Out5', 'Out6']
   with torch.cuda.amp.autocast(enabled=True):
        torch.onnx.export(model,         # model being run
             (dummy_input,),       # model input (or a tuple for multiple inputs)
             "ImageClassifier.onnx",       # where to save the model
             export_params=True,  # store the trained parameter weights inside the model file
             opset_version=11,    # the ONNX version to export the model to
             verbose=True,
             do_constant_folding=True,  # whether to execute constant folding for optimization
             input_names = input_names,   # the model's input names
             output_names = output_names, # the model's output names
             dynamic_axes={'modelInput' : {0 : 'batch_size'},    # variable length axes
                           'Out0' : {0 : 'batch_size'},
                           'Out1' : {0 : 'batch_size'},
                           'Out2' : {0 : 'batch_size'},
                           'Out3' : {0 : 'batch_size'},
                           'Out4' : {0 : 'batch_size'},
                           'Out5' : {0 : 'batch_size'},
                           'Out6' : {0 : 'batch_size'},
                           })
    print(" ")
    print('Model has been converted to ONNX')
```

However, i am getting error messages from pytorch jit.

This is the Verbose information
  %6182 : Half(32, 120087, 4, strides=[480348, 4, 1], requires_grad=1, device=cuda:0) = aten::cat(%6180, %6181) # /workspace/ssd/model/retinanet.py:466:0
  %6183 : (Half(32, 256, 100, 100, strides=[2560000, 1, 25600, 256], requires_grad=1, device=cuda:0), Half(32, 256, 50, 50, strides=[640000, 1, 12800, 256], requires_grad=1, device=cuda:0), Half(32, 256, 25, 25, strides=[160000, 1, 6400, 256], requires_grad=1, device=cuda:0), Half(32, 256, 13, 13, strides=[43264, 1, 3328, 256], requires_grad=1, device=cuda:0), Half(32, 256, 7, 7, strides=[12544, 1, 1792, 256], requires_grad=1, device=cuda:0), Half(32, 120087, 264, strides=[31702968, 264, 1], requires_grad=1, device=cuda:0), Half(32, 120087, 4, strides=[480348, 4, 1], requires_grad=1, device=cuda:0)) = prim::TupleConstruct(%5144, %5352, %5560, %5768, %5976, %5059, %6182)
  return (%6183)
```
  Traceback (most recent call last):
  File "train.py", line 651, in <module>
    main(args)
  File "train.py", line 562, in main
    metric_logger, accuracy = train_one_epoch(model=model,
  File "/workspace/ssd/engine.py", line 237, in train_one_epoch
    save_onnx_model(model,device)
  File "/workspace/ssd/engine.py", line 169, in save_onnx_model
    torch.onnx.export(model,         # model being run
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 479, in export
    _export(
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 1419, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 1063, in _model_to_graph
    graph = _optimize_graph(
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 551, in _optimize_graph
    _C._jit_pass_lower_all_tuples(graph)
**RuntimeError: prim::TupleUnpack not matched to tuple construct**
```
Not sure if people have seen similar errors before. What is causing the TupleUnpack not matched to tuple construct Runtime error here?





### Versions

torch version: 1.13