When I using torch.export.onnx, it reported an error
/home/pacaep/env/py38/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2157.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
LXRT encoder with 12 l_layers, 5 x_layers, and 0 r_layers.
/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/utils.py:90: UserWarning: 'enable_onnx_checker' is deprecated and ignored. It will be removed in the next PyTorch release. To proceed despite ONNX checker failures, catch torch.onnx.ONNXCheckerError.
warnings.warn("'enable_onnx_checker' is deprecated and ignored. It will be removed in "
/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/utils.py:103: UserWarning: `use_external_data_format' is deprecated and ignored. Will be removed in next PyTorch release. The code will work as it is False if models are not larger than 2GB, Otherwise set to False because of size limits imposed by Protocol Buffers.
warnings.warn("`use_external_data_format' is deprecated and ignored. Will be removed in next "
/home/pacaep/wbdc2022-baseline/utils/swin.py:449: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
assert H == self.img_size[0] and W == self.img_size[1], \
/home/pacaep/wbdc2022-baseline/utils/swin.py:242: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
assert L == H * W, "input feature has wrong size"
/home/pacaep/wbdc2022-baseline/utils/swin.py:46: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
x = x.view(B, H // window_size, window_size, W // window_size, window_size, C)
/home/pacaep/wbdc2022-baseline/utils/swin.py:124: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
qkv = self.qkv(x).reshape(B_, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
/home/pacaep/wbdc2022-baseline/utils/swin.py:62: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
B = int(windows.shape[0] / (H * W / window_size / window_size))
/home/pacaep/wbdc2022-baseline/utils/swin.py:139: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
attn = attn.view(B_ // nW, nW, self.num_heads, N, N) + mask.unsqueeze(1).unsqueeze(0)
/home/pacaep/wbdc2022-baseline/utils/swin.py:319: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
assert L == H * W, "input feature has wrong size"
/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/symbolic_helper.py:325: UserWarning: Type cannot be inferred, which might cause exported graph to produce incorrect results.
warnings.warn("Type cannot be inferred, which might cause exported graph to produce incorrect results.")
[W shape_type_inference.cpp:434] Warning: Constant folding in symbolic shape inference fails: index_select(): Index is supposed to be a vector
Exception raised from index_select_out_cpu_ at ../aten/src/ATen/native/TensorAdvancedIndexing.cpp:887 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x42 (0x7fcb6f42cd62 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libc10.so)
frame #1: at::native::index_select_out_cpu_(at::Tensor const&, long, at::Tensor const&, at::Tensor&) + 0x3a9 (0x7fcbb435a189 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #2: at::native::index_select_cpu_(at::Tensor const&, long, at::Tensor const&) + 0xe6 (0x7fcbb435c146 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #3: <unknown function> + 0x1d37f12 (0x7fcbb4a53f12 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #4: at::_ops::index_select::redispatch(c10::DispatchKeySet, at::Tensor const&, long, at::Tensor const&) + 0xb9 (0x7fcbb45ef099 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #5: <unknown function> + 0x3250ac3 (0x7fcbb5f6cac3 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #6: <unknown function> + 0x32510f5 (0x7fcbb5f6d0f5 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #7: at::_ops::index_select::call(at::Tensor const&, long, at::Tensor const&) + 0x166 (0x7fcbb466ece6 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
frame #8: torch::jit::onnx_constant_fold::runTorchBackendForOnnx(torch::jit::Node const*, std::vector<at::Tensor, std::allocator<at::Tensor> >&, int) + 0x1b5f (0x7fcc366d275f in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #9: <unknown function> + 0xbbdc72 (0x7fcc36719c72 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #10: torch::jit::ONNXShapeTypeInference(torch::jit::Node*, std::map<std::string, c10::IValue, std::less<std::string>, std::allocator<std::pair<std::string const, c10::IValue> > > const&, int) + 0xa8e (0x7fcc3671f3ce in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #11: <unknown function> + 0xbc4ed4 (0x7fcc36720ed4 in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #12: <unknown function> + 0xb356dc (0x7fcc366916dc in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #13: <unknown function> + 0x2a588e (0x7fcc35e0188e in /home/pacaep/env/py38/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
<omitting python frames>
frame #41: __libc_start_main + 0xf5 (0x7fcc6e9fb555 in /usr/lib64/libc.so.6)
(function ComputeConstantFolding)
Traceback (most recent call last):
File "torch2onnx.py", line 33, in <module>
torch.onnx.export(model, (frame_input,frame_mask,title_input,title_mask), './save/model.onnx', verbose=False, opset_version=12,
File "/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/__init__.py", line 316, in export
return utils.export(model, args, f, export_params, verbose, training,
File "/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 107, in export
_export(model, args, f, export_params, verbose, training, input_names, output_names,
File "/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 724, in _export
_model_to_graph(model, args, verbose, input_names,
File "/home/pacaep/env/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 544, in _model_to_graph
params_dict = torch._C._jit_pass_onnx_constant_fold(graph, params_dict,
IndexError: index_select(): Index is supposed to be a vector
When I using
torch.export.onnx
, it reported an errorplease teach me how to deal with it, thanks