RuntimeError: unexpected tensor scalar type

I am getting an error saying RuntimeError: unexpected tensor scalar type while exporting my pytorch model to ONNX:

Could someone tell me what I’m missing here?
Thanks!

The error could be raised e.g. in these lines of code which would point to an unknown dtype. Which dtypes are you using in your workflow and could you check, if this dtype is not in the supported list?

Not sure if you have resolved the problem. I have come across the same error.

File “/usr/local/lib/python3.8/site-packages/torch/onnx/utils.py”, line 897, in _graph_op
torch._C._jit_pass_onnx_node_shape_type_inference(n, _params_dict, opset_version)
RuntimeError: unexpected tensor scalar type

I try to print out the n, _params_dict here and I got

%552 : Tensor = onnx::Constant[value={0}]()
{}
%553 : Tensor = onnx::Shape(%2)
{}
%554 : Tensor = onnx::Constant[value={0}]()
{}
%555 : Tensor = onnx::Constant[value={0}]()
{}
%556 : Tensor = onnx::Gather[axis=0](%553, %555)
{}
%557 : Tensor = onnx::Constant[value={4}]()
{}
%558 : Tensor = onnx::Constant[value={257}]()
{}
%559 : Tensor = onnx::Constant[value={-1}]()
{}
%561 : Tensor = onnx::Reshape(%0, %560)
{}
Is it due to Reshape()?

I have figure out my problem. it is due to complex number. You can refer to Unexpected tensor scalar type with torch.onnx.export and ComplexFloat · Issue #59246 · pytorch/pytorch · GitHub.

The error log comes from pytorch/export.cpp at master · pytorch/pytorch · GitHub

1 Like