-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OnnxExporterError: Unsupported: ONNX export of operator GridSample with 5D volumetric input. #79
Comments
@Cyril9227, torch.onnx.export() fails for me too. It seems like the cause is described in pytorch/pytorch#100790 that will be addressed through pytorch/pytorch#114801 (ONNX opset 20 support). In the meantime I was trying to convert to ONNX through Haiku (JAX) -> TensorFlow ->ONNX, using https://dm-haiku.readthedocs.io/en/latest/notebooks/jax2tf.html as a tutorial for Haiku -> TF:
but it fails with TypeError: build_online_model_init() missing 1 required positional argument: 'query_points'. Similar with build_online_model_predict(). Maybe the input_signature() is incorrect in tf.function(), but I cannot figure out how to fix it. Since tf2onnx only supports ONNX opset up to 18, the TF SavedModel to ONNX conversion is likely to have the same problem as with PyTorch :( |
@Cyril9227 I have posted a solution here https://github.com/pytorch/pytorch/issues/100790. See if that works for you |
@saikiran321, the solution you have posted does not produce the unsupported ONNX error related to opset 20 support. |
I'm no expert on ONNX, but if the problem is a 5D gather operation, then I suspect the source of the problem is extracting query features. It's possible to rewrite the vmap using a 4D gather; it wastes computation, but it's probably relatively small compared to the rest of the model. Try setting parallelize_query_extraction to True when contstructing the tapir model; it should produce exactly the same result given the same checkpoint, but hopefully it will avoid the 5D gather. As a bit of an explanation, when extracting the query feature, we get a [t,y,x] coordinate and use bilinear interpolation to extract a feature from that location. The parallelize_query_extraction version instead extracts the feature at [y,x] from every frame (using a vmapped 4D gather), and then multiplies the resulting tensor by a 1-hot t vector to discard every query feature except the one on frame t. Of course, this is only implemented the jax version; you'd have to re-implement the same algorithm in the torch model to export from torch. |
hi! hi! I export opset16 -onnx,and use onnx_graphsurgeon to directly modify the opset to 20,then use trtexec --onnx xx—engine, meeting the same problem:Error Code 3: API Usage Error (Parameter check failed at: optimizer/api/network.cpp::addGridSample::1474, condition: input.getDimensions().nbDims == 4 @saikiran321 @SergeySandler @Cyril9227 @yotam |
Hi
Hi! Same error, did you succeed to solve this? |
I modified the torch model for the case of t=1 and reduced all the 5D to 4D, among other changes: https://github.com/ibaiGorordo/Tapir-Pytorch-Inference I also added a script to export the model but it is very slow when running in onnxruntime compared to Pytorch (RTX4080): ~700 ms without refinement and ~20s with 4 iterations (1000 points 640x640) |
Do you have the code for inference with ONNX? Do you use CUDA Execution Provider or CPU Execution Provider with ONNX? |
I added the inference time calculation on the The slow part seems to be with the convolutions in the pips mixer block |
@ibaiGorordo, I have reproduced tapir.onnx and it is three times slower than Pytorch with CUDA device. There are a couple of hints for Windows that might be useful, especially if your results with ONNX are worse than with CPU:
|
Hi everyone,
Thanks for the awesome work. I've been trying to export the pytorch model to ONNX for inference with
torch.onnx.export
but it yields this error :OnnxExporterError: Unsupported: ONNX export of operator GridSample with 5D volumetric input.
Unfortunately, It seems 5D grid_sample is still unsupported by onnx / torch. Is there any alternative available ? Or any advice to make the model work with ONNX ?
Thanks
The text was updated successfully, but these errors were encountered: