Skip to content

Commit b4c53c6

Browse files
Move the NXP op alias table out of the test package (pytorch#22592)
The NXP backend keeps a table of short names for edge operators, for example `AddTensor = exir_ops.edge.aten.add.Tensor`. It lives in the backend's test package, but three modules that ship in the wheel read it at import time: - `backend/edge_helper.py` - `backend/node_format_inference.py` - `edge_passes/move_auxiliary_operator_into_separate_qdq_cluster_pass.py` Two dozen production files import those modules, so the backend cannot load at all without a test package. The dependency points the wrong way: the tests should depend on the backend, not the backend on the tests. ### What this does The table has no test logic in it, so it moves to `backend/ops_aliases.py`, next to the code that reads it. That follows the shape the Arm backend already uses for shared operator constants in `backends/arm/constants.py`. The Buck target that published the table from the test package is removed, since the backend library already globs the directory it moves into. No behavior changes. The names, values and every importer stay the same, including the roughly fifty tests that use the table. ### Why the diff looks larger than it is Most of it is one line per file. Every importer switches from `nxp.tests.ops_aliases` to `nxp.backend.ops_aliases`, and because `backend` sorts before `tests`, the import sorter then moves that line to the top of the block. So a one line change shows up as several lines moving in some files. No code changed in any of them. ### Test plan Imported the moved module and every updated importer from an installed wheel, and confirmed the table exposes the same names bound to the same values as before the move. Compared the alias assignments before and after by parsing both files: 56 aliases, no names added or removed, no values changed. Checked that every NXP test target can still reach the table, through the backend library that already globs that directory, and that no reference to the old Buck target or the old import path remains anywhere in the tree. Ran the formatter and linter over all changed files. Co-authored-by: PyTorch Bot <pytorchbot@users.noreply.github.com>
1 parent 9b3f660 commit b4c53c6

54 files changed

Lines changed: 206 additions & 214 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎backends/nxp/BUCK‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fbcode_target(_kind = runtime.python_library,
6868
"fbsource//third-party/pypi/neutron_converter:neutron_converter",
6969
"//caffe2:torch",
7070
"//executorch/exir:lib",
71-
"//executorch/backends/nxp/tests:ops_aliases",
7271
],
7372
)
7473

‎backends/nxp/backend/edge_helper.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.nxp.tests.ops_aliases import (
11+
from executorch.backends.nxp.backend.ops_aliases import (
1212
AddTensor,
1313
Amax,
1414
Amin,

‎backends/nxp/backend/node_format_inference.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
try_get_arg,
1616
)
1717
from executorch.backends.nxp.backend.edge_program_converter import functions_converters
18-
from executorch.backends.nxp.tests.ops_aliases import (
18+
from executorch.backends.nxp.backend.ops_aliases import (
1919
AdaptiveAvgPool2D,
2020
Amax,
2121
Amin,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
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.
55

6-
# This file defines ops aliases for shorter and more readable test description. List is sorted alphabetically.
7-
# When finding a missing alias, add it at the correct place.
6+
# This file defines ops aliases for shorter and more readable descriptions of edge operators.
7+
# List is sorted alphabetically. When finding a missing alias, add it at the correct place.
88

99
import operator
1010

‎backends/nxp/edge_passes/move_auxiliary_operator_into_separate_qdq_cluster_pass.py‎

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

88
import torch
9+
from executorch.backends.nxp.backend.ops_aliases import PermuteCopy
910

1011
from executorch.backends.nxp.edge_passes.neutron_edge_pass import NeutronEdgePass
1112
from executorch.backends.nxp.neutron_partitioner import QDQClusterRecognizer
12-
from executorch.backends.nxp.tests.ops_aliases import PermuteCopy
1313

1414
# noinspection PyProtectedMember
1515
from executorch.exir.dialects._ops import ops as exir_ops

‎backends/nxp/tests/BUCK‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ load("@fbcode_macros//build_defs:python_pytest.bzl", "python_pytest")
44

55
oncall("executorch")
66

7-
fbcode_target(_kind = runtime.python_library,
8-
name = "ops_aliases",
9-
srcs = [
10-
"ops_aliases.py",
11-
],
12-
deps = [
13-
"//caffe2:torch",
14-
"//executorch/exir:lib",
15-
],
16-
)
17-
187
fbcode_target(_kind = runtime.python_library,
198
name = "models",
209
srcs = [

‎backends/nxp/tests/generic_tests/test_add_batch_size_for_3d_input_pool_2d_ops.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
from executorch.backends.nxp.aten_passes.neutron_aten_pass_manager import (
1616
NeutronAtenPassManager,
1717
)
18+
from executorch.backends.nxp.backend.ops_aliases import (
19+
AdaptiveAvgPool2D,
20+
AvgPool2D,
21+
GetItem,
22+
MaxPool2DWithIndices,
23+
ViewCopy,
24+
)
1825
from executorch.backends.nxp.tests.dataset_creator import RandomDatasetCreator
1926
from executorch.backends.nxp.tests.executorch_pipeline import neutron_target_spec
2027
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
@@ -28,13 +35,6 @@
2835
MaxPool2dModule,
2936
)
3037
from executorch.backends.nxp.tests.nsys_testing import lower_run_compare
31-
from executorch.backends.nxp.tests.ops_aliases import (
32-
AdaptiveAvgPool2D,
33-
AvgPool2D,
34-
GetItem,
35-
MaxPool2DWithIndices,
36-
ViewCopy,
37-
)
3838

3939

4040
@pytest.fixture(autouse=True)

‎backends/nxp/tests/generic_tests/test_convert_div_to_mul.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ConvertDivToMulPass,
1414
NeutronAtenPassManager,
1515
)
16+
from executorch.backends.nxp.backend.ops_aliases import MulTensor
1617
from executorch.backends.nxp.tests.dataset_creator import RandomDatasetCreator
1718
from executorch.backends.nxp.tests.executorch_pipeline import neutron_target_spec
1819
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
@@ -22,7 +23,6 @@
2223
StaticDivLinearModel,
2324
)
2425
from executorch.backends.nxp.tests.nsys_testing import lower_run_compare
25-
from executorch.backends.nxp.tests.ops_aliases import MulTensor
2626

2727

2828
@pytest.fixture(autouse=True)

‎backends/nxp/tests/generic_tests/test_convert_scalar_to_attr.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from executorch.backends.nxp.backend.edge_helper import (
1919
try_get_tensor_constant_from_node,
2020
)
21+
from executorch.backends.nxp.backend.ops_aliases import AddTensor, MulTensor, SubTensor
2122
from executorch.backends.nxp.tests.dataset_creator import RandomDatasetCreator
2223
from executorch.backends.nxp.tests.executorch_pipeline import neutron_target_spec
2324
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
@@ -31,7 +32,6 @@
3132
AllCloseOutputComparator,
3233
lower_run_compare,
3334
)
34-
from executorch.backends.nxp.tests.ops_aliases import AddTensor, MulTensor, SubTensor
3535

3636

3737
@pytest.fixture(autouse=True)

‎backends/nxp/tests/generic_tests/test_decompose_split_to_slices.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
NeutronAtenPassManager,
1313
SplitGRUBasedOnNumLayers,
1414
)
15+
from executorch.backends.nxp.backend.ops_aliases import SliceCopy
1516
from executorch.backends.nxp.tests.executorch_pipeline import neutron_target_spec
1617
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
1718
from executorch.backends.nxp.tests.graph_verifier import DetailedGraphVerifier
@@ -21,7 +22,6 @@
2122
SplitWithSize,
2223
)
2324
from executorch.backends.nxp.tests.nsys_testing import lower_run_compare
24-
from executorch.backends.nxp.tests.ops_aliases import SliceCopy
2525

2626

2727
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)