Skip to content
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

Support Elu operator, reading axes list from inputs rather than attribute in Reduce* ops #132

Merged
merged 5 commits into from
Apr 29, 2024

Conversation

robertknight
Copy link
Owner

@robertknight robertknight commented Apr 28, 2024

This addresses a few issues I found while playing around with ONNX models from openpilot:

  • Support the Elu activation operator
  • The latest versions of the Reduce* operators take axes as a dynamic input rather than static attribute.
  • Enable the ort-infer.py script to run with models that have float16 inputs

For RTen, the original supercombo.onnx model fails to convert because the weights are in float16 format. However this hack works (at least for getting the model to run, I haven't verified the outputs):

diff --git a/rten-convert/rten_convert/converter.py b/rten-convert/rten_convert/converter.py
index 42b427a6..d4fe5f4e 100644
--- a/rten-convert/rten_convert/converter.py
+++ b/rten-convert/rten_convert/converter.py
@@ -426,6 +426,9 @@ def constant_node_from_onnx_initializer(
         case "float32" | "int32":
             pass
 
+        case "float16":
+            data = data.astype(np.float32)
+
         # Int types that can be widened to int32
         case "bool" | "int8" | "int16":
             data = data.astype(np.int32)

TODO:

  • Tests for Elu op
  • Tests for Reduce operator change

This allows testing float16 models under ONNX Runtime for reference, even though
RTen doesn't support them yet.
@robertknight robertknight force-pushed the openpilot-supercombo branch 2 times, most recently from 5f4060f to 06e8357 Compare April 28, 2024 15:20
There are existing `data` and `to_vec` methods which never and always copy
respectively. This fills in a gap by adding a method which only copies if
needed.
I noted a slight difference between the PyTorch and ONNX expressions for this
function, but they are equivalent for `x = 0`.
In earlier versions of the ONNX `Reduce*` operators, axes were specified as an
attribute. In the latest version they were promoted to an input.
@robertknight robertknight marked this pull request as ready for review April 29, 2024 06:27
@robertknight robertknight merged commit aa3c7a0 into main Apr 29, 2024
2 checks passed
@robertknight robertknight deleted the openpilot-supercombo branch April 29, 2024 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant