-
Notifications
You must be signed in to change notification settings - Fork 713
Add ArmPassManager #3749
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
Closed
Closed
Add ArmPassManager #3749
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9175a43
Add ArmPassManager
oscarandersson8218 7e7c6be
ArmPassManager fixes
oscarandersson8218 39d9538
Address review comments for ArmPassManager
oscarandersson8218 ca57e95
Merge remote-tracking branch 'origin/upstream/main' into HEAD
oscarandersson8218 2bde11e
Pass quantize_io flag to get_u55_compile_spec
oscarandersson8218 c233860
Merge remote-tracking branch 'origin/upstream/main' into HEAD
oscarandersson8218 a9c550b
Restore call to TagIOQuantPass
oscarandersson8218 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # Copyright 2024 Arm Limited and/or its affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import torch | ||
| from executorch.backends.arm.passes.remove_clone_pass import RemoveClonePass | ||
| from executorch.exir.backend.compile_spec_schema import CompileSpec | ||
| from executorch.exir.pass_manager import PassManager | ||
|
|
||
|
|
||
| class ArmPassManager(PassManager): | ||
|
|
||
| def _transform(self, graph_module: torch.fx.Graph): | ||
| return self(graph_module).graph_module | ||
|
|
||
| def transform_to_backend_pipeline( | ||
| self, graph_module: torch.fx.Graph, compile_spec: CompileSpec | ||
| ): | ||
| """Apply passes before transforming program to backend""" | ||
| self.add_pass(RemoveClonePass()) | ||
|
|
||
| return self._transform(graph_module) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright 2024 Arm Limited and/or its affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import torch | ||
| from executorch.exir.dialects._ops import ops as exir_ops | ||
| from executorch.exir.pass_base import ExportPass, PassResult | ||
|
|
||
|
|
||
| class RemoveClonePass(ExportPass): | ||
|
|
||
| def call(self, graph_module: torch.fx.GraphModule): | ||
| for node in graph_module.graph.nodes: | ||
| if node.op != "call_function": | ||
| continue | ||
| if node.target == exir_ops.edge.aten.clone.default: | ||
| for user in list(node.users): | ||
| # TODO remove dq/q-ops around removed clone-op | ||
| user.replace_input_with(node, node.args[0]) | ||
| graph_module.graph.erase_node(node) | ||
| graph_module.graph.eliminate_dead_code() | ||
| graph_module.recompile() | ||
| return PassResult(graph_module, True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2024 Arm Limited and/or its affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import torch | ||
| from executorch.exir.dialects._ops import ops as exir_ops | ||
| from executorch.exir.pass_base import ExportPass, PassResult | ||
|
|
||
|
|
||
| class TagIOQuantPass(ExportPass): | ||
| """ | ||
| Pass run before partitioning to tag Q/DQ on any placeholder and output | ||
| to ensure we don't greedily partition them for device. Float conversion | ||
| has to happen outside a TOSA base inference profile. | ||
| """ | ||
|
|
||
| def is_quant_node(self, node: torch.fx.node.Node): | ||
| return node.target in { | ||
| exir_ops.edge.quantized_decomposed.quantize_per_channel.default, | ||
| exir_ops.edge.quantized_decomposed.quantize_per_tensor.default, | ||
| exir_ops.edge.quantized_decomposed.quantize_per_tensor.tensor, | ||
| } | ||
|
|
||
| def is_dequant_node(self, node: torch.fx.node.Node): | ||
| return node.target in { | ||
| exir_ops.edge.quantized_decomposed.dequantize_per_channel.default, | ||
| exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default, | ||
| exir_ops.edge.quantized_decomposed.dequantize_per_tensor.tensor, | ||
| } | ||
|
|
||
| def call(self, graph_module: torch.fx.GraphModule): | ||
| for node in graph_module.graph.nodes: | ||
| # tag q of input | ||
| if node.op == "placeholder": | ||
| for user in node.users.keys(): | ||
| # if we have an input going into a quantize | ||
| if self.is_quant_node(user): | ||
| user.meta["arm_override_partition"] = False | ||
|
|
||
| # tag dq of outputs | ||
| if node.op == "output": | ||
| quant, *_ = node.args[0] | ||
| if self.is_dequant_node(quant): | ||
| quant.meta["arm_override_partition"] = False | ||
|
|
||
| graph_module.recompile() | ||
| return PassResult(graph_module, True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Copyright 2024 Arm Limited and/or its affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.arm.test import common | ||
| from executorch.backends.arm.test.tester.arm_tester import ArmTester | ||
|
|
||
|
|
||
| class Add(torch.nn.Module): | ||
|
|
||
| def get_inputs(self): | ||
| return (torch.rand(1, 10, 10, 10),) | ||
|
|
||
| def forward(self, x): | ||
| return x + x | ||
|
|
||
|
|
||
| class TestTagIOQuantPass(unittest.TestCase): | ||
|
|
||
| def _tosa_BI_u55_pipeline(self, module: torch.nn.Module): | ||
| ( | ||
| ArmTester( | ||
| module, | ||
| example_inputs=module.get_inputs(), | ||
| compile_spec=common.get_u55_compile_spec(quantize_io=True), | ||
| ) | ||
| .quantize() | ||
| .export() | ||
| .to_edge() | ||
| .check_count( | ||
| { | ||
| "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor_default": 2 | ||
| } | ||
| ) | ||
| .check_count( | ||
| { | ||
| "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default": 2 | ||
| } | ||
| ) | ||
| .partition() | ||
| .check_count( | ||
| { | ||
| "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor_default": 1 | ||
| } | ||
| ) | ||
| .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) | ||
| .check_count( | ||
| { | ||
| "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default": 1 | ||
| } | ||
| ) | ||
| # .to_executorch() requires additional steps | ||
| ) | ||
|
|
||
| def test_BI_u55_artifact(self): | ||
| model = Add() | ||
| self._tosa_BI_u55_pipeline(model) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.