-
Notifications
You must be signed in to change notification settings - Fork 64
Use ir methods to replace onnx helper #2091
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
base: main
Are you sure you want to change the base?
Conversation
❌ 8 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR aims to deprecate the use of onnx.helper and onnx.numpy_helper in favor of ir-based methods to improve performance. Key changes include replacing multiple onnx.helper calls with either their ir or ir.serde counterparts (and adding “# noqa: TID251” comments) and updating imports and utility functions accordingly.
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
onnxscript/tensor.py | Updated import and added noqa comment on onnx.helper usage. |
onnxscript/_internal/utils.py | Applied noqa comments to onnx.helper calls in utility functions. |
onnxscript/optimizer/_constant_folding.py | Replaced onnx.numpy_helper.from_array with ir.serde.serialize_tensor. |
onnxscript/main.py | Updated model export logic to use ir.Model and ir.save. |
onnxscript/optimizer/_legacy/constant_folding.py, etc. | Added ruff: noqa: TID251 markers and adjusted helper calls across files. |
onnxscript/_internal/autocast.py | Replaced tensor conversion via numpy_helper with ir.serde.serialize_tensor. |
onnxscript/rewriter/llama_rule_sets.py | Modified allowed tensor types check to use as_int() instead of value. |
onnxscript/rewriter/cast_constant_of_shape.py and others | Changed onnx.helper.make_tensor calls to use ir.tensor. |
onnxscript/function_libs/torch_lib/ops/nn.py | Updated empty-tensor creation to use ir.tensor. |
Comments suppressed due to low confidence (2)
onnxscript/rewriter/llama_rule_sets.py:65
- Ensure that converting the attribute value with as_int() returns the expected integer representation that matches the entries in _allowed_tensor_types. Verify that edge cases or unexpected types do not cause the check to fail.
to.as_int() in cls._allowed_tensor_types
onnxscript/_internal/autocast.py:39
- Confirm that the new serialization using ir.serde.serialize_tensor produces outputs consistent with the previous behavior of numpy_helper.from_array, ensuring compatibility with downstream tensor utilities.
return ir.serde.serialize_tensor(ir.tensor(pyvalue, name=tensor_name))
Ban onnx.helper and onnx.numpy_helper because they can be slow. Selectively enable usages of some with
noqa: TID251
and updated usages of the rest.Fix
ir.tensor
to generate float32 tensors when a plain python float is provided.