IndexError: too many indices for tensor of dimension 2

MLHafizur: <p>I am trying to load a PyTorch model and load that in ONNX format.</p>
<p>Input size:</p>
<pre><code class="lang-auto">features.values()
dict_values([tensor([[  101,  1037,  5264,  ..., 10127,  1998,   102],
        [  101, 16137,  3968,  ...,  2861,  1017,   102],
        [  101, 17827,  1037,  ...,  5252,  2924,   102],
        ...,
        [  101,  3046,  1996,  ...,  2440,  3193,   102],
        [  101,  3046,  1996,  ...,  1037,  3319,   102],
        [  101,  3653,  3286,  ...,  9967,  1997,   102]]), tensor([[1, 1, 1,  ..., 1, 1, 1],
        [1, 1, 1,  ..., 1, 1, 1],
        [1, 1, 1,  ..., 1, 1, 1],
        ...,
        [1, 1, 1,  ..., 1, 1, 1],
        [1, 1, 1,  ..., 1, 1, 1],
        [1, 1, 1,  ..., 1, 1, 1]])])
</code></pre>
<pre><code class="lang-auto">&gt; tuple(features.values())
(tensor([[  101,  103...,   102]]), tensor([[1, 1, 1,  ....1, 1, 1]]))
</code></pre>
<p>But the conversion command throwing an IndexError:<br>
<code>onnx_adv_model = torch.onnx.export(model, args=tuple(features.values()), f="./src/data/export-pt.onnx")</code></p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/onnx/__init__.py", line 350, in export
    return utils.export(
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 163, in export
    _export(
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 1074, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 727, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 602, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/onnx/utils.py", line 517, in _trace_and_get_graph_from_model
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 1175, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 118, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1118, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/azureuser/cloudfiles/code/Users/Hafizur.Rahman/research-clarity-id-multiclassification/src/multiclassificationEN/modeling/Classifier.py", line 108, in forward
    outputs = self.encoder(features)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/azureuser/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1118, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/azureuser/cloudfiles/code/Users/Hafizur.Rahman/research-clarity-id-multiclassification/src/multiclassificationEN/modeling/Transformer.py", line 43, in forward
    trans_features = {'input_ids': features['input_ids'], 'attention_mask': features['attention_mask']}
IndexError: too many indices for tensor of dimension 2
</code></pre>
<p>Looking forward to your help.</p>