diff --git a/backends/arm/TARGETS b/backends/arm/TARGETS index 220db373710..39910f01503 100644 --- a/backends/arm/TARGETS +++ b/backends/arm/TARGETS @@ -8,7 +8,7 @@ python_library( typing = True, deps = [ ":arm_backend", - "//executorch/backends/arm/passes:passes", + "//executorch/backends/arm/_passes:passes", "//executorch/exir:lib", ], ) @@ -27,7 +27,7 @@ python_library( ":arm_vela", "//executorch/backends/arm/operators:lib", "//executorch/backends/arm/operators:node_visitor", - "//executorch/backends/arm/passes:passes", + "//executorch/backends/arm/_passes:passes", ], ) diff --git a/backends/arm/passes/TARGETS b/backends/arm/_passes/TARGETS similarity index 100% rename from backends/arm/passes/TARGETS rename to backends/arm/_passes/TARGETS diff --git a/backends/arm/passes/annotate_channels_last_dim_order_pass.py b/backends/arm/_passes/annotate_channels_last_dim_order_pass.py similarity index 100% rename from backends/arm/passes/annotate_channels_last_dim_order_pass.py rename to backends/arm/_passes/annotate_channels_last_dim_order_pass.py diff --git a/backends/arm/passes/arm_pass_manager.py b/backends/arm/_passes/arm_pass_manager.py similarity index 87% rename from backends/arm/passes/arm_pass_manager.py rename to backends/arm/_passes/arm_pass_manager.py index 75ef551171e..620109ef604 100644 --- a/backends/arm/passes/arm_pass_manager.py +++ b/backends/arm/_passes/arm_pass_manager.py @@ -8,13 +8,13 @@ # pyre-unsafe import torch -from executorch.backends.arm.passes.annotate_channels_last_dim_order_pass import ( +from executorch.backends.arm._passes.annotate_channels_last_dim_order_pass import ( AnnotateChannelsLastDimOrder, ) -from executorch.backends.arm.passes.convert_expand_copy_to_repeat import ( +from executorch.backends.arm._passes.convert_expand_copy_to_repeat import ( ConvertExpandCopyToRepeatPass, ) -from executorch.backends.arm.passes.convert_split_to_slice import ( +from executorch.backends.arm._passes.convert_split_to_slice import ( ConvertSplitToSlicePass, ) from executorch.backends.arm.passes.meandim_to_averagepool_pass import ( diff --git a/backends/arm/_passes/arm_pass_utils.py b/backends/arm/_passes/arm_pass_utils.py new file mode 100644 index 00000000000..34704d2cedf --- /dev/null +++ b/backends/arm/_passes/arm_pass_utils.py @@ -0,0 +1,66 @@ +# 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. + +from typing import Optional + +import torch + +from executorch.exir.dialects._ops import ops as exir_ops +from torch._ops import OpOverload + + +def create_node( + graph: torch.fx.Graph, + op_target: OpOverload, + args: tuple = (), + kwargs: Optional[dict] = None, + quantize: bool = False, + q_params: Optional[tuple] = None, +): + """ + Adds a node to 'graph'. graph.inserting_before/after() should be used before the call to decide where to insert the node. + If quantize is true and q_params is not None, a q dq pair is inserted after the newly created node. + """ + + node = graph.create_node( + "call_function", + op_target, + args=args, + kwargs=kwargs or {}, + ) + if quantize and q_params: + return insert_q_dq_pair(graph, node, q_params) + return node + + +def insert_q_dq_pair( + graph: torch.fx.Graph, + anchor: torch.fx.Node, + q_params: tuple, +): + """ + Inserts a q dq node pair after the node 'anchor'. + """ + + with graph.inserting_after(anchor): + q = create_node( + graph=graph, + op_target=exir_ops.edge.quantized_decomposed.quantize_per_tensor.default, + args=(), # We add the argument last + ) + q.meta = anchor.meta + with graph.inserting_after(q): + dq = create_node( + graph=graph, + op_target=exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default, + args=(q,) + q_params, + ) + dq.meta = q.meta + anchor.replace_all_uses_with(dq) + # We add this last so the replace all uses above does not replace the quantized + # node's first use + q.args = (anchor,) + q_params + return dq diff --git a/backends/arm/_passes/cast_int64_pass.py b/backends/arm/_passes/cast_int64_pass.py new file mode 100644 index 00000000000..6bdbca62879 --- /dev/null +++ b/backends/arm/_passes/cast_int64_pass.py @@ -0,0 +1,35 @@ +# Copyright 2024 Arm Limited and/or its affiliates. +# +# 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.pass_base import ExportPass, PassResult + + +class CastInt64ToInt32Pass(ExportPass): + def __init__(self, exported_program: torch.export.ExportedProgram): + super(CastInt64ToInt32Pass, self).__init__() + self.exported_program = exported_program + + def _to_int32(self, graph_module: torch.fx.GraphModule): + for node in graph_module.graph.nodes: + fake_tensor = node.meta["val"] + if isinstance(fake_tensor, torch._subclasses.fake_tensor.FakeTensor): + if node.meta["val"].dtype == torch.int64: + node.meta["val"] = node.meta["val"].to(torch.int32) + buffer_name = ( + self.exported_program.graph_signature.inputs_to_buffers[ + node.name + ] + ) + new_tensor = self.exported_program.state_dict[buffer_name].to( + torch.int32 + ) + self.exported_program.state_dict[buffer_name] = new_tensor + + def call(self, graph_module: torch.fx.GraphModule): + self._to_int32(graph_module) + graph_module.recompile() + graph_module = super().call(graph_module).graph_module + return PassResult(graph_module, True) diff --git a/backends/arm/passes/convert_expand_copy_to_repeat.py b/backends/arm/_passes/convert_expand_copy_to_repeat.py similarity index 100% rename from backends/arm/passes/convert_expand_copy_to_repeat.py rename to backends/arm/_passes/convert_expand_copy_to_repeat.py diff --git a/backends/arm/passes/convert_split_to_slice.py b/backends/arm/_passes/convert_split_to_slice.py similarity index 100% rename from backends/arm/passes/convert_split_to_slice.py rename to backends/arm/_passes/convert_split_to_slice.py diff --git a/backends/arm/_passes/decompose_div_pass.py b/backends/arm/_passes/decompose_div_pass.py new file mode 100644 index 00000000000..13ee8d8dff7 --- /dev/null +++ b/backends/arm/_passes/decompose_div_pass.py @@ -0,0 +1,45 @@ +# 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 + + +def get_div_decomposition(op) -> tuple: + """ + Returns the the (reciprocal_op, mul_op), where the ops depends on if + the div op is in exir_ops torch.ops.aten. + """ + if op == exir_ops.edge.aten.div.Tensor: + return (exir_ops.edge.aten.reciprocal.default, exir_ops.edge.aten.mul.Tensor) + if op == torch.ops.aten.div.Tensor: + return (torch.ops.aten.reciprocal.default, torch.ops.aten.mul.Tensor) + raise RuntimeError(f"Can't get div decomposition for op {op}") + + +class DecomposeDivPass(ExportPass): + """ + This pass decomposes div into a mul and a reciprocal node. + + Example: + y = div(a,b) + Becomes: + x = reciprocal(b) + y = mul(a,x) + """ + + def call_operator(self, op, args, kwargs, meta): + if op not in (exir_ops.edge.aten.div.Tensor, torch.ops.aten.div.Tensor): + return super().call_operator(op, args, kwargs, meta) + + reciprocal_op, mul_op = get_div_decomposition(op) + + numerator = args[0] + denominator = args[1] + reciprocal = super().call_operator(reciprocal_op, (denominator,), {}, meta) + + return super().call_operator(mul_op, (numerator, reciprocal), {}, meta) diff --git a/backends/arm/passes/meandim_to_averagepool_pass.py b/backends/arm/_passes/meandim_to_averagepool_pass.py similarity index 100% rename from backends/arm/passes/meandim_to_averagepool_pass.py rename to backends/arm/_passes/meandim_to_averagepool_pass.py diff --git a/backends/arm/passes/remove_clone_pass.py b/backends/arm/_passes/remove_clone_pass.py similarity index 100% rename from backends/arm/passes/remove_clone_pass.py rename to backends/arm/_passes/remove_clone_pass.py diff --git a/backends/arm/_passes/scalars_to_attribute_pass.py b/backends/arm/_passes/scalars_to_attribute_pass.py new file mode 100644 index 00000000000..e9e547b9c96 --- /dev/null +++ b/backends/arm/_passes/scalars_to_attribute_pass.py @@ -0,0 +1,69 @@ +# 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. + +from typing import cast, Union + +import torch +from executorch.backends.arm.tosa_mapping import extract_tensor_meta + +from executorch.exir.pass_base import ExportPass, PassResult +from torch.ao.quantization.fx.utils import get_new_attr_name_with_prefix +from torch.fx import GraphModule, Node + + +class ScalarsToAttributePass(ExportPass): + """ + For ops in 'targeted_ops', convert inputs that are scalar values + to attribute Nodes that output the same value. + """ + + targeted_ops = [ + torch.ops.aten.add.Tensor, + torch.ops.aten.sub.Tensor, + torch.ops.aten.sub_.Tensor, + torch.ops.aten.mul.Tensor, + torch.ops.aten.div.Tensor, + ] + + def call(self, graph_module: GraphModule) -> PassResult: + for n in graph_module.graph.nodes: + n = cast(Node, n) + if n.op != "call_function" or n.target not in self.targeted_ops: + continue + + biggest_rank = 1 + for arg in n.args: + if isinstance(arg, Node): + _, shape, _ = extract_tensor_meta(arg.meta) + biggest_rank = max(biggest_rank, len(shape)) + + new_args = [] + for arg in n.args: + if isinstance(arg, Node): + new_args.append(arg) + continue + + prefix = "_tensor_constant_" + get_new_attr_name = get_new_attr_name_with_prefix(prefix) + tensor_constant_name = get_new_attr_name(graph_module) + float_tensor = torch.tensor( + float(cast(Union[int, float], arg)) + ).reshape((1,) * biggest_rank) + graph_module.register_buffer(tensor_constant_name, float_tensor) + fake_mode = n.meta["val"].fake_mode + + with graph_module.graph.inserting_before(n): + get_attr_node = graph_module.graph.create_node( + "get_attr", tensor_constant_name, (), {} + ) + get_attr_node.meta["val"] = fake_mode.from_tensor( + float_tensor, static_shapes=True + ) + new_args.append(get_attr_node) + n.args = tuple(new_args) + + graph_module.recompile() + return PassResult(graph_module, True) diff --git a/backends/arm/passes/size_adjust_conv2d_pass.py b/backends/arm/_passes/size_adjust_conv2d_pass.py similarity index 100% rename from backends/arm/passes/size_adjust_conv2d_pass.py rename to backends/arm/_passes/size_adjust_conv2d_pass.py diff --git a/backends/arm/passes/tag_io_quant_pass.py b/backends/arm/_passes/tag_io_quant_pass.py similarity index 100% rename from backends/arm/passes/tag_io_quant_pass.py rename to backends/arm/_passes/tag_io_quant_pass.py diff --git a/backends/arm/arm_backend.py b/backends/arm/arm_backend.py index a5f47c222fe..c3e2e84c6ac 100644 --- a/backends/arm/arm_backend.py +++ b/backends/arm/arm_backend.py @@ -20,7 +20,9 @@ from executorch.backends.arm.operators.node_visitor import get_node_visitors from executorch.backends.arm.operators.op_output import process_output from executorch.backends.arm.operators.op_placeholder import process_placeholder -from executorch.backends.arm.passes.arm_pass_manager import ArmPassManager +from executorch.backends.arm._passes.arm_pass_manager import ( + ArmPassManager, +) # usort: skip from executorch.backends.arm.tosa_utils import ( dbg_fail, dbg_tosa_dump, diff --git a/backends/arm/arm_partitioner.py b/backends/arm/arm_partitioner.py index 6b57c3d9658..7793060f6f9 100644 --- a/backends/arm/arm_partitioner.py +++ b/backends/arm/arm_partitioner.py @@ -11,8 +11,8 @@ from typing import final, List import torch -from executorch.backends.arm.arm_backend import ArmBackend -from executorch.backends.arm.passes.tag_io_quant_pass import TagIOQuantPass +from executorch.backends.arm.arm_backend import ArmBackend # usort: skip +from executorch.backends.arm._passes.tag_io_quant_pass import TagIOQuantPass from executorch.exir.backend.compile_spec_schema import CompileSpec from executorch.exir.backend.partitioner import ( DelegationSpec, diff --git a/backends/arm/test/passes/test_meandim_to_averagepool2d.py b/backends/arm/test/passes/test_meandim_to_averagepool2d.py index 1cd63e6e52e..c8fa0f4b7ab 100644 --- a/backends/arm/test/passes/test_meandim_to_averagepool2d.py +++ b/backends/arm/test/passes/test_meandim_to_averagepool2d.py @@ -7,7 +7,7 @@ import unittest import torch -from executorch.backends.arm.passes.meandim_to_averagepool_pass import ( +from executorch.backends.arm._passes.meandim_to_averagepool_pass import ( ConvertMeanDimToAveragePool, ) diff --git a/backends/qualcomm/README.md b/backends/qualcomm/README.md index be7cd427d6e..d426aff16b1 100644 --- a/backends/qualcomm/README.md +++ b/backends/qualcomm/README.md @@ -46,7 +46,7 @@ backends/qualcomm | └── python # Python interface for using QNN libraries. ├── builders # Codes for lowering each operators (AoT Part). ├── partition # QNN Partitioner (AoT Part). -├── passes # Various passes helping lower models to QNN backend (AoT Part). +├── _passes # Various private passes helping lower models to QNN backend (AoT Part). ├── python # Places to put pybind artifacts for accessing QNN APIs, structures, etc (AoT Part). ├── quantizer # QNN Quantizer ├── runtime # Here is QNN runtime responsbile for compiling a model on x64. diff --git a/backends/qualcomm/_passes/TARGETS b/backends/qualcomm/_passes/TARGETS new file mode 100644 index 00000000000..a824ca9f6e5 --- /dev/null +++ b/backends/qualcomm/_passes/TARGETS @@ -0,0 +1,18 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +oncall("executorch") + +runtime.python_library( + name = "passes", + srcs = glob([ + "*.py", + ]), + visibility = [ + "@EXECUTORCH_CLIENTS", + ], + deps = [ + "//executorch/backends/transforms:addmm_mm_to_linear", + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + ], +) diff --git a/backends/qualcomm/passes/annotate_and_quant_scalar.py b/backends/qualcomm/_passes/annotate_and_quant_scalar.py similarity index 100% rename from backends/qualcomm/passes/annotate_and_quant_scalar.py rename to backends/qualcomm/_passes/annotate_and_quant_scalar.py diff --git a/backends/qualcomm/passes/annotate_decomposed.py b/backends/qualcomm/_passes/annotate_decomposed.py similarity index 100% rename from backends/qualcomm/passes/annotate_decomposed.py rename to backends/qualcomm/_passes/annotate_decomposed.py diff --git a/backends/qualcomm/passes/annotate_quant_attrs.py b/backends/qualcomm/_passes/annotate_quant_attrs.py similarity index 100% rename from backends/qualcomm/passes/annotate_quant_attrs.py rename to backends/qualcomm/_passes/annotate_quant_attrs.py diff --git a/backends/qualcomm/passes/build_quant_io.py b/backends/qualcomm/_passes/build_quant_io.py similarity index 100% rename from backends/qualcomm/passes/build_quant_io.py rename to backends/qualcomm/_passes/build_quant_io.py diff --git a/backends/qualcomm/passes/convert_binary_op_with_scalar.py b/backends/qualcomm/_passes/convert_binary_op_with_scalar.py similarity index 100% rename from backends/qualcomm/passes/convert_binary_op_with_scalar.py rename to backends/qualcomm/_passes/convert_binary_op_with_scalar.py diff --git a/backends/qualcomm/passes/convert_bmm_to_matmul.py b/backends/qualcomm/_passes/convert_bmm_to_matmul.py similarity index 100% rename from backends/qualcomm/passes/convert_bmm_to_matmul.py rename to backends/qualcomm/_passes/convert_bmm_to_matmul.py diff --git a/backends/qualcomm/passes/convert_interpolate_with_upsample2d.py b/backends/qualcomm/_passes/convert_interpolate_with_upsample2d.py similarity index 100% rename from backends/qualcomm/passes/convert_interpolate_with_upsample2d.py rename to backends/qualcomm/_passes/convert_interpolate_with_upsample2d.py diff --git a/backends/qualcomm/passes/convert_prelu.py b/backends/qualcomm/_passes/convert_prelu.py similarity index 100% rename from backends/qualcomm/passes/convert_prelu.py rename to backends/qualcomm/_passes/convert_prelu.py diff --git a/backends/qualcomm/passes/convert_to_linear.py b/backends/qualcomm/_passes/convert_to_linear.py similarity index 100% rename from backends/qualcomm/passes/convert_to_linear.py rename to backends/qualcomm/_passes/convert_to_linear.py diff --git a/backends/qualcomm/passes/decompose_silu.py b/backends/qualcomm/_passes/decompose_silu.py similarity index 100% rename from backends/qualcomm/passes/decompose_silu.py rename to backends/qualcomm/_passes/decompose_silu.py diff --git a/backends/qualcomm/passes/fold_qdq.py b/backends/qualcomm/_passes/fold_qdq.py similarity index 100% rename from backends/qualcomm/passes/fold_qdq.py rename to backends/qualcomm/_passes/fold_qdq.py diff --git a/backends/qualcomm/passes/fuse_consecutive_transpose.py b/backends/qualcomm/_passes/fuse_consecutive_transpose.py similarity index 100% rename from backends/qualcomm/passes/fuse_consecutive_transpose.py rename to backends/qualcomm/_passes/fuse_consecutive_transpose.py diff --git a/backends/qualcomm/passes/i64_to_i32.py b/backends/qualcomm/_passes/i64_to_i32.py similarity index 100% rename from backends/qualcomm/passes/i64_to_i32.py rename to backends/qualcomm/_passes/i64_to_i32.py diff --git a/backends/qualcomm/passes/insert_io_qdq.py b/backends/qualcomm/_passes/insert_io_qdq.py similarity index 100% rename from backends/qualcomm/passes/insert_io_qdq.py rename to backends/qualcomm/_passes/insert_io_qdq.py diff --git a/backends/qualcomm/passes/insert_requantize.py b/backends/qualcomm/_passes/insert_requantize.py similarity index 100% rename from backends/qualcomm/passes/insert_requantize.py rename to backends/qualcomm/_passes/insert_requantize.py diff --git a/backends/qualcomm/passes/layout_transform.py b/backends/qualcomm/_passes/layout_transform.py similarity index 100% rename from backends/qualcomm/passes/layout_transform.py rename to backends/qualcomm/_passes/layout_transform.py diff --git a/backends/qualcomm/passes/recompose_pixel_unshuffle.py b/backends/qualcomm/_passes/recompose_pixel_unshuffle.py similarity index 100% rename from backends/qualcomm/passes/recompose_pixel_unshuffle.py rename to backends/qualcomm/_passes/recompose_pixel_unshuffle.py diff --git a/backends/qualcomm/passes/recompose_rms_norm.py b/backends/qualcomm/_passes/recompose_rms_norm.py similarity index 100% rename from backends/qualcomm/passes/recompose_rms_norm.py rename to backends/qualcomm/_passes/recompose_rms_norm.py diff --git a/backends/qualcomm/passes/reduce_dynamic_range.py b/backends/qualcomm/_passes/reduce_dynamic_range.py similarity index 100% rename from backends/qualcomm/passes/reduce_dynamic_range.py rename to backends/qualcomm/_passes/reduce_dynamic_range.py diff --git a/backends/qualcomm/passes/remove_redundancy.py b/backends/qualcomm/_passes/remove_redundancy.py similarity index 100% rename from backends/qualcomm/passes/remove_redundancy.py rename to backends/qualcomm/_passes/remove_redundancy.py diff --git a/backends/qualcomm/passes/replace_index_put_input.py b/backends/qualcomm/_passes/replace_index_put_input.py similarity index 100% rename from backends/qualcomm/passes/replace_index_put_input.py rename to backends/qualcomm/_passes/replace_index_put_input.py diff --git a/backends/qualcomm/passes/replace_inf_buffer.py b/backends/qualcomm/_passes/replace_inf_buffer.py similarity index 100% rename from backends/qualcomm/passes/replace_inf_buffer.py rename to backends/qualcomm/_passes/replace_inf_buffer.py diff --git a/backends/qualcomm/passes/utils.py b/backends/qualcomm/_passes/utils.py similarity index 100% rename from backends/qualcomm/passes/utils.py rename to backends/qualcomm/_passes/utils.py diff --git a/backends/qualcomm/qnn_preprocess.py b/backends/qualcomm/qnn_preprocess.py index 6360b35280f..417934acbd4 100644 --- a/backends/qualcomm/qnn_preprocess.py +++ b/backends/qualcomm/qnn_preprocess.py @@ -11,15 +11,15 @@ import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager import torch # noqa: F401 -from executorch.backends.qualcomm.builders.node_visitor import get_node_visitors -from executorch.backends.qualcomm.builders.qnn_constants import OpContextLoader -from executorch.backends.qualcomm.passes.convert_to_linear import ConvertToLinear -from executorch.backends.qualcomm.passes.fuse_consecutive_transpose import ( +from executorch.backends.qualcomm._passes.convert_to_linear import ConvertToLinear +from executorch.backends.qualcomm._passes.fuse_consecutive_transpose import ( FuseConsecutiveTranspose, ) -from executorch.backends.qualcomm.passes.insert_io_qdq import InsertIOQDQ -from executorch.backends.qualcomm.passes.insert_requantize import InsertRequantize -from executorch.backends.qualcomm.passes.layout_transform import LayoutTransform +from executorch.backends.qualcomm._passes.insert_io_qdq import InsertIOQDQ +from executorch.backends.qualcomm._passes.insert_requantize import InsertRequantize +from executorch.backends.qualcomm._passes.layout_transform import LayoutTransform +from executorch.backends.qualcomm.builders.node_visitor import get_node_visitors +from executorch.backends.qualcomm.builders.qnn_constants import OpContextLoader from executorch.backends.qualcomm.utils.utils import generate_qnn_executorch_option from executorch.exir.backend.backend_details import ( BackendDetails, diff --git a/backends/qualcomm/quantizer/quantizer.py b/backends/qualcomm/quantizer/quantizer.py index e27edf939c8..b479d79ab89 100644 --- a/backends/qualcomm/quantizer/quantizer.py +++ b/backends/qualcomm/quantizer/quantizer.py @@ -7,12 +7,12 @@ from typing import Callable, Dict, Optional, Sequence, Set import torch -from executorch.backends.qualcomm.passes.decompose_silu import DecomposeSilu -from executorch.backends.qualcomm.passes.recompose_pixel_unshuffle import ( +from executorch.backends.qualcomm._passes.decompose_silu import DecomposeSilu +from executorch.backends.qualcomm._passes.recompose_pixel_unshuffle import ( RecomposePixelUnshuffle, ) -from executorch.backends.qualcomm.passes.reduce_dynamic_range import ReduceDynamicRange -from executorch.backends.qualcomm.passes.replace_inf_buffer import ReplaceInfBuffer +from executorch.backends.qualcomm._passes.reduce_dynamic_range import ReduceDynamicRange +from executorch.backends.qualcomm._passes.replace_inf_buffer import ReplaceInfBuffer from executorch.backends.transforms.decompose_sdpa import ( DecomposeScaledDotProductAttention, ) diff --git a/backends/qualcomm/utils/constants.py b/backends/qualcomm/utils/constants.py index 9875c9f5afb..4787e89ca64 100644 --- a/backends/qualcomm/utils/constants.py +++ b/backends/qualcomm/utils/constants.py @@ -6,7 +6,7 @@ # Qualcomm specific key -# constants in backends/qualcomm/passes & backends/qualcomm/builders +# constants in backends/qualcomm/_passes & backends/qualcomm/builders QCOM_AXIS = "axis" QCOM_AXIS_ORDER = "axis_order" QCOM_BITWIDTH = "bitwidth" diff --git a/backends/qualcomm/utils/utils.py b/backends/qualcomm/utils/utils.py index e1be24d0d64..4509843abac 100644 --- a/backends/qualcomm/utils/utils.py +++ b/backends/qualcomm/utils/utils.py @@ -14,37 +14,42 @@ import executorch.exir as exir import torch - -from executorch.backends.qualcomm.builders.node_visitor import ( - QNN_QUANT_TYPE_MAP, - QNN_TENSOR_TYPE_MAP, -) -from executorch.backends.qualcomm.builders.qnn_constants import OpContextLoader -from executorch.backends.qualcomm.passes.annotate_and_quant_scalar import ( +from executorch.backends.qualcomm._passes.annotate_and_quant_scalar import ( AnnotateAndQuantScalar, ) -from executorch.backends.qualcomm.passes.annotate_decomposed import AnnotateDecomposed -from executorch.backends.qualcomm.passes.annotate_quant_attrs import AnnotateQuantAttrs -from executorch.backends.qualcomm.passes.convert_binary_op_with_scalar import ( +from executorch.backends.qualcomm._passes.annotate_decomposed import AnnotateDecomposed +from executorch.backends.qualcomm._passes.annotate_quant_attrs import AnnotateQuantAttrs +from executorch.backends.qualcomm._passes.convert_binary_op_with_scalar import ( ConvertBinaryOpsWithScalar, ) -from executorch.backends.qualcomm.passes.convert_bmm_to_matmul import ConvertBmmToMatmul -from executorch.backends.qualcomm.passes.convert_interpolate_with_upsample2d import ( +from executorch.backends.qualcomm._passes.convert_bmm_to_matmul import ( + ConvertBmmToMatmul, +) +from executorch.backends.qualcomm._passes.convert_interpolate_with_upsample2d import ( ConvertInterpolateWithUpsample2D, ) -from executorch.backends.qualcomm.passes.convert_prelu import ConvertPReLU -from executorch.backends.qualcomm.passes.convert_to_linear import ConvertToLinear -from executorch.backends.qualcomm.passes.fold_qdq import FoldQDQ -from executorch.backends.qualcomm.passes.i64_to_i32 import I64toI32 -from executorch.backends.qualcomm.passes.layout_transform import LayoutTransform -from executorch.backends.qualcomm.passes.recompose_pixel_unshuffle import ( +from executorch.backends.qualcomm._passes.convert_prelu import ConvertPReLU +from executorch.backends.qualcomm._passes.convert_to_linear import ConvertToLinear +from executorch.backends.qualcomm._passes.fold_qdq import FoldQDQ +from executorch.backends.qualcomm._passes.i64_to_i32 import I64toI32 +from executorch.backends.qualcomm._passes.layout_transform import LayoutTransform +from executorch.backends.qualcomm._passes.recompose_pixel_unshuffle import ( RecomposePixelUnshuffle, ) -from executorch.backends.qualcomm.passes.recompose_rms_norm import RecomposeRmsNorm -from executorch.backends.qualcomm.passes.remove_redundancy import RemoveRedundancy -from executorch.backends.qualcomm.passes.replace_index_put_input import ( +from executorch.backends.qualcomm._passes.recompose_rms_norm import RecomposeRmsNorm +from executorch.backends.qualcomm._passes.remove_redundancy import RemoveRedundancy +from executorch.backends.qualcomm._passes.replace_index_put_input import ( ReplaceIndexPutInput, ) + +from executorch.backends.qualcomm.builders.node_visitor import ( + QNN_QUANT_TYPE_MAP, + QNN_TENSOR_TYPE_MAP, +) +from executorch.backends.qualcomm.builders.qnn_constants import OpContextLoader +from executorch.backends.qualcomm.passes.expand_broadcast_tensor_shape import ( + ExpandBroadcastTensorShape, +) from executorch.backends.qualcomm.serialization.qnn_compile_spec_schema import ( _soc_info_table, QcomChipset, diff --git a/examples/qualcomm/oss_scripts/llama2/llama.py b/examples/qualcomm/oss_scripts/llama2/llama.py index 9712b1c08fd..cd7ec24d3a7 100644 --- a/examples/qualcomm/oss_scripts/llama2/llama.py +++ b/examples/qualcomm/oss_scripts/llama2/llama.py @@ -12,9 +12,9 @@ from multiprocessing.connection import Client import torch +from executorch.backends.qualcomm._passes.build_quant_io import BuildQuantIo from executorch.backends.qualcomm.partition.qnn_partitioner import QnnPartitioner -from executorch.backends.qualcomm.passes.build_quant_io import BuildQuantIo from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype from executorch.backends.qualcomm.serialization.qnn_compile_spec_schema import (