Skip to content

Commit 9e64882

Browse files
Arm backend: Populate __init__.py for quantizer and Arm root (#10351)
Populate backends/arm/quantizer/__init__.py and backends/arm/__init__.py Signed-off-by: Oscar Andersson <[email protected]>
1 parent 04cacc6 commit 9e64882

22 files changed

+57
-47
lines changed

backends/arm/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates.
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
from .arm_backend import ArmCompileSpecBuilder # noqa # usort: skip
7+
from .tosa_backend import TOSABackend # noqa # usort: skip
8+
from .tosa_partitioner import TOSAPartitioner # noqa # usort: skip
9+
from .ethosu_backend import EthosUBackend # noqa # usort: skip
10+
from .ethosu_partitioner import EthosUPartitioner # noqa # usort: skip

backends/arm/ethosu_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import logging
1515
from typing import final, List
1616

17-
from executorch.backends.arm.arm_vela import vela_compile
17+
from executorch.backends.arm import TOSABackend
1818

19-
from executorch.backends.arm.tosa_backend import TOSABackend
19+
from executorch.backends.arm.arm_vela import vela_compile
2020
from executorch.exir.backend.backend_details import BackendDetails, PreprocessResult
2121
from executorch.exir.backend.compile_spec_schema import CompileSpec
2222
from torch.export.exported_program import ExportedProgram

backends/arm/ethosu_partitioner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from executorch.backends.arm.arm_backend import (
1111
is_ethosu,
1212
) # usort: skip
13-
from executorch.backends.arm.ethosu_backend import EthosUBackend
14-
from executorch.backends.arm.tosa_partitioner import TOSAPartitioner
13+
from executorch.backends.arm import EthosUBackend, TOSAPartitioner
1514
from executorch.exir.backend.compile_spec_schema import CompileSpec
1615
from executorch.exir.backend.partitioner import DelegationSpec
1716
from torch.fx.passes.operator_support import OperatorSupportBase

backends/arm/quantizer/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
# Copyright 2024 Arm Limited and/or its affiliates.
1+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
5+
6+
7+
from .quantization_config import QuantizationConfig # noqa # usort: skip
8+
from .arm_quantizer import ( # noqa
9+
EthosUQuantizer,
10+
get_symmetric_quantization_config,
11+
TOSAQuantizer,
12+
)

backends/arm/quantizer/arm_quantizer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
import torch
2020
from executorch.backends.arm._passes import ArmPassManager
2121

22-
from executorch.backends.arm.quantizer import arm_quantizer_utils
22+
from executorch.backends.arm.quantizer import arm_quantizer_utils, QuantizationConfig
2323
from executorch.backends.arm.quantizer.arm_quantizer_utils import ( # type: ignore[attr-defined]
2424
mark_node_as_annotated,
2525
)
2626
from executorch.backends.arm.quantizer.quantization_annotator import ( # type: ignore[import-not-found]
2727
annotate_graph,
2828
)
2929

30-
from executorch.backends.arm.quantizer.quantization_config import QuantizationConfig
3130
from executorch.backends.arm.tosa_specification import TosaSpecification
3231
from executorch.backends.arm.arm_backend import (
3332
get_tosa_spec,

backends/arm/quantizer/quantization_annotator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
import torch
1212
import torch.fx
13-
from executorch.backends.arm.quantizer import arm_quantizer_utils
14-
from executorch.backends.arm.quantizer.quantization_config import QuantizationConfig
13+
from executorch.backends.arm.quantizer import arm_quantizer_utils, QuantizationConfig
1514
from executorch.backends.arm.tosa_utils import get_node_debug_info
1615
from torch.ao.quantization.quantizer import QuantizationSpecBase, SharedQuantizationSpec
1716
from torch.ao.quantization.quantizer.utils import (

backends/arm/test/ops/test_expand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import torch
1717

18-
from executorch.backends.arm.quantizer.arm_quantizer import (
18+
from executorch.backends.arm.quantizer import (
1919
EthosUQuantizer,
2020
get_symmetric_quantization_config,
2121
TOSAQuantizer,

backends/arm/test/ops/test_hardtanh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import torch
1515

16-
from executorch.backends.arm.quantizer.arm_quantizer import (
16+
from executorch.backends.arm.quantizer import (
1717
EthosUQuantizer,
1818
get_symmetric_quantization_config,
1919
TOSAQuantizer,

backends/arm/test/ops/test_max_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313

1414
import torch
15-
from executorch.backends.arm.quantizer.arm_quantizer import (
15+
from executorch.backends.arm.quantizer import (
1616
EthosUQuantizer,
1717
get_symmetric_quantization_config,
1818
TOSAQuantizer,

backends/arm/test/ops/test_permute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import torch
1515

16-
from executorch.backends.arm.quantizer.arm_quantizer import (
16+
from executorch.backends.arm.quantizer import (
1717
EthosUQuantizer,
1818
get_symmetric_quantization_config,
1919
TOSAQuantizer,

backends/arm/test/ops/test_relu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Tuple
1111

1212
import torch
13-
from executorch.backends.arm.quantizer.arm_quantizer import (
13+
from executorch.backends.arm.quantizer import (
1414
EthosUQuantizer,
1515
get_symmetric_quantization_config,
1616
TOSAQuantizer,

backends/arm/test/ops/test_repeat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import torch
1515

16-
from executorch.backends.arm.quantizer.arm_quantizer import (
16+
from executorch.backends.arm.quantizer import (
1717
EthosUQuantizer,
1818
get_symmetric_quantization_config,
1919
TOSAQuantizer,

backends/arm/test/ops/test_sigmoid_16bit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
import torch
9-
from executorch.backends.arm.quantizer.arm_quantizer import (
9+
from executorch.backends.arm.quantizer import (
1010
get_symmetric_quantization_config,
1111
TOSAQuantizer,
1212
)

backends/arm/test/ops/test_sigmoid_32bit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77
import torch
8-
from executorch.backends.arm.quantizer.arm_quantizer import TOSAQuantizer
8+
from executorch.backends.arm.quantizer import TOSAQuantizer
99
from executorch.backends.arm.quantizer.quantization_config import QuantizationConfig
1010
from executorch.backends.arm.test import common
1111
from executorch.backends.arm.test.tester.test_pipeline import (

backends/arm/test/ops/test_var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import unittest
1212

1313
import torch
14-
from executorch.backends.arm.quantizer.arm_quantizer import (
14+
from executorch.backends.arm.quantizer import (
1515
EthosUQuantizer,
1616
get_symmetric_quantization_config,
1717
TOSAQuantizer,

backends/arm/test/ops/test_where.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import torch
1111

12-
from executorch.backends.arm.quantizer.arm_quantizer import (
12+
from executorch.backends.arm.quantizer import (
1313
EthosUQuantizer,
1414
get_symmetric_quantization_config,
1515
TOSAQuantizer,

backends/arm/test/tester/arm_tester.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import torch.utils._pytree as pytree
1919

2020
import tosa_tools.v0_80.serializer.tosa_serializer as ts # type: ignore[import-untyped]
21+
from executorch.backends.arm import EthosUPartitioner, TOSAPartitioner
2122
from executorch.backends.arm._passes.arm_pass_manager import ArmPassManager
2223

2324
from executorch.backends.arm.arm_backend import (
@@ -26,8 +27,7 @@
2627
is_ethosu,
2728
is_tosa,
2829
)
29-
from executorch.backends.arm.ethosu_partitioner import EthosUPartitioner
30-
from executorch.backends.arm.quantizer.arm_quantizer import (
30+
from executorch.backends.arm.quantizer import (
3131
EthosUQuantizer,
3232
get_symmetric_quantization_config,
3333
TOSAQuantizer,
@@ -47,7 +47,6 @@
4747
print_error_diffs,
4848
)
4949
from executorch.backends.arm.tosa_mapping import extract_tensor_meta
50-
from executorch.backends.arm.tosa_partitioner import TOSAPartitioner
5150

5251
from executorch.backends.xnnpack.test.tester import Tester
5352
from executorch.devtools.backend_debug import get_delegation_info

backends/arm/test/tester/test_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import torch
1010

11-
from executorch.backends.arm.quantizer.arm_quantizer import (
11+
from executorch.backends.arm.quantizer import (
1212
EthosUQuantizer,
1313
get_symmetric_quantization_config,
1414
TOSAQuantizer,

backends/arm/tosa_partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
get_tosa_spec,
1414
is_tosa,
1515
) # usort: skip
16+
from executorch.backends.arm import TOSABackend
1617
from executorch.backends.arm._passes.arm_pass_utils import get_first_fake_tensor
1718
from executorch.backends.arm.operator_support.tosa_supported_operators import (
1819
tosa_support_factory,
1920
)
20-
from executorch.backends.arm.tosa_backend import TOSABackend
2121
from executorch.exir.backend.compile_spec_schema import CompileSpec
2222
from executorch.exir.backend.partitioner import (
2323
DelegationSpec,

backends/arm/tosa_quant_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import math
1111
from typing import cast, List, NamedTuple, Tuple
1212

13-
import executorch.backends.arm.tosa_mapping
14-
1513
import torch.fx
1614
import torch.fx.node
1715

@@ -234,7 +232,7 @@ def build_rescale(
234232

235233
def build_rescale_to_int32(
236234
tosa_fb: ts.TosaSerializer,
237-
input_arg: executorch.backends.arm.tosa_mapping.TosaArg,
235+
input_arg: TosaArg,
238236
input_zp: int,
239237
rescale_scale: list[float],
240238
is_scale32: bool = True,

examples/arm/aot_arm_compiler.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717

1818
import torch
1919
from examples.devtools.scripts.export_bundled_program import save_bundled_program
20-
from executorch.backends.arm.arm_backend import (
20+
from executorch.backends.arm import (
2121
ArmCompileSpecBuilder,
22-
get_tosa_spec,
23-
is_ethosu,
24-
is_tosa,
22+
EthosUPartitioner,
23+
TOSAPartitioner,
2524
)
26-
from executorch.backends.arm.ethosu_partitioner import EthosUPartitioner
27-
from executorch.backends.arm.quantizer.arm_quantizer import (
25+
from executorch.backends.arm.arm_backend import get_tosa_spec, is_ethosu, is_tosa
26+
from executorch.backends.arm.quantizer import (
2827
EthosUQuantizer,
2928
get_symmetric_quantization_config,
3029
TOSAQuantizer,
3130
)
32-
from executorch.backends.arm.tosa_partitioner import TOSAPartitioner
3331
from executorch.backends.arm.tosa_specification import TosaSpecification
3432

3533
from executorch.backends.arm.util.arm_model_evaluator import (

examples/arm/ethos_u_minimal_example.ipynb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
"metadata": {},
8080
"outputs": [],
8181
"source": [
82-
"from executorch.backends.arm.arm_backend import ArmCompileSpecBuilder\n",
83-
"from executorch.backends.arm.quantizer.arm_quantizer import (\n",
82+
"from executorch.backends.arm import ArmCompileSpecBuilder\n",
83+
"from executorch.backends.arm.quantizer import (\n",
8484
" EthosUQuantizer,\n",
8585
" get_symmetric_quantization_config,\n",
8686
")\n",
@@ -89,7 +89,7 @@
8989
"target = \"ethos-u55-128\"\n",
9090
"\n",
9191
"# Create a compilation spec describing the target for configuring the quantizer\n",
92-
"# Some args are used by the Arm Vela graph compiler later in the example. Refer to Arm Vela documentation for an \n",
92+
"# Some args are used by the Arm Vela graph compiler later in the example. Refer to Arm Vela documentation for an\n",
9393
"# explanation of its flags: https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela/-/blob/main/OPTIONS.md\n",
9494
"spec_builder = ArmCompileSpecBuilder().ethosu_compile_spec(\n",
9595
" target,\n",
@@ -100,12 +100,12 @@
100100
"compile_spec = spec_builder.build()\n",
101101
"\n",
102102
"# Create and configure quantizer to use a symmetric quantization config globally on all nodes\n",
103-
"quantizer = EthosUQuantizer(compile_spec) \n",
103+
"quantizer = EthosUQuantizer(compile_spec)\n",
104104
"operator_config = get_symmetric_quantization_config(is_per_channel=False)\n",
105105
"quantizer.set_global(operator_config)\n",
106106
"\n",
107107
"# Post training quantization\n",
108-
"quantized_graph_module = prepare_pt2e(graph_module, quantizer) \n",
108+
"quantized_graph_module = prepare_pt2e(graph_module, quantizer)\n",
109109
"quantized_graph_module(*example_inputs) # Calibrate the graph module with the example input\n",
110110
"quantized_graph_module = convert_pt2e(quantized_graph_module)\n",
111111
"\n",
@@ -128,8 +128,8 @@
128128
"metadata": {},
129129
"outputs": [],
130130
"source": [
131-
"import subprocess \n",
132-
"import os \n",
131+
"import subprocess\n",
132+
"import os\n",
133133
"\n",
134134
"# Setup paths\n",
135135
"cwd_dir = os.getcwd()\n",
@@ -163,16 +163,16 @@
163163
"metadata": {},
164164
"outputs": [],
165165
"source": [
166-
"from executorch.backends.arm.ethosu_partitioner import EthosUPartitioner\n",
166+
"from executorch.backends.arm import EthosUPartitioner\n",
167167
"from executorch.exir import (\n",
168168
" EdgeCompileConfig,\n",
169169
" ExecutorchBackendConfig,\n",
170170
" to_edge_transform_and_lower,\n",
171171
")\n",
172172
"from executorch.extension.export_util.utils import save_pte_program\n",
173-
"import platform \n",
173+
"import platform\n",
174174
"\n",
175-
"# Create partitioner from compile spec \n",
175+
"# Create partitioner from compile spec\n",
176176
"partitioner = EthosUPartitioner(compile_spec)\n",
177177
"\n",
178178
"# Lower the exported program to the Ethos-U backend\n",
@@ -185,8 +185,8 @@
185185
" )\n",
186186
"\n",
187187
"# Load quantization ops library\n",
188-
"os_aot_lib_names = {\"Darwin\" : \"libquantized_ops_aot_lib.dylib\", \n",
189-
" \"Linux\" : \"libquantized_ops_aot_lib.so\", \n",
188+
"os_aot_lib_names = {\"Darwin\" : \"libquantized_ops_aot_lib.dylib\",\n",
189+
" \"Linux\" : \"libquantized_ops_aot_lib.so\",\n",
190190
" \"Windows\": \"libquantized_ops_aot_lib.dll\"}\n",
191191
"aot_lib_name = os_aot_lib_names[platform.system()]\n",
192192
"\n",
@@ -226,7 +226,7 @@
226226
"metadata": {},
227227
"outputs": [],
228228
"source": [
229-
"# Build executorch \n",
229+
"# Build executorch\n",
230230
"subprocess.run(os.path.join(script_dir, \"build_executorch.sh\"), shell=True, cwd=et_dir)\n",
231231
"\n",
232232
"# Build portable kernels\n",

0 commit comments

Comments
 (0)