-
Notifications
You must be signed in to change notification settings - Fork 277
[ONNX] Add eliminate_nop_cast pass #3376
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
[ONNX] Add eliminate_nop_cast pass #3376
Conversation
|
@kshpv Please review |
4650dc4 to
fa04951
Compare
alexsu52
left a comment
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.
Is this PR in draft or can it be reviewed?
76053b7 to
ac7b3c2
Compare
f059315 to
17f658e
Compare
|
NNCF/nightly/e2e_onnx_model_zoo: Build # 953 |
I've updated it, so it can now be reviewed. |
alexsu52
left a comment
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.
LGTM
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 pull request introduces the eliminate_nop_cast optimization pass to remove no-op cast nodes from ONNX graphs before quantization. Key changes include:
- Adding a new pass in nncf/onnx/graph/passes.py to eliminate redundant Cast nodes.
- Integrating the pass into model preprocessing in both the test and quantization flows.
- Creating a test model with a no-op Cast and a corresponding unit test in tests/onnx.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/onnx/test_passes.py | Added a unit test to validate the elimination of no-op Cast nodes. |
| tests/onnx/models.py | Introduced a helper to build a MatMul model with a no-op Cast node. |
| nncf/onnx/quantization/quantize_model.py | Integrated preprocess passes into the quantization pipeline. |
| nncf/onnx/graph/passes.py | Implemented the eliminate_nop_cast and apply_preprocess_passes passes. |
Comments suppressed due to low confidence (2)
nncf/onnx/graph/passes.py:58
- Consider verifying that cast_node.output[0] exists in model.graph.value_info before attempting removal, to prevent potential KeyError if the value info is absent.
model.graph.value_info.remove(value_infos[cast_node.output[0]])
tests/onnx/models.py:1911
- Ensure that numpy is imported as 'np' in this module if it is not already imported to avoid a NameError.
W_values = np.random.rand(3, 2).astype(np.float32)
Changes
Apply the
eliminate_nop_castoptimization pass before building the NNCF graph. This pass aims to eliminate no-op cast nodes in the graph. A no-op cast is a cast that doesn't change the value, such as casting a tensor to its own type.Reason for changes
Statistics cannot be collected after the no-op Cast nodes because such nodes are removed from the ONNX inference graph during the session.
Related tickets
Ref: 164211