-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
onnx_export_option_B_pt_export.md
onnx_export_option_A_success.md
🐛 Describe the bug
Hey,
I am trying to export a PyTorch UNet model with MultiheadAttention in the bottleneck and dynamic shapes.
Without MultiheadAttention I can use dynamo=False and inference is successful with variable input shapes but this fails with MultiheadAttention .
In this gist I tried exporting with dynamo and dynamic_axes, with dynamo and dynamic_shapes and without dynamo but every option fails either during exporting or during inference.
https://gist.github.com/f-fuchs/012f7efb2984700d2eca93e5a8acc3f3
Option A: dynamo with dynamic_axes
export succeeds but inference with but size =! 1 leads to:
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: input for the following indices
index: 0 Got: 2 Expected: 1
Please fix either the inputs/outputs or the model.
Option B: dynamo with dynamic_shapes
export fails with convoluted guards, report is attached
Option C: dynamo=False with dynamic_axes
export works but error during inference due to MultiheadAttention
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'/attention_bottleneck/transformer_blocks/transformer_blocks.0/attn_self/Reshape_4' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:45 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) input_shape_size == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{1024,1,512}, requested shape:{256,8,64}
Versions
torch 2.7.1
onnx 1.18.0