Skip to content

Commit e0755f9

Browse files
Cortex-M: Fix circular dependency (pytorch#22896)
Move utils file to top level to avoid operators <==> passes dependency, which could lead to a circular dependency. Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
1 parent 7f1d82b commit e0755f9

14 files changed

Lines changed: 43 additions & 42 deletions

‎backends/cortex_m/BUCK‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
99

1010
oncall("executorch")
1111

12+
fbcode_target(
13+
_kind = python_library,
14+
name = "utils",
15+
srcs = [
16+
"utils.py",
17+
],
18+
deps = [
19+
"//caffe2:torch",
20+
"//executorch/exir/dialects:lib",
21+
],
22+
)
23+
1224
fbcode_target(
1325
_kind = python_library,
1426
name = "quantizer_reporter",

‎backends/cortex_m/ops/BUCK‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fbcode_target(_kind = runtime.python_library,
3030
],
3131
deps = [
3232
"fbcode//caffe2:torch",
33-
"//executorch/backends/cortex_m/passes:passes_utils",
33+
"//executorch/backends/cortex_m:utils",
3434
"//executorch/backends/cortex_m/quantizer:quantization_configs",
3535
"//executorch/exir:_warnings",
3636
],

‎backends/cortex_m/ops/operators.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111

1212
import torch
1313
import torch.nn.functional as F
14-
from executorch.backends.cortex_m.passes.passes_utils import (
14+
from executorch.backends.cortex_m.quantizer.quantization_configs import (
15+
CMSIS_SOFTMAX_SCALE,
16+
CMSIS_SOFTMAX_ZERO_POINT,
17+
)
18+
from executorch.backends.cortex_m.utils import (
1519
dequantize_per_tensor_cmsis,
1620
is_channel_broadcast,
1721
is_channels_last,
1822
quantize_per_tensor_cmsis,
1923
requantize_cmsis,
2024
SHIFT_INT8,
2125
)
22-
from executorch.backends.cortex_m.quantizer.quantization_configs import (
23-
CMSIS_SOFTMAX_SCALE,
24-
CMSIS_SOFTMAX_ZERO_POINT,
25-
)
2626
from executorch.exir._warnings import experimental
2727
from executorch.exir.dialects._ops import ops as exir_ops
2828

‎backends/cortex_m/passes/BUCK‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fbcode_target(_kind = runtime.python_library,
2121
"//executorch/exir:pass_base",
2222
"//executorch/exir/dialects:lib",
2323
"//executorch/backends/cortex_m/ops:ops",
24-
"//executorch/backends/cortex_m/passes:passes_utils",
24+
"//executorch/backends/cortex_m:utils",
2525
],
2626
)
2727

@@ -48,7 +48,7 @@ fbcode_target(_kind = runtime.python_library,
4848
"//executorch/backends/cortex_m:cmsis_nn",
4949
"//executorch/backends/cortex_m:target_config",
5050
"//executorch/backends/cortex_m/ops:ops",
51-
"//executorch/backends/cortex_m/passes:passes_utils",
51+
"//executorch/backends/cortex_m:utils",
5252
"//executorch/backends/cortex_m/passes:replace_quant_nodes_pass",
5353
"//executorch/backends/transforms:aten_to_dialect_pass",
5454
"//executorch/backends/transforms:canonicalize_view_copy_permute_pass",
@@ -67,14 +67,3 @@ fbcode_target(_kind = runtime.python_library,
6767
"//executorch/exir/program:lib",
6868
],
6969
)
70-
71-
fbcode_target(_kind = runtime.python_library,
72-
name="passes_utils",
73-
srcs=[
74-
"passes_utils.py",
75-
],
76-
deps=[
77-
"fbcode//caffe2:torch",
78-
"//executorch/exir/dialects:lib",
79-
],
80-
)

‎backends/cortex_m/passes/activation_fusion_pass.py‎

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

99
import executorch.backends.cortex_m.ops.operators # noqa: F401
1010
from executorch.backends.arm._passes.quant_args import QuantArgs
11-
from executorch.backends.cortex_m.passes.passes_utils import (
11+
from executorch.backends.cortex_m.utils import (
1212
get_activation_bounds,
1313
quantize_val,
1414
skips_quantized_max_pool2d,

‎backends/cortex_m/passes/aten_to_cortex_m_pass.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
import torch.fx
1616
from executorch.backends.arm._passes.arm_pass_utils import get_first_fake_tensor
1717
from executorch.backends.cortex_m.library import cmsis_nn
18+
from executorch.backends.cortex_m.quantizer.quantization_configs import (
19+
CMSIS_SOFTMAX_SCALE,
20+
CMSIS_SOFTMAX_ZERO_POINT,
21+
)
22+
from executorch.backends.cortex_m.target_config import CortexMTargetConfig
1823

19-
from executorch.backends.cortex_m.passes.passes_utils import (
24+
from executorch.backends.cortex_m.utils import (
2025
build_activation_lut,
2126
is_foldable_alpha,
2227
quantize_multiplier_aot,
2328
quantize_val,
2429
SHIFT_INT8,
2530
to_physical_order,
2631
)
27-
from executorch.backends.cortex_m.quantizer.quantization_configs import (
28-
CMSIS_SOFTMAX_SCALE,
29-
CMSIS_SOFTMAX_ZERO_POINT,
30-
)
31-
from executorch.backends.cortex_m.target_config import CortexMTargetConfig
3232
from executorch.backends.transforms.aten_to_dialect_pass import (
3333
AtenToDialectPass,
3434
DialectNodeSpec,

‎backends/cortex_m/passes/decompose_hardswish_pass.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import torch
1212
from executorch.backends.arm._passes.quant_args import QuantArgs
1313

14-
from executorch.backends.cortex_m.passes.passes_utils import quantize_val
14+
from executorch.backends.cortex_m.utils import quantize_val
1515

1616
from executorch.exir.dialects._ops import ops as exir_ops
1717
from executorch.exir.pass_base import ExportPass

‎backends/cortex_m/passes/explicit_layout_pass.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2026 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
67

78
import executorch.backends.transforms.channels_last_ops # noqa: F401
89

910
import torch
10-
from executorch.backends.cortex_m.passes.passes_utils import (
11+
from executorch.backends.cortex_m.utils import (
1112
coerce_int_pair,
1213
skips_quantized_max_pool2d,
1314
)

‎backends/cortex_m/passes/quantized_clamp_activation_pass.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from executorch.backends.arm._passes.fold_qdq_with_annotated_qparams_pass import (
1212
get_output_qparams,
1313
)
14-
from executorch.backends.cortex_m.passes.passes_utils import (
15-
get_activation_bounds,
16-
quantize_val,
17-
)
14+
from executorch.backends.cortex_m.utils import get_activation_bounds, quantize_val
1815
from executorch.exir.dialects._ops import ops as exir_ops
1916
from executorch.exir.pass_base import ExportPass
2017
from torch.fx import GraphModule, Node

‎backends/cortex_m/quantizer/pattern_checkers.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
from executorch.backends.arm._passes.arm_pass_utils import get_first_fake_tensor
88
from executorch.backends.arm.quantizer.arm_quantizer_utils import PatternCheck
99
from executorch.backends.arm.quantizer.quantization_config import QuantizationConfig
10-
from executorch.backends.cortex_m.passes.passes_utils import (
10+
from executorch.backends.cortex_m.quantizer.quantization_configs import (
11+
CMSIS_SOFTMAX_SCALE,
12+
CMSIS_SOFTMAX_ZERO_POINT,
13+
)
14+
from executorch.backends.cortex_m.utils import (
1115
coerce_int_pair,
1216
is_channel_broadcast,
1317
is_channels_last,
1418
is_foldable_alpha,
1519
)
16-
from executorch.backends.cortex_m.quantizer.quantization_configs import (
17-
CMSIS_SOFTMAX_SCALE,
18-
CMSIS_SOFTMAX_ZERO_POINT,
19-
)
2020
from torch.fx import Node
2121
from torchao.quantization.pt2e.quantizer import (
2222
FixedQParamsQuantizationSpec,

0 commit comments

Comments
 (0)