-
Notifications
You must be signed in to change notification settings - Fork 731
Arm backend: Support quantized cond and while #15849
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15849
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 3 Unrelated FailuresAs of commit 332375f with merge base 9952aef ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@metascroy Hey Scott, this PR is rather large so probably best for you to test internally first. Thanks! |
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 adds support for quantized while_loop and cond operations to the Arm backend. The implementation extends the TOSA backend to handle control flow constructs with proper quantization handling through specialized passes and annotation logic.
Key changes:
- Introduces
while_loopoperator support with validation, node visitors, and tests - Adds quantization infrastructure for control flow operations via
InsertControlFlowRescalesPassand updated annotation logic - Refactors control flow support into dedicated module (
control_flow_support.py) for better code organization
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| backends/arm/tosa/partitioner.py | Renames get_control_flow_submodules to get_cond_while_submodules |
| backends/arm/tosa/backend.py | Adds containing_graph_module parameter and output node normalization |
| backends/arm/test/tester/test_pipeline.py | Switches to custom ArmQuantize class |
| backends/arm/test/tester/quantize.py | New custom quantize stage for Arm-specific quantization with submodule support |
| backends/arm/test/tester/arm_tester.py | Updates quantize stage to use ArmQuantize |
| backends/arm/test/ops/test_while.py | New comprehensive test suite for while_loop operations |
| backends/arm/test/ops/test_cond.py | Adds tests for quantized conditionals and new test cases |
| backends/arm/scripts/parse_test_names.py | Adds while_loop.default to custom edge ops list |
| backends/arm/quantizer/quantization_annotator.py | Extends annotation logic to handle cond and while_loop operations |
| backends/arm/quantizer/arm_quantizer.py | Adds quantize_with_submodules method for proper submodule quantization |
| backends/arm/process_node.py | Handles placeholder processing for submodule inputs |
| backends/arm/operators/operator_validation_utils.py | Adds reusable control flow extension validation |
| backends/arm/operators/op_while.py | New visitor for while_loop operator serialization |
| backends/arm/operators/op_cond_if.py | Refactors to use shared validation utility |
| backends/arm/operators/init.py | Imports new op_while module |
| backends/arm/operator_support/tosa_supported_operators.py | Moves control flow support to dedicated module |
| backends/arm/operator_support/control_flow_support.py | New dedicated module for control flow partitioning logic |
| backends/arm/operator_support/init.py | Imports new control flow support module |
| backends/arm/_passes/insert_rescales_pass.py | Adds InsertControlFlowRescalesPass for quantization parameter handling |
| backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py | Extends to handle control flow node quantization folding |
| backends/arm/_passes/arm_pass_manager.py | Integrates new control flow rescale pass |
| backends/arm/_passes/init.py | Exports new control flow rescale pass |
Comments suppressed due to low confidence (1)
backends/arm/process_node.py:249
- Unnecessary 'pass' statement.
pass
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Copilot reviewed 22 out of 22 changed files in this pull request and generated 11 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Importing now |
The standard prepare/convert_pt2 does not seem to support
quantization out of the box. Instead, a quantization call
is introduced in the TOSAQuantizer, that does the neccessary
steps to get correct quantization on submodules. A custom
Quantize step is needed in the ArmTester to make this work
in testing.
Additionally, getting correct quantization parameters needs
some delicate handling. The model is calibrated twice,
once for each code path. Because of this, the observers outside
the if/else submodules see different data than the observers
inside the submodules. Rescales need to be inserted to handle
this. To get a correctly traced graph at all times, we
1. Fold the outmost quant ops in the submodules at the same
time as the cond is folded. Add qparam meta to folded
nodes inside submodule.
2. Use this meta in the InsertCondRescale pass to
insert a tosa.RESCALE to handle the different qparams.
3. After this, the submodule's q-dq nodes can be folded normally.
Signed-off-by: Erik Lundell <[email protected]>
Change-Id: Ia37c4478a661d1156f537ca6d4e1e17f0f130d24
- Refactor CondSupported to also test while, move to own file and split into one check for submodule nodes, and one for ops. - Add node visitor - Add tests Signed-off-by: Erik Lundell <[email protected]> Change-Id: I932c2065fe3e9ff8956bc336c62624522d9ba0f0
- Add annotation logic. - Extend cond handling in q-dq folding to while - Extend InsertCondRescale pass to handle while. Signed-off-by: Erik Lundell <[email protected]> Change-Id: Ia3b2ad04a2d1c298f09b0d15a5e6969ed46db66b
Signed-off-by: Erik Lundell <[email protected]> Change-Id: I89b908d821b3d718fc86597fad95a32b12097bdc
Strange, I rebased now and did not get any merge conflicts. Anyways, just pushed a rebased version + fixes from copilot's review. |
It's not the OSS code base that had a merge conflict, but the internal codebase (which can be 10-20 commits behind main in the OSS one due to the import process). Anyway, I was able to import this morning and tests are running. For my own reference: D87349540 |
|
The internal tests pass on this, so I think we're safe to merge |
|
@metascroy has imported this pull request. If you are a Meta employee, you can view this in D87349540. |
|
Fails are unrelated to Arm changes in this PR |
cc @freddan80 @per @zingo @oscarandersson8218 @digantdesai