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()?