diff --git a/.lintrunner.toml b/.lintrunner.toml index dd75ea8f323..08e732f36db 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -291,6 +291,7 @@ code = 'MYPY' include_patterns = [ # TODO(https://github.com/pytorch/executorch/issues/7441): Gradually start enabling all folders. # 'backends/**/*.py', + 'backends/arm/**/*.py', 'build/**/*.py', 'codegen/**/*.py', # 'devtools/**/*.py', @@ -312,6 +313,7 @@ exclude_patterns = [ '**/third-party/**', 'scripts/check_binary_dependencies.py', 'profiler/test/test_profiler_e2e.py', + 'backends/arm/test/**', ] command = [ 'python', diff --git a/backends/arm/_passes/annotate_channels_last_dim_order_pass.py b/backends/arm/_passes/annotate_channels_last_dim_order_pass.py index a3d168fb870..18bc1c2af69 100644 --- a/backends/arm/_passes/annotate_channels_last_dim_order_pass.py +++ b/backends/arm/_passes/annotate_channels_last_dim_order_pass.py @@ -209,7 +209,7 @@ def call(self, graph_module: torch.fx.GraphModule): # dim_order = (2, 3, 0, 1) (https://www.mlplatform.org/tosa/tosa_spec.html#_depthwise_conv2d). dim_order = self.HWCM_order else: - dim_order = tuple(range(node_data.dim())) + dim_order = tuple(range(node_data.dim())) # type: ignore[assignment] node.meta["tosa_dim_order"] = dim_order # Take care of cases when: # 4D (NHWC) -> >4D (NCH) diff --git a/backends/arm/_passes/arm_pass_manager.py b/backends/arm/_passes/arm_pass_manager.py index 9bac3b037cd..2edbaafcb77 100644 --- a/backends/arm/_passes/arm_pass_manager.py +++ b/backends/arm/_passes/arm_pass_manager.py @@ -21,7 +21,7 @@ from executorch.backends.arm._passes.convert_split_to_slice import ( ConvertSplitToSlicePass, ) -from executorch.backends.arm._passes.convert_squeezes_to_view import ( +from executorch.backends.arm._passes.convert_squeezes_to_view import ( # type: ignore[import-not-found] ConvertSqueezesToViewPass, ) from executorch.backends.arm._passes.decompose_div_pass import DecomposeDivPass @@ -30,7 +30,9 @@ ) from executorch.backends.arm._passes.decompose_linear_pass import DecomposeLinearPass from executorch.backends.arm._passes.decompose_meandim_pass import DecomposeMeanDimPass -from executorch.backends.arm._passes.decompose_select import DecomposeSelectPass +from executorch.backends.arm._passes.decompose_select import ( # type: ignore[import-not-found] + DecomposeSelectPass, +) from executorch.backends.arm._passes.decompose_softmaxes_pass import ( DecomposeSoftmaxesPass, ) @@ -40,7 +42,7 @@ QuantizeFullArgument, RetraceFoldedDtypesPass, ) -from executorch.backends.arm._passes.fuse_quantized_activation_pass import ( +from executorch.backends.arm._passes.fuse_quantized_activation_pass import ( # type: ignore[import-not-found] FuseQuantizedActivationPass, ) from executorch.backends.arm._passes.insert_table_ops import InsertTableOpsPass @@ -48,10 +50,12 @@ KeepDimsFalseToSqueezePass, ) from executorch.backends.arm._passes.match_arg_ranks_pass import MatchArgRanksPass -from executorch.backends.arm._passes.meandim_to_averagepool_pass import ( +from executorch.backends.arm._passes.meandim_to_averagepool_pass import ( # type: ignore[attr-defined] ConvertMeanDimToAveragePoolPass, ) -from executorch.backends.arm._passes.mm_to_bmm_pass import ConvertMmToBmmPass +from executorch.backends.arm._passes.mm_to_bmm_pass import ( # type: ignore[import-not-found] + ConvertMmToBmmPass, +) from executorch.backends.arm._passes.remove_clone_pass import RemoveClonePass from executorch.backends.arm._passes.scalars_to_attribute_pass import ( ScalarsToAttributePass, @@ -89,7 +93,7 @@ def _tosa_080_BI_pipeline(self, exported_program: ExportedProgram) -> GraphModul self.add_pass(AnnotateDecomposedMatmulPass()) self.add_pass(QuantizeFullArgument()) - self.add_pass(FoldAndAnnotateQParamsPass()) + self.add_pass(FoldAndAnnotateQParamsPass()) # type: ignore[call-arg] self.add_pass(RetraceFoldedDtypesPass()) self.add_pass(InsertTableOpsPass(exported_program)) @@ -125,7 +129,7 @@ def _tosa_080_MI_pipeline(self, exported_program: ExportedProgram) -> GraphModul self.add_pass(AnnotateDecomposedMatmulPass()) self.add_pass(QuantizeFullArgument()) - self.add_pass(FoldAndAnnotateQParamsPass()) + self.add_pass(FoldAndAnnotateQParamsPass()) # type: ignore[call-arg] self.add_pass(RetraceFoldedDtypesPass()) self.add_pass(InsertTableOpsPass(exported_program)) diff --git a/backends/arm/_passes/arm_pass_utils.py b/backends/arm/_passes/arm_pass_utils.py index 7377d401aba..cb43acc7fdb 100644 --- a/backends/arm/_passes/arm_pass_utils.py +++ b/backends/arm/_passes/arm_pass_utils.py @@ -1,5 +1,5 @@ # Copyright (c) Meta Platforms, Inc. and affiliates. -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -58,9 +58,9 @@ def get_param_tensor( elif is_get_attr_node(node): # This is a hack to support both lifted and unlifted graph try: - return getattr(node.graph.owning_module, node.target) + return getattr(node.graph.owning_module, node.target) # type: ignore[arg-type] except AttributeError: - return getattr(exp_prog.graph_module, node.target) + return getattr(exp_prog.graph_module, node.target) # type: ignore[arg-type] raise RuntimeError(f"unsupported param type, {node.op}.") @@ -156,7 +156,7 @@ def get_node_arg(args: list | dict, key: int | str | type, default_value=None): f"Out of bounds index {key} for getting value in args (of size {len(args)})" ) elif isinstance(key, str): - return args.get(key, default_value) # pyre-ignore[16] + return args.get(key, default_value) # type: ignore[union-attr] # pyre-ignore[16] elif isclass(key): for arg in args: if isinstance(arg, key): diff --git a/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py b/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py index b1e680b7bca..683e3969e79 100644 --- a/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py +++ b/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py @@ -134,7 +134,7 @@ def fold_and_annotate_arg( node.meta["input_qparams"][i] = input_qparams for n in nodes_to_remove: assert n.target == dq_op - n.replace_all_uses_with(n.args[0]) + n.replace_all_uses_with(n.args[0]) # type: ignore[arg-type] graph_module.graph.erase_node(n) def call(self, graph_module: GraphModule) -> PassResult: diff --git a/backends/arm/_passes/keep_dims_false_to_squeeze_pass.py b/backends/arm/_passes/keep_dims_false_to_squeeze_pass.py index f4d369a5040..ad95379cc87 100644 --- a/backends/arm/_passes/keep_dims_false_to_squeeze_pass.py +++ b/backends/arm/_passes/keep_dims_false_to_squeeze_pass.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -66,7 +66,7 @@ def call(self, graph_module: torch.fx.GraphModule): sum_node = cast(torch.fx.Node, node) keep_dim = get_node_arg( # pyre-ignore[6] - sum_node.args, + sum_node.args, # type: ignore[arg-type] keep_dim_index, False, ) @@ -74,7 +74,7 @@ def call(self, graph_module: torch.fx.GraphModule): if keep_dim: continue - dim_list = get_node_arg(sum_node.args, 1, [0]) # pyre-ignore[6] + dim_list = get_node_arg(sum_node.args, 1, [0]) # type: ignore[arg-type] # pyre-ignore[6] # Add keep_dim = True arg to sum node. set_node_arg(sum_node, 2, True) diff --git a/backends/arm/_passes/scalars_to_attribute_pass.py b/backends/arm/_passes/scalars_to_attribute_pass.py index f6fe02b6ebc..78865fe33ff 100644 --- a/backends/arm/_passes/scalars_to_attribute_pass.py +++ b/backends/arm/_passes/scalars_to_attribute_pass.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -54,7 +54,7 @@ def call(self, graph_module: GraphModule) -> PassResult: if isinstance(arg, int) and not torch.is_floating_point( get_first_fake_tensor(n) ): - new_args.append(arg) + new_args.append(arg) # type: ignore[arg-type] continue prefix = "_tensor_constant_" diff --git a/backends/arm/arm_backend.py b/backends/arm/arm_backend.py index d695aec2fd8..899bafcf04c 100644 --- a/backends/arm/arm_backend.py +++ b/backends/arm/arm_backend.py @@ -15,7 +15,7 @@ import os from typing import cast, final, List, Optional -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.arm_vela import vela_compile from executorch.backends.arm.operators.node_visitor import get_node_visitors @@ -230,7 +230,7 @@ def preprocess( # noqa: C901 # Converted output for this subgraph, serializer needs path early as it emits # const data directly. Path created and data written only in debug builds. tosa_graph = ts.TosaSerializer(artifact_path) - graph_module = ArmPassManager(tosa_spec).transform_to_backend_pipeline( + graph_module = ArmPassManager(tosa_spec).transform_to_backend_pipeline( # type: ignore exported_program=edge_program ) diff --git a/backends/arm/arm_partitioner.py b/backends/arm/arm_partitioner.py index cc4058c4c52..b956d65db58 100644 --- a/backends/arm/arm_partitioner.py +++ b/backends/arm/arm_partitioner.py @@ -10,7 +10,7 @@ from typing import Callable, final, List, Optional, Tuple import torch -from executorch.backends.arm.arm_backend import ( +from executorch.backends.arm.arm_backend import ( # type: ignore[attr-defined] ArmBackend, ) # usort: skip from executorch.backends.arm.operator_support.tosa_supported_operators import ( diff --git a/backends/arm/arm_vela.py b/backends/arm/arm_vela.py index 918d95ba379..ef0336147af 100644 --- a/backends/arm/arm_vela.py +++ b/backends/arm/arm_vela.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -12,7 +12,7 @@ from typing import List import numpy as np -from ethosu.vela import vela +from ethosu.vela import vela # type: ignore # Pack either input or output tensor block, compose the related arrays into @@ -96,13 +96,13 @@ def vela_compile(tosa_graph, args: List[str], shape_order=None): block_name = block_name + b"\x00" * (16 - len(block_name)) # We need the acual unpadded block lengths for hw setup - block_length = struct.pack(" bool if input_dtype not in supported_dtypes: logger.info( f"Input dtype {input_val.dtype} is not supported in " - f"{node.target.name()}." # pyre-ignore[16] + f"{node.target.name()}." # type: ignore[union-attr] # pyre-ignore[16] ) return False @@ -107,7 +107,7 @@ def is_node_supported(self, node: fx.Node, tosa_spec: TosaSpecification) -> bool if output_val.dtype not in supported_dtypes[input_dtype]: logger.info( f"Output dtype {output_val.dtype} is not supported in " - f"{node.target.name()} for input dtype {input_dtype}. " # pyre-ignore[16] + f"{node.target.name()} for input dtype {input_dtype}. " # type: ignore[union-attr] # pyre-ignore[16] f"Supported output types: " f"{''.join(str(t) for t in supported_dtypes[input_dtype])}" ) @@ -118,7 +118,7 @@ def is_node_supported(self, node: fx.Node, tosa_spec: TosaSpecification) -> bool if node.kwargs["memory_format"] in (torch.preserve_format,): logger.info( f"Argument 'memory_format' is not supported for " - f"{node.target.name()} right now." # pyre-ignore[16] + f"{node.target.name()} right now." # type: ignore[union-attr] # pyre-ignore[16] ) return False @@ -126,10 +126,10 @@ def is_node_supported(self, node: fx.Node, tosa_spec: TosaSpecification) -> bool if "dim_order" in node.kwargs: dim_order = node.kwargs["dim_order"] # pyre-ignore[6] - if dim_order != list(range(len(dim_order))): + if dim_order != list(range(len(dim_order))): # type: ignore[arg-type] logger.info( f"Argument {dim_order=} is not supported for " - f"{node.target.name()} right now." # pyre-ignore[16] + f"{node.target.name()} right now." # type: ignore[union-attr] # pyre-ignore[16] ) return False diff --git a/backends/arm/operator_support/tosa_supported_operators.py b/backends/arm/operator_support/tosa_supported_operators.py index c3102a86a48..68c9843e52e 100644 --- a/backends/arm/operator_support/tosa_supported_operators.py +++ b/backends/arm/operator_support/tosa_supported_operators.py @@ -137,5 +137,5 @@ def is_node_supported(self, submodules, node: fx.Node) -> bool: def is_node_supported_custom(self, node: fx.Node) -> bool: tosa_checks = get_registered_tosa_support_checks(self.tosa_spec) if node.target in tosa_checks.keys(): - return tosa_checks[node.target].is_node_supported(node, self.tosa_spec) + return tosa_checks[node.target].is_node_supported(node, self.tosa_spec) # type: ignore[index] return False diff --git a/backends/arm/operators/node_visitor.py b/backends/arm/operators/node_visitor.py index 8609e5e3918..b8fd09ea98c 100644 --- a/backends/arm/operators/node_visitor.py +++ b/backends/arm/operators/node_visitor.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -7,7 +7,7 @@ from typing import Dict, List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.tosa_mapping import TosaArg from executorch.backends.arm.tosa_specification import TosaSpecification @@ -44,7 +44,7 @@ def define_node( # container for all node visitors -_node_visitor_dicts = { +_node_visitor_dicts = { # type: ignore[var-annotated] TosaSpecification.create_from_string("TOSA-0.80+BI"): {}, TosaSpecification.create_from_string("TOSA-0.80+MI"): {}, } diff --git a/backends/arm/operators/op_add.py b/backends/arm/operators/op_add.py index 74f00354edf..ccdeb2c1bcf 100644 --- a/backends/arm/operators/op_add.py +++ b/backends/arm/operators/op_add.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -10,7 +10,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils import executorch.backends.arm.tosa_utils as tutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, @@ -75,7 +75,7 @@ def define_node( if output.dtype == ts.DType.INT8: # Scale output back to 8 bit # pyre-ignore - tqutils.insert_rescale_op_to_int8(tosa_graph, add_output, scale_back, node) + tqutils.insert_rescale_op_to_int8(tosa_graph, add_output, scale_back, node) # type: ignore[possibly-undefined] @register_node_visitor diff --git a/backends/arm/operators/op_avg_pool2d.py b/backends/arm/operators/op_avg_pool2d.py index fecddac6591..e300b3ed016 100644 --- a/backends/arm/operators/op_avg_pool2d.py +++ b/backends/arm/operators/op_avg_pool2d.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch # pyre-fixme[21]: ' Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass` diff --git a/backends/arm/operators/op_batch_norm.py b/backends/arm/operators/op_batch_norm.py index ce5998cb721..dc423d0b4a2 100644 --- a/backends/arm/operators/op_batch_norm.py +++ b/backends/arm/operators/op_batch_norm.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_bmm.py b/backends/arm/operators/op_bmm.py index 83d3df27014..d3261ebde0c 100644 --- a/backends/arm/operators/op_bmm.py +++ b/backends/arm/operators/op_bmm.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -7,7 +7,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' @@ -75,14 +75,14 @@ def define_node( if output.dtype == ts.DType.INT8: output_qparams = get_output_qparams(node)[0] # pyre-ignore[16] final_output_scale = ( - input_qparams[0].scale * input_qparams[1].scale # pyre-ignore[61] + input_qparams[0].scale * input_qparams[1].scale # type: ignore[possibly-undefined] # pyre-ignore[61] ) / output_qparams.scale build_rescale( tosa_fb=tosa_graph, scale=final_output_scale, # pyre-ignore[61]: Uninitialized local [61]: Local variable `bmm_result` is undefined, or not always defined. - input_node=bmm_result, + input_node=bmm_result, # type: ignore[possibly-undefined] output_name=output.name, output_type=ts.DType.INT8, output_shape=bmm_result.shape, diff --git a/backends/arm/operators/op_cat.py b/backends/arm/operators/op_cat.py index e249942d0b7..f786395cc39 100644 --- a/backends/arm/operators/op_cat.py +++ b/backends/arm/operators/op_cat.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -7,7 +7,7 @@ from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_conv2d.py b/backends/arm/operators/op_conv2d.py index 42156da0132..f97e408a02a 100644 --- a/backends/arm/operators/op_conv2d.py +++ b/backends/arm/operators/op_conv2d.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' @@ -165,13 +165,13 @@ def define_node( # integer value domain of the next op. Otherwise return float32 output. if inputs[0].dtype == ts.DType.INT8: # Get scale_factor from input, weight, and output. - input_scale = input_qparams[0].scale # pyre-ignore [61] + input_scale = input_qparams[0].scale # type: ignore[possibly-undefined] # pyre-ignore [61] weight_scale = input_qparams[1].scale # pyre-ignore [61] output_qargs = get_output_qparams(node) # pyre-ignore [16] build_rescale_conv_output( tosa_graph, # pyre-fixme[61]: Uninitialized local [61]: Local variable `conv2d_res` is undefined, or not always defined. - conv2d_res, + conv2d_res, # type: ignore[possibly-undefined] output.name, output.dtype, input_scale, diff --git a/backends/arm/operators/op_eq.py b/backends/arm/operators/op_eq.py index e6e2492aec0..02fc89099e0 100644 --- a/backends/arm/operators/op_eq.py +++ b/backends/arm/operators/op_eq.py @@ -9,7 +9,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_exp.py b/backends/arm/operators/op_exp.py index 46f49809750..4b8232ef6e7 100644 --- a/backends/arm/operators/op_exp.py +++ b/backends/arm/operators/op_exp.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_full.py b/backends/arm/operators/op_full.py index 7964e58226c..f06b9873e63 100644 --- a/backends/arm/operators/op_full.py +++ b/backends/arm/operators/op_full.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -8,7 +8,7 @@ import numpy as np -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, @@ -40,7 +40,7 @@ def define_node( if output.dtype == ts.DType.INT8: fill_dtype = np.int8 else: - fill_dtype = np.float32 + fill_dtype = np.float32 # type: ignore[assignment] data = np.full(shape, value, dtype=fill_dtype) tosa_graph.addConst(shape, output.dtype, data, node.name + "full-const") diff --git a/backends/arm/operators/op_ge.py b/backends/arm/operators/op_ge.py index 810b40bb1ad..e4de12f3327 100644 --- a/backends/arm/operators/op_ge.py +++ b/backends/arm/operators/op_ge.py @@ -9,7 +9,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_get_item.py b/backends/arm/operators/op_get_item.py index f7372262c6e..577a8c8d2ea 100644 --- a/backends/arm/operators/op_get_item.py +++ b/backends/arm/operators/op_get_item.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_gt.py b/backends/arm/operators/op_gt.py index 7a22db66862..65cf8197bdc 100644 --- a/backends/arm/operators/op_gt.py +++ b/backends/arm/operators/op_gt.py @@ -9,7 +9,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_hardtanh.py b/backends/arm/operators/op_hardtanh.py index c971b50b665..fc0ee552a9f 100644 --- a/backends/arm/operators/op_hardtanh.py +++ b/backends/arm/operators/op_hardtanh.py @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' diff --git a/backends/arm/operators/op_le.py b/backends/arm/operators/op_le.py index ee6929617e4..8fea2b92088 100644 --- a/backends/arm/operators/op_le.py +++ b/backends/arm/operators/op_le.py @@ -9,7 +9,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_log.py b/backends/arm/operators/op_log.py index 868eeb94431..7f664900b31 100644 --- a/backends/arm/operators/op_log.py +++ b/backends/arm/operators/op_log.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_lt.py b/backends/arm/operators/op_lt.py index 20bac97af48..da93ab41799 100644 --- a/backends/arm/operators/op_lt.py +++ b/backends/arm/operators/op_lt.py @@ -9,7 +9,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_max.py b/backends/arm/operators/op_max.py index 660a2cf0afd..35a635de137 100644 --- a/backends/arm/operators/op_max.py +++ b/backends/arm/operators/op_max.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -8,7 +8,7 @@ from typing import List import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' from executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass import ( diff --git a/backends/arm/operators/op_max_pool2d.py b/backends/arm/operators/op_max_pool2d.py index 6cb5f0490e9..f32300f561d 100644 --- a/backends/arm/operators/op_max_pool2d.py +++ b/backends/arm/operators/op_max_pool2d.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' diff --git a/backends/arm/operators/op_min.py b/backends/arm/operators/op_min.py index 2282d9e1cf1..a409acf1ae8 100644 --- a/backends/arm/operators/op_min.py +++ b/backends/arm/operators/op_min.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -9,7 +9,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' from executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass import ( diff --git a/backends/arm/operators/op_mul.py b/backends/arm/operators/op_mul.py index c6a315d4452..ef886de11e8 100644 --- a/backends/arm/operators/op_mul.py +++ b/backends/arm/operators/op_mul.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -10,7 +10,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils import executorch.backends.arm.tosa_utils as tutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' diff --git a/backends/arm/operators/op_permute.py b/backends/arm/operators/op_permute.py index 16d3d4a04e0..103ae1b9a2f 100644 --- a/backends/arm/operators/op_permute.py +++ b/backends/arm/operators/op_permute.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -7,7 +7,7 @@ from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_reciprocal.py b/backends/arm/operators/op_reciprocal.py index 121b78fed6f..5410e1dd99a 100644 --- a/backends/arm/operators/op_reciprocal.py +++ b/backends/arm/operators/op_reciprocal.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_relu.py b/backends/arm/operators/op_relu.py index b5ffa2aa70c..c37e4b3e75d 100644 --- a/backends/arm/operators/op_relu.py +++ b/backends/arm/operators/op_relu.py @@ -5,7 +5,7 @@ # pyre-unsafe -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch.fx # pyre-fixme[21]: 'Could not find a module corresponding to import `executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass`.' diff --git a/backends/arm/operators/op_repeat.py b/backends/arm/operators/op_repeat.py index fd76a52052e..b97d7023ef0 100644 --- a/backends/arm/operators/op_repeat.py +++ b/backends/arm/operators/op_repeat.py @@ -1,11 +1,11 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. # pyre-unsafe -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_rshift.py b/backends/arm/operators/op_rshift.py index 2c1f4d5bbeb..ac61cca6a98 100644 --- a/backends/arm/operators/op_rshift.py +++ b/backends/arm/operators/op_rshift.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -6,7 +6,7 @@ from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_rsqrt.py b/backends/arm/operators/op_rsqrt.py index 1cc3e8fcff5..0fbb203b081 100644 --- a/backends/arm/operators/op_rsqrt.py +++ b/backends/arm/operators/op_rsqrt.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_sigmoid.py b/backends/arm/operators/op_sigmoid.py index 0c28c0ed008..118c813dcf4 100644 --- a/backends/arm/operators/op_sigmoid.py +++ b/backends/arm/operators/op_sigmoid.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_slice.py b/backends/arm/operators/op_slice.py index 9327e005b67..7f4804af587 100644 --- a/backends/arm/operators/op_slice.py +++ b/backends/arm/operators/op_slice.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -7,7 +7,7 @@ from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_sub.py b/backends/arm/operators/op_sub.py index 0c569a6ffd8..6cd422095ab 100644 --- a/backends/arm/operators/op_sub.py +++ b/backends/arm/operators/op_sub.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -10,7 +10,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils import executorch.backends.arm.tosa_utils as tutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, @@ -75,7 +75,7 @@ def define_node( if output.dtype == ts.DType.INT8: # Scale output back to 8 bit # pyre-ignore - tqutils.insert_rescale_op_to_int8(tosa_graph, sub_output, scale_back, node) + tqutils.insert_rescale_op_to_int8(tosa_graph, sub_output, scale_back, node) # type: ignore[possibly-undefined] @register_node_visitor diff --git a/backends/arm/operators/op_sum.py b/backends/arm/operators/op_sum.py index dcc194a6567..b5b388b3352 100644 --- a/backends/arm/operators/op_sum.py +++ b/backends/arm/operators/op_sum.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -10,7 +10,7 @@ import executorch.backends.arm.tosa_quant_utils as tqutils import executorch.backends.arm.tosa_utils as tutils -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_table.py b/backends/arm/operators/op_table.py index bfaaf4578ed..d8d9b69d2f1 100644 --- a/backends/arm/operators/op_table.py +++ b/backends/arm/operators/op_table.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -9,7 +9,7 @@ import numpy as np -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, @@ -30,9 +30,9 @@ def define_node( inputs: List[TosaArg], output: TosaArg, ) -> None: - assert node.name in self._exported_program.state_dict.keys() + assert node.name in self._exported_program.state_dict.keys() # type: ignore[union-attr] assert inputs[0].dtype == output.dtype == ts.DType.INT8 - table = self._exported_program.state_dict[node.name] + table = self._exported_program.state_dict[node.name] # type: ignore[union-attr] table_attr = ts.TosaSerializerAttribute() table_attr.TableAttribute(np.array(table)) tosa_graph.addOperator( diff --git a/backends/arm/operators/op_tanh.py b/backends/arm/operators/op_tanh.py index a1e91be4ffb..7961b14f2ae 100644 --- a/backends/arm/operators/op_tanh.py +++ b/backends/arm/operators/op_tanh.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, register_node_visitor, diff --git a/backends/arm/operators/op_to_copy.py b/backends/arm/operators/op_to_copy.py index 256e54f3a2d..feaec3a41e9 100644 --- a/backends/arm/operators/op_to_copy.py +++ b/backends/arm/operators/op_to_copy.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,9 +6,9 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch -import tosa.Op as TosaOp +import tosa.Op as TosaOp # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_to_dim_order_copy.py b/backends/arm/operators/op_to_dim_order_copy.py index c2ec620b821..397979a439d 100644 --- a/backends/arm/operators/op_to_dim_order_copy.py +++ b/backends/arm/operators/op_to_dim_order_copy.py @@ -6,9 +6,9 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch -import tosa.Op as TosaOp +import tosa.Op as TosaOp # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_transpose.py b/backends/arm/operators/op_transpose.py index 42675be34b5..4e7195ecdac 100644 --- a/backends/arm/operators/op_transpose.py +++ b/backends/arm/operators/op_transpose.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -7,7 +7,7 @@ from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/operators/op_upsample_nearest2d.py b/backends/arm/operators/op_upsample_nearest2d.py index 68fcb521d90..38e4087d38d 100644 --- a/backends/arm/operators/op_upsample_nearest2d.py +++ b/backends/arm/operators/op_upsample_nearest2d.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -6,7 +6,7 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, @@ -16,7 +16,7 @@ from executorch.backends.arm.tosa_utils import get_resize_parameters, tosa_shape from serializer.tosa_serializer import TosaOp -from tosa.ResizeMode import ResizeMode +from tosa.ResizeMode import ResizeMode # type: ignore @register_node_visitor diff --git a/backends/arm/operators/op_view.py b/backends/arm/operators/op_view.py index 3489795ed50..119e32fa58f 100644 --- a/backends/arm/operators/op_view.py +++ b/backends/arm/operators/op_view.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -6,9 +6,9 @@ # pyre-unsafe from typing import List -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch -import tosa.Op as TosaOp +import tosa.Op as TosaOp # type: ignore from executorch.backends.arm.operators.node_visitor import ( NodeVisitor, diff --git a/backends/arm/process_node.py b/backends/arm/process_node.py index 36a1567df93..a83ead987ed 100644 --- a/backends/arm/process_node.py +++ b/backends/arm/process_node.py @@ -8,7 +8,7 @@ from typing import cast, Dict import numpy as np -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch import torch.fx from executorch.backends.arm.operators.node_visitor import NodeVisitor @@ -36,9 +36,9 @@ def process_call_function( # Visiting each Node # pyre-ignore[16]: Undefined attribute. - if node.target.__name__ in node_visitors: + if node.target.__name__ in node_visitors: # type: ignore[union-attr] # pyre-ignore[16]: Undefined attribute. - node_visitors[node.target.__name__].define_node( + node_visitors[node.target.__name__].define_node( # type: ignore[union-attr] node, tosa_graph, inputs, diff --git a/backends/arm/quantizer/arm_quantizer.py b/backends/arm/quantizer/arm_quantizer.py index cba66cfe561..c1a017fa1dc 100644 --- a/backends/arm/quantizer/arm_quantizer.py +++ b/backends/arm/quantizer/arm_quantizer.py @@ -20,8 +20,12 @@ from executorch.backends.arm._passes.arm_pass_manager import ArmPassManager from executorch.backends.arm.quantizer import arm_quantizer_utils -from executorch.backends.arm.quantizer.arm_quantizer_utils import mark_node_as_annotated -from executorch.backends.arm.quantizer.quantization_annotator import annotate_graph +from executorch.backends.arm.quantizer.arm_quantizer_utils import ( # type: ignore[attr-defined] + mark_node_as_annotated, +) +from executorch.backends.arm.quantizer.quantization_annotator import ( # type: ignore[import-not-found] + annotate_graph, +) from executorch.backends.arm.quantizer.quantization_config import QuantizationConfig from executorch.backends.arm.tosa_specification import TosaSpecification @@ -253,7 +257,7 @@ def transform_for_annotation(self, model: GraphModule) -> GraphModule: Currently transforms scalar values to tensor attributes. """ - return ArmPassManager(self.tosa_spec).transform_for_annotation_pipeline( + return ArmPassManager(self.tosa_spec).transform_for_annotation_pipeline( # type: ignore[arg-type] graph_module=model ) diff --git a/backends/arm/quantizer/quantization_annotator.py b/backends/arm/quantizer/quantization_annotator.py index f2a124f2790..1daf7f83c94 100644 --- a/backends/arm/quantizer/quantization_annotator.py +++ b/backends/arm/quantizer/quantization_annotator.py @@ -55,7 +55,7 @@ def _is_ok_for_quantization( for n_arg in _as_list(node.args[quant_property.index]): assert isinstance(n_arg, Node) - if not arm_quantizer_utils.is_ok_for_quantization(n_arg, gm): + if not arm_quantizer_utils.is_ok_for_quantization(n_arg, gm): # type: ignore[attr-defined] return False return True @@ -77,7 +77,7 @@ def _annotate_input(node: Node, quant_property: _QuantProperty): assert isinstance(n_arg, Node) _annotate_input_qspec_map(node, n_arg, qspec) if quant_property.mark_annotated: - arm_quantizer_utils.mark_node_as_annotated(n_arg) + arm_quantizer_utils.mark_node_as_annotated(n_arg) # type: ignore[attr-defined] def _annotate_output(node: Node, quant_property: _QuantProperty): @@ -107,7 +107,7 @@ def _match_pattern( child = next(iter(node.users)) elif node.target in pattern[1]: assert len(node.args) != 0 - parent = node.args[0] + parent = node.args[0] # type: ignore[assignment] child = node else: return False @@ -259,23 +259,23 @@ def any_or_hardtanh_min_zero(n: Node): torch.ops.aten.minimum.default, torch.ops.aten.maximum.default, ): - shared_qspec = SharedQuantizationSpec((node.args[0], node)) + shared_qspec = SharedQuantizationSpec((node.args[0], node)) # type: ignore[arg-type] quant_properties.quant_inputs = [ _QuantProperty(0, input_act_qspec), _QuantProperty( - 1, input_act_qspec if node.args[0] == node.args[1] else shared_qspec + 1, input_act_qspec if node.args[0] == node.args[1] else shared_qspec # type: ignore[arg-type] ), ] - quant_properties.quant_output = _QuantProperty(0, shared_qspec) + quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type] elif node.target == torch.ops.aten.adaptive_avg_pool2d.default: input_qspec = ( - SharedQuantizationSpec(node.args[0]) - if arm_quantizer_utils.is_output_annotated(node.args[0]) + SharedQuantizationSpec(node.args[0]) # type: ignore[arg-type] + if arm_quantizer_utils.is_output_annotated(node.args[0]) # type: ignore else input_act_qspec ) - quant_properties.quant_inputs = [_QuantProperty(0, input_qspec)] + quant_properties.quant_inputs = [_QuantProperty(0, input_qspec)] # type: ignore[arg-type] quant_properties.quant_output = _QuantProperty( - 0, SharedQuantizationSpec((node.args[0], node)) + 0, SharedQuantizationSpec((node.args[0], node)) # type: ignore[arg-type] ) elif node.target in ( torch.ops.aten.cat.default, @@ -290,19 +290,19 @@ def any_or_hardtanh_min_zero(n: Node): _QuantProperty( 0, [ - input_act_qspec if n == node.args[0][0] else shared_qspec + input_act_qspec if n == node.args[0][0] else shared_qspec # type: ignore[misc] for n in node.args[0] ], ) ] - quant_properties.quant_output = _QuantProperty(0, shared_qspec) + quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type] elif node.target in _one_to_one: quant_properties.quant_inputs = [_QuantProperty(0, input_act_qspec)] quant_properties.quant_output = _QuantProperty(0, output_act_qspec) elif node.target in _one_to_one_shared_input_qspec: quant_properties.quant_inputs = [_QuantProperty(0, input_act_qspec)] quant_properties.quant_output = _QuantProperty( - 0, SharedQuantizationSpec((node.args[0], node)) + 0, SharedQuantizationSpec((node.args[0], node)) # type: ignore[arg-type] ) elif node.target in [ torch.ops.aten.eq.Tensor, @@ -311,26 +311,26 @@ def any_or_hardtanh_min_zero(n: Node): torch.ops.aten.le.Tensor, torch.ops.aten.lt.Tensor, ]: - shared_qspec = SharedQuantizationSpec((node.args[0], node)) + shared_qspec = SharedQuantizationSpec((node.args[0], node)) # type: ignore[arg-type] quant_properties.quant_inputs = [ _QuantProperty(0, input_act_qspec), _QuantProperty( - 1, input_act_qspec if node.args[0] == node.args[1] else shared_qspec + 1, input_act_qspec if node.args[0] == node.args[1] else shared_qspec # type: ignore[arg-type] ), ] quant_properties.quant_output = None elif node.target in _parent_shared_qspec: if not isinstance(node.args[0], Node): - return None + return None # type: ignore[return-value] - if not arm_quantizer_utils.is_output_annotated(node.args[0]): - return None + if not arm_quantizer_utils.is_output_annotated(node.args[0]): # type: ignore[attr-defined] + return None # type: ignore[return-value] shared_qspec = SharedQuantizationSpec(node.args[0]) - quant_properties.quant_inputs = [_QuantProperty(0, shared_qspec)] - quant_properties.quant_output = _QuantProperty(0, shared_qspec) + quant_properties.quant_inputs = [_QuantProperty(0, shared_qspec)] # type: ignore[arg-type] + quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type] else: - return None + return None # type: ignore[return-value] # Don't check if operator.getitem is ok for quantization, it's always ok if node.target == operator.getitem: @@ -340,16 +340,16 @@ def any_or_hardtanh_min_zero(n: Node): # provided QuantProperties for quant_property in quant_properties.quant_inputs: if not _is_ok_for_quantization(node, quant_property, gm): - return None + return None # type: ignore[return-value] if quant_properties.quant_output is not None: if not _is_ok_for_quantization(node, quant_properties.quant_output, gm): - return None + return None # type: ignore[return-value] return quant_properties -def annotate_graph( +def annotate_graph( # type: ignore[return] gm: torch.fx.GraphModule, quantization_config: QuantizationConfig, filter_fn: Optional[Callable[[Node], bool]] = None, @@ -374,4 +374,4 @@ def annotate_graph( if quant_properties.quant_output is not None: _annotate_output(node, quant_properties.quant_output) - arm_quantizer_utils.mark_node_as_annotated(node) + arm_quantizer_utils.mark_node_as_annotated(node) # type: ignore[attr-defined] diff --git a/backends/arm/quantizer/quantization_config.py b/backends/arm/quantizer/quantization_config.py index b94d9bda640..394995201e4 100644 --- a/backends/arm/quantizer/quantization_config.py +++ b/backends/arm/quantizer/quantization_config.py @@ -82,14 +82,14 @@ def _derive_qparams_fn( input_act = node.args[0] weight = node.args[1] quantization_spec = DerivedQuantizationSpec( - derived_from=[(input_act, node), (weight, node)], + derived_from=[(input_act, node), (weight, node)], # type: ignore[list-item] derive_qparams_fn=_derive_qparams_fn, dtype=torch.int32, quant_min=torch.iinfo(torch.int32).min, quant_max=torch.iinfo(torch.int32).max - 1, qscheme=torch.per_tensor_symmetric, ) - return quantization_spec + return quantization_spec # type: ignore[return-value] if self.bias is None: return None diff --git a/backends/arm/test/common.py b/backends/arm/test/common.py index 7ebf89e3927..2f08fa81918 100644 --- a/backends/arm/test/common.py +++ b/backends/arm/test/common.py @@ -41,8 +41,8 @@ def maybe_get_tosa_collate_path() -> str | None: if tosa_test_base: current_test = os.environ.get("PYTEST_CURRENT_TEST") #'backends/arm/test/ops/test_mean_dim.py::TestMeanDim::test_meandim_tosa_BI_0_zeros (call)' - test_class = current_test.split("::")[1] - test_name = current_test.split("::")[-1].split(" ")[0] + test_class = current_test.split("::")[1] # type: ignore[union-attr] + test_name = current_test.split("::")[-1].split(" ")[0] # type: ignore[union-attr] if "BI" in test_name: tosa_test_base = os.path.join(tosa_test_base, "tosa-bi") elif "MI" in test_name: @@ -100,7 +100,7 @@ def get_u85_compile_spec( """ Default compile spec for Ethos-U85 tests. """ - return get_u85_compile_spec_unbuilt( + return get_u85_compile_spec_unbuilt( # type: ignore[attr-defined] custom_path=custom_path, ).build() @@ -144,4 +144,4 @@ def get_u85_compile_spec_unbuilt( ) .dump_intermediate_artifacts_to(artifact_path) ) - return compile_spec + return compile_spec # type: ignore[return-value] diff --git a/backends/arm/test/misc/test_debug_feats.py b/backends/arm/test/misc/test_debug_feats.py index a9491418a44..690549d7174 100644 --- a/backends/arm/test/misc/test_debug_feats.py +++ b/backends/arm/test/misc/test_debug_feats.py @@ -48,7 +48,7 @@ def _tosa_MI_pipeline(self, module: torch.nn.Module, dump_file=None): ( ArmTester( module, - example_inputs=module.get_inputs(), + example_inputs=module.get_inputs(), # type: ignore[operator] compile_spec=common.get_tosa_compile_spec("TOSA-0.80+MI"), ) .export() @@ -61,7 +61,7 @@ def _tosa_BI_pipeline(self, module: torch.nn.Module, dump_file=None): ( ArmTester( module, - example_inputs=module.get_inputs(), + example_inputs=module.get_inputs(), # type: ignore[operator] compile_spec=common.get_tosa_compile_spec("TOSA-0.80+BI"), ) .quantize() diff --git a/backends/arm/test/misc/test_lifted_tensor.py b/backends/arm/test/misc/test_lifted_tensor.py index a16b1e639b1..092483fd632 100644 --- a/backends/arm/test/misc/test_lifted_tensor.py +++ b/backends/arm/test/misc/test_lifted_tensor.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 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. @@ -10,7 +10,7 @@ import torch from executorch.backends.arm.test import common from executorch.backends.arm.test.tester.arm_tester import ArmTester -from parameterized import parameterized +from parameterized import parameterized # type: ignore[import-untyped] class LiftedTensor(torch.nn.Module): @@ -23,14 +23,14 @@ class LiftedTensor(torch.nn.Module): (operator.sub, (torch.rand(2, 2), 2)), ] - def __init__(self, op: callable): + def __init__(self, op: callable): # type: ignore[valid-type] super().__init__() self.op = op self.lifted_tensor = torch.Tensor([[1, 2], [3, 4]]) def forward(self, x: torch.Tensor, length) -> torch.Tensor: sliced = self.lifted_tensor[:, :length] - return self.op(sliced, x) + return self.op(sliced, x) # type: ignore[misc] class LiftedScalarTensor(torch.nn.Module): @@ -42,13 +42,13 @@ class LiftedScalarTensor(torch.nn.Module): (operator.sub, (torch.randn(3),), 1.0), ] - def __init__(self, op: callable, arg1: Union[int, float, torch.tensor]): + def __init__(self, op: callable, arg1: Union[int, float, torch.tensor]): # type: ignore[valid-type] super().__init__() self.op = op self.arg1 = arg1 def forward(self, x: torch.Tensor) -> torch.Tensor: - return self.op(x, self.arg1) + return self.op(x, self.arg1) # type: ignore[misc] class TestLiftedTensor(unittest.TestCase): diff --git a/backends/arm/test/misc/test_tosa_spec.py b/backends/arm/test/misc/test_tosa_spec.py index 77b10cf3151..d61b3fe718b 100644 --- a/backends/arm/test/misc/test_tosa_spec.py +++ b/backends/arm/test/misc/test_tosa_spec.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -13,7 +13,7 @@ ) from executorch.exir.backend.compile_spec_schema import CompileSpec -from parameterized import parameterized +from parameterized import parameterized # type: ignore[import-untyped] test_valid_0_80_strings = [ "TOSA-0.80+BI", @@ -64,13 +64,13 @@ class TestTosaSpecification(unittest.TestCase): """Tests the TOSA specification class""" - @parameterized.expand(test_valid_0_80_strings) + @parameterized.expand(test_valid_0_80_strings) # type: ignore[misc] def test_version_string_0_80(self, version_string: str): tosa_spec = TosaSpecification.create_from_string(version_string) assert isinstance(tosa_spec, Tosa_0_80) assert tosa_spec.profile in ["BI", "MI"] - @parameterized.expand(test_valid_1_00_strings) + @parameterized.expand(test_valid_1_00_strings) # type: ignore[misc] def test_version_string_1_00(self, version_string: str): tosa_spec = TosaSpecification.create_from_string(version_string) assert isinstance(tosa_spec, Tosa_1_00) @@ -83,7 +83,7 @@ def test_version_string_1_00(self, version_string: str): e in test_valid_1_00_extensions[profile] for e in tosa_spec.extensions ] - @parameterized.expand(test_invalid_strings) + @parameterized.expand(test_invalid_strings) # type: ignore[misc] def test_invalid_version_strings(self, version_string: str): tosa_spec = None with self.assertRaises(ValueError): @@ -91,12 +91,12 @@ def test_invalid_version_strings(self, version_string: str): assert tosa_spec is None - @parameterized.expand(test_compile_specs) + @parameterized.expand(test_compile_specs) # type: ignore[misc] def test_create_from_compilespec(self, compile_specs: list[CompileSpec]): tosa_spec = TosaSpecification.create_from_compilespecs(compile_specs) assert isinstance(tosa_spec, TosaSpecification) - @parameterized.expand(test_compile_specs_no_version) + @parameterized.expand(test_compile_specs_no_version) # type: ignore[misc] def test_create_from_invalid_compilespec(self, compile_specs: list[CompileSpec]): tosa_spec = None with self.assertRaises(ValueError): diff --git a/backends/arm/test/models/test_mobilenet_v2_arm.py b/backends/arm/test/models/test_mobilenet_v2_arm.py index 21bd43202d6..62b14a1022e 100644 --- a/backends/arm/test/models/test_mobilenet_v2_arm.py +++ b/backends/arm/test/models/test_mobilenet_v2_arm.py @@ -14,8 +14,10 @@ from executorch.backends.arm.test import common, conftest from executorch.backends.arm.test.tester.arm_tester import ArmTester -from torchvision import models, transforms -from torchvision.models.mobilenetv2 import MobileNet_V2_Weights +from torchvision import models, transforms # type: ignore[import-untyped] +from torchvision.models.mobilenetv2 import ( # type: ignore[import-untyped] + MobileNet_V2_Weights, +) logger = logging.getLogger(__name__) diff --git a/backends/arm/test/ops/test_add.py b/backends/arm/test/ops/test_add.py index db6fde53ae9..5d9269f1d4d 100644 --- a/backends/arm/test/ops/test_add.py +++ b/backends/arm/test/ops/test_add.py @@ -14,7 +14,7 @@ from executorch.backends.arm.test import common, conftest from executorch.backends.arm.test.tester.arm_tester import ArmTester from executorch.exir.backend.compile_spec_schema import CompileSpec -from parameterized import parameterized +from parameterized import parameterized # type: ignore[import-untyped] class TestSimpleAdd(unittest.TestCase): diff --git a/backends/arm/test/tester/arm_tester.py b/backends/arm/test/tester/arm_tester.py index 639cea5bae9..a5e7267b372 100644 --- a/backends/arm/test/tester/arm_tester.py +++ b/backends/arm/test/tester/arm_tester.py @@ -12,7 +12,7 @@ import executorch.backends.xnnpack.test.tester.tester as tester -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore[import-untyped] import torch.fx import torch.utils._pytree as pytree diff --git a/backends/arm/tosa_mapping.py b/backends/arm/tosa_mapping.py index ec57bd5ce22..75d82f2a4b6 100644 --- a/backends/arm/tosa_mapping.py +++ b/backends/arm/tosa_mapping.py @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Arm Limited and/or its affiliates. +# Copyright 2023-2025 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. @@ -11,7 +11,7 @@ # the standardised TOSA representation. # -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch diff --git a/backends/arm/tosa_quant_utils.py b/backends/arm/tosa_quant_utils.py index 9869a08c0ba..d53362cb363 100644 --- a/backends/arm/tosa_quant_utils.py +++ b/backends/arm/tosa_quant_utils.py @@ -10,9 +10,9 @@ import math from typing import cast, NamedTuple -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch.fx -import tosa.Op as TosaOp +import tosa.Op as TosaOp # type: ignore from executorch.backends.arm.tosa_mapping import TosaArg from executorch.exir.dialects._ops import ops as exir_ops from serializer.tosa_serializer import TosaSerializerTensor diff --git a/backends/arm/tosa_utils.py b/backends/arm/tosa_utils.py index 9fefdbb3ff3..a57e8aa10c9 100644 --- a/backends/arm/tosa_utils.py +++ b/backends/arm/tosa_utils.py @@ -10,7 +10,7 @@ from typing import Any import numpy as np -import serializer.tosa_serializer as ts +import serializer.tosa_serializer as ts # type: ignore import torch from executorch.backends.arm.tosa_mapping import TosaArg diff --git a/backends/arm/util/arm_model_evaluator.py b/backends/arm/util/arm_model_evaluator.py index f8aeab25ba1..b43c781dfdf 100644 --- a/backends/arm/util/arm_model_evaluator.py +++ b/backends/arm/util/arm_model_evaluator.py @@ -1,4 +1,4 @@ -# Copyright 2024 Arm Limited and/or its affiliates. +# Copyright 2024-2025 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -17,7 +17,7 @@ import torch from torch.nn.modules import Module from torch.utils.data import DataLoader -from torchvision import datasets, transforms +from torchvision import datasets, transforms # type: ignore[import-untyped] # Logger for outputting progress for longer running evaluation @@ -59,7 +59,7 @@ def __init__( if tosa_output_path: self.tosa_output_path = tosa_output_path else: - self.tosa_output_path = None + self.tosa_output_path = None # type: ignore[assignment] def get_model_error(self) -> defaultdict: """ @@ -104,7 +104,7 @@ def get_compression_ratio(self) -> float: return compression_ratio - def evaluate(self) -> dict[Any]: + def evaluate(self) -> dict[Any]: # type: ignore[type-arg] model_error_dict = self.get_model_error() output_metrics = {"name": self.model_name, "metrics": dict(model_error_dict)} @@ -112,7 +112,7 @@ def evaluate(self) -> dict[Any]: if self.tosa_output_path: # We know output_metrics["metrics"] is list since we just defined it, safe to ignore. # pyre-ignore[16] - output_metrics["metrics"][ + output_metrics["metrics"][ # type: ignore[index] "compression_ratio" ] = self.get_compression_ratio()