From 984bc6a891eaa69b2f75ebf1d92dcd4e7269ae89 Mon Sep 17 00:00:00 2001 From: Per Held Date: Wed, 5 Nov 2025 12:42:09 +0100 Subject: [PATCH 1/6] Arm backend: Fix mypy warnings in test_fuse_duplicate... Fix mypy warning about type. Signed-off-by: per.held@arm.com Change-Id: I09a5f75943c12b304a2e4d4ff6af8739021aeb44 --- .../test/passes/test_fuse_duplicate_users_pass.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/backends/arm/test/passes/test_fuse_duplicate_users_pass.py b/backends/arm/test/passes/test_fuse_duplicate_users_pass.py index a7e80794015..ffe56e72691 100644 --- a/backends/arm/test/passes/test_fuse_duplicate_users_pass.py +++ b/backends/arm/test/passes/test_fuse_duplicate_users_pass.py @@ -3,7 +3,7 @@ # 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 Tuple +from typing import Dict, Tuple import torch from executorch.backends.arm._passes import FuseDuplicateUsersPass @@ -13,7 +13,12 @@ input_t = Tuple[torch.Tensor] # Input x -class FuseaAvgPool(torch.nn.Module): +class ModuleWithOps(torch.nn.Module): + ops_before_pass: Dict[str, int] + ops_after_pass: Dict[str, int] + + +class FuseaAvgPool(ModuleWithOps): ops_before_pass = { "executorch_exir_dialects_edge__ops_aten_avg_pool2d_default": 3, } @@ -27,7 +32,7 @@ def forward(self, x): return self.avg(x) + self.avg(x) + self.avg(x) -class FuseAvgPoolChain(torch.nn.Module): +class FuseAvgPoolChain(ModuleWithOps): ops_before_pass = { "executorch_exir_dialects_edge__ops_aten_avg_pool2d_default": 6, } @@ -44,14 +49,14 @@ def forward(self, x): return first + second + third -modules = { +modules: Dict[str, ModuleWithOps] = { "fuse_avg_pool": FuseaAvgPool(), "fuse_avg_pool_chain": FuseAvgPoolChain(), } @common.parametrize("module", modules) -def test_fuse_duplicate_ops_FP(module: torch.nn.Module): +def test_fuse_duplicate_ops_FP(module: ModuleWithOps): pipeline = PassPipeline[input_t]( module=module, test_data=(torch.ones(1, 1, 1, 1),), From 43903941204d81dd1c456180ea98d5f8c406f7f4 Mon Sep 17 00:00:00 2001 From: Per Held Date: Fri, 7 Nov 2025 09:04:41 +0100 Subject: [PATCH 2/6] Arm backend: Add ignores for missing imports in test/models/sta... Some missing imports for third-party libraries used in stable_diffusion had ignores added to them. Signed-off-by: per.held@arm.com Change-Id: Icd86edd39ae4541813bc84c07fdab90571da98c2 --- .../models/stable_diffusion/test_SD3Transformer2DModel.py | 4 +++- .../models/stable_diffusion/test_vae_AutoencoderKL.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py b/backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py index 9506fe727db..3e1f19dd39c 100644 --- a/backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py +++ b/backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py @@ -7,7 +7,9 @@ from typing import Tuple import torch -from diffusers.models.transformers import SD3Transformer2DModel +from diffusers.models.transformers import ( # type: ignore[import-not-found] + SD3Transformer2DModel, +) from executorch.backends.arm.test import common from executorch.backends.arm.test.models.stable_diffusion.stable_diffusion_module_test_configs import ( diff --git a/backends/arm/test/models/stable_diffusion/test_vae_AutoencoderKL.py b/backends/arm/test/models/stable_diffusion/test_vae_AutoencoderKL.py index a3c3a018131..5d33576a817 100644 --- a/backends/arm/test/models/stable_diffusion/test_vae_AutoencoderKL.py +++ b/backends/arm/test/models/stable_diffusion/test_vae_AutoencoderKL.py @@ -7,8 +7,12 @@ from typing import Tuple import torch -from diffusers.models.autoencoders import AutoencoderKL -from diffusers.utils.testing_utils import floats_tensor +from diffusers.models.autoencoders import ( # type: ignore[import-not-found] + AutoencoderKL, +) +from diffusers.utils.testing_utils import ( # type: ignore[import-not-found] + floats_tensor, +) from executorch.backends.arm.test import common from executorch.backends.arm.test.models.stable_diffusion.stable_diffusion_module_test_configs import ( From 6e0b9ffa01c58b80fb37af62d78fbfe6df1b860d Mon Sep 17 00:00:00 2001 From: Per Held Date: Wed, 5 Nov 2025 11:01:28 +0100 Subject: [PATCH 3/6] Add src to mypy_path in .mypy.ini Add src to mypy_path to get rid of lots of missing import warnings. Signed-off-by: per.held@arm.com Change-Id: I4ed1a08cfe185aa956c6408fefa5aadeb567d4c1 --- .mypy.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mypy.ini b/.mypy.ini index e01392a0dfd..a8df0f41b00 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -24,7 +24,7 @@ files = test, util -mypy_path = executorch +mypy_path = executorch,src [mypy-executorch.backends.*] follow_untyped_imports = True From 7b209a60dae83c922f457646b189fd6419366b8b Mon Sep 17 00:00:00 2001 From: Per Held Date: Tue, 21 Oct 2025 14:14:13 +0200 Subject: [PATCH 4/6] Arm backend: Enable mypy for tests Add test directory in arm backend to lintrunner. Except the ops directory which has to be fixed later. About "disallow_untyped_decorators = False": The only way to make mypy happy seems to be a wrapper around the decorator for each file it is used. I have read numerous of threads about it and there seems to be no good solution. Hence the added ignore for backends/arm. Signed-off-by: per.held@arm.com Change-Id: I0430041cb3308b51798d74da61cc4d310966772a --- .lintrunner.toml | 2 +- .mypy.ini | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.lintrunner.toml b/.lintrunner.toml index d0c9c6aef6a..396b7fde5ac 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -367,7 +367,7 @@ exclude_patterns = [ '**/third-party/**', 'scripts/check_binary_dependencies.py', 'profiler/test/test_profiler_e2e.py', - 'backends/arm/test/**', + 'backends/arm/test/ops/*.py', ] command = [ 'python', diff --git a/.mypy.ini b/.mypy.ini index a8df0f41b00..0ce444e8a79 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -29,6 +29,9 @@ mypy_path = executorch,src [mypy-executorch.backends.*] follow_untyped_imports = True +[mypy-backends.arm.*] +disallow_untyped_decorators = False + [mypy-executorch.codegen.*] follow_untyped_imports = True From 858a2d5e4ab4d9a7c80525cdf44213afa70dab6d Mon Sep 17 00:00:00 2001 From: Per Held Date: Fri, 7 Nov 2025 13:40:45 +0100 Subject: [PATCH 5/6] Arm backend: Use correct ignore for import-not-found Add ignore for import as well, since on github these packages are not installed and thus its a import-not-found error and not untyped as it becomes locally if you have the packages installed. Signed-off-by: per.held@arm.com Change-Id: Iba7b579f8f95991aca26054698e1d357dc14a853 --- backends/arm/test/runner_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/arm/test/runner_utils.py b/backends/arm/test/runner_utils.py index 2c76af1b779..5e22a54d393 100644 --- a/backends/arm/test/runner_utils.py +++ b/backends/arm/test/runner_utils.py @@ -36,7 +36,7 @@ from torch.fx.node import Node from torch.overrides import TorchFunctionMode -from tosa.TosaGraph import TosaGraph # type: ignore[import-untyped] +from tosa.TosaGraph import TosaGraph # type: ignore[import-not-found, import-untyped] logger = logging.getLogger(__name__) @@ -762,7 +762,7 @@ def run_tosa_graph( inputs_np = [torch_tensor_to_numpy(input_tensor) for input_tensor in inputs] if isinstance(tosa_version, Tosa_1_00): - import tosa_reference_model as reference_model # type: ignore[import-untyped] + import tosa_reference_model as reference_model # type: ignore[import-not-found, import-untyped] debug_mode = "ALL" if logger.getEffectiveLevel() <= logging.DEBUG else None outputs_np, status = reference_model.run( From c501ea763f6745e785a1a40ab41808a9f4e025e5 Mon Sep 17 00:00:00 2001 From: Per Held Date: Mon, 10 Nov 2025 08:42:41 +0100 Subject: [PATCH 6/6] Arm backend: Add mypy ignore for nss import Signed-off-by: per.held@arm.com Change-Id: I351b955621c8f5b807e4ead2722d3b7f0d98df51 --- backends/arm/test/models/test_nss.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backends/arm/test/models/test_nss.py b/backends/arm/test/models/test_nss.py index 82187d2b479..5f7db548109 100644 --- a/backends/arm/test/models/test_nss.py +++ b/backends/arm/test/models/test_nss.py @@ -19,7 +19,9 @@ from huggingface_hub import hf_hub_download -from ng_model_gym.usecases.nss.model.model_blocks import AutoEncoderV1 +from ng_model_gym.usecases.nss.model.model_blocks import ( # type: ignore[import-not-found,import-untyped] + AutoEncoderV1, +) input_t = Tuple[torch.Tensor] # Input x