Skip to content

Commit d827cf7

Browse files
Revert "NXP backend: Add support for AdaptiveAvgPool1d, fix AdaptiveAvgPool1d tests, add check for 4D pool ops inputs" (pytorch#21922)
Reverts pytorch#21740 Broke a lot of internal builds due to buck issues. # was too high to forward fix
1 parent e25f129 commit d827cf7

59 files changed

Lines changed: 274 additions & 343 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/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.ops_aliases import (
11+
from executorch.backends.nxp.tests.ops_aliases import (
1212
AddTensor,
1313
Amax,
1414
Amin,

‎backends/nxp/backend/ir/converter/node_converters/ops_converters/adaptive_avg_pool_2d_converter.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import executorch.backends.nxp.backend.ir.lib.tflite.Padding as tflPadding
77
import torch
88

9-
from executorch.backends.nxp.backend.edge_helper import input_rank
109
from executorch.backends.nxp.backend.ir.converter.conversion import common
1110
from executorch.backends.nxp.backend.ir.converter.node_converter import (
1211
CustomDelegationOptions,
@@ -46,10 +45,6 @@ def _is_supported_in_IR(
4645
parameters_mapping: dict[str, Parameter],
4746
custom_delegation_options: CustomDelegationOptions,
4847
) -> bool:
49-
# The input must be 4D.
50-
if input_rank(node, 0) != 4:
51-
return False
52-
5348
input_size = node.args[0].meta["val"].shape
5449
output_size = node.args[1]
5550

‎backends/nxp/backend/ir/converter/node_converters/ops_converters/avg_pool_2d_converter.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import numpy as np
77
import torch
8-
9-
from executorch.backends.nxp.backend.edge_helper import input_rank
108
from executorch.backends.nxp.backend.ir.converter.conversion import (
119
aten_translator,
1210
common,
@@ -38,10 +36,6 @@ def _is_supported_in_IR(
3836
parameters_mapping: dict[str, Parameter],
3937
custom_delegation_options: CustomDelegationOptions,
4038
) -> bool:
41-
# The input must be 4D.
42-
if input_rank(node, 0) != 4:
43-
return False
44-
4539
n_args = len(node.args)
4640

4741
padding = node.args[3] if n_args >= 4 else [0, 0]

‎backends/nxp/backend/ir/converter/node_converters/ops_converters/max_pool2d_with_indices_converter.py‎

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

88
import numpy as np
99
import torch
10-
from executorch.backends.nxp.backend.edge_helper import input_rank, try_get_arg
10+
from executorch.backends.nxp.backend.edge_helper import try_get_arg
1111
from executorch.backends.nxp.backend.ir.converter.conversion import (
1212
aten_translator,
1313
common,
@@ -42,10 +42,6 @@ def _is_supported_in_IR(
4242
parameters_mapping: dict[str, Parameter],
4343
custom_delegation_options: CustomDelegationOptions,
4444
) -> bool:
45-
# The input must be 4D.
46-
if input_rank(node, 0) != 4:
47-
return False
48-
4945
kernel_size, stride, padding, dilation, ceil_mode = (
5046
MaxPool2DWithIndicesConverter._get_node_args(node)
5147
)

‎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.ops_aliases import (
18+
from executorch.backends.nxp.tests.ops_aliases import (
1919
AdaptiveAvgPool2D,
2020
Amax,
2121
Amin,

‎backends/nxp/edge_passes/move_auxiliary_operator_into_separate_qdq_cluster_pass.py‎

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@
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+
import operator
7+
68
import torch
79

810
from executorch.backends.nxp.edge_passes.neutron_edge_pass import NeutronEdgePass
911
from executorch.backends.nxp.neutron_partitioner import QDQClusterRecognizer
12+
from executorch.backends.nxp.tests.ops_aliases import PermuteCopy
1013

11-
from executorch.backends.nxp.ops_aliases import (
12-
AdaptiveAvgPool2D,
13-
AddMM,
14-
AvgPool2D,
15-
Clone,
16-
CloneDimOrder,
17-
Convolution,
18-
DequantizePerTensor,
19-
GetItem,
20-
HardTanh,
21-
MaxPool2DWithIndices,
22-
MM,
23-
PermuteCopy,
24-
QuantizePerTensor,
25-
Relu,
26-
Sigmoid,
27-
SqueezeCopy,
28-
Tanh,
29-
UnsqueezeCopy,
30-
ViewCopy,
31-
)
14+
# noinspection PyProtectedMember
15+
from executorch.exir.dialects._ops import ops as exir_ops
3216
from torch.fx import Node
3317
from torch.fx.passes.infra.pass_base import PassResult
3418

19+
# Operator aliases for better readability.
20+
AddMM = exir_ops.edge.aten.addmm.default
21+
AvgPool2D = exir_ops.edge.aten.avg_pool2d.default
22+
MaxPool2D = exir_ops.edge.aten.max_pool2d_with_indices.default
23+
Conv = exir_ops.edge.aten.convolution.default
24+
Clone = exir_ops.edge.aten.clone.default
25+
CloneDimOrder = exir_ops.edge.dim_order_ops._clone_dim_order.default
26+
Getitem = operator.getitem
27+
HardTanh = exir_ops.edge.aten.hardtanh.default
28+
MM = exir_ops.edge.aten.mm.default
29+
Relu = exir_ops.edge.aten.relu.default
30+
Sigmoid = exir_ops.edge.aten.sigmoid.default
31+
SqueezeCopy = exir_ops.edge.aten.squeeze_copy.dims
32+
Tanh = exir_ops.edge.aten.tanh.default
33+
UnsqueezeCopy = exir_ops.edge.aten.unsqueeze_copy.default
34+
ViewCopy = exir_ops.edge.aten.view_copy.default
35+
3536

3637
def insert_qdq_pair_after_node(
3738
graph: torch.fx.Graph, anchor: torch.fx.Node, q_params: tuple
@@ -40,7 +41,7 @@ def insert_qdq_pair_after_node(
4041
with graph.inserting_after(anchor):
4142
quantize_op = graph.create_node(
4243
op="call_function",
43-
target=QuantizePerTensor,
44+
target=exir_ops.edge.quantized_decomposed.quantize_per_tensor.default,
4445
args=(), # Will be added later.
4546
)
4647
quantize_op.meta = anchor.meta
@@ -49,7 +50,7 @@ def insert_qdq_pair_after_node(
4950
with graph.inserting_after(quantize_op):
5051
dequantize_op = graph.create_node(
5152
op="call_function",
52-
target=DequantizePerTensor,
53+
target=exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,
5354
args=(quantize_op,) + q_params,
5455
)
5556
dequantize_op.meta = quantize_op.meta
@@ -64,15 +65,17 @@ def _is_dequantize(node_: Node) -> bool:
6465
return (
6566
hasattr(node_, "op")
6667
and node_.op == "call_function"
67-
and node_.target == DequantizePerTensor
68+
and node_.target
69+
== exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default
6870
)
6971

7072

7173
def _is_quantize(node_: Node) -> bool:
7274
return (
7375
hasattr(node_, "op")
7476
and node_.op == "call_function"
75-
and node_.target == QuantizePerTensor
77+
and node_.target
78+
== exir_ops.edge.quantized_decomposed.quantize_per_tensor.default
7679
)
7780

7881

@@ -114,7 +117,7 @@ class MoveLeadingAuxiliaryOperatorIntoSeparateQDQClusterPass(NeutronEdgePass):
114117
PermuteCopy,
115118
],
116119
ViewCopy: [Clone, CloneDimOrder],
117-
Convolution: [
120+
Conv: [
118121
ViewCopy, # For 1D conv
119122
],
120123
# AvgPool1D is represented in edge as Unsqueeze -> AvgPool2D -> Squeeze. The reshaping nodes must be moved out
@@ -123,15 +126,9 @@ class MoveLeadingAuxiliaryOperatorIntoSeparateQDQClusterPass(NeutronEdgePass):
123126
ViewCopy,
124127
UnsqueezeCopy,
125128
],
126-
# MaxPool1D is represented in edge as Unsqueeze -> MaxPool2D -> GetItem -> Squeeze. The reshaping nodes must be moved out
129+
# MaxPool1D is represented in edge as Unsqueeze -> MaxPool2D -> Getitem -> Squeeze. The reshaping nodes must be moved out
127130
# of the cluster. Instead of [Un]squeeze, ViewCopy can be used as well.
128-
MaxPool2DWithIndices: [
129-
ViewCopy,
130-
UnsqueezeCopy,
131-
],
132-
# AdaptiveAvgPool1D is represented in edge as Unsqueeze -> AdaptiveAvgPool2D -> Squeeze. The reshaping nodes
133-
# must be moved out of the cluster. Instead of [Un]squeeze, ViewCopy can be used as well.
134-
AdaptiveAvgPool2D: [
131+
MaxPool2D: [
135132
ViewCopy,
136133
UnsqueezeCopy,
137134
],
@@ -225,7 +222,7 @@ class MoveTrailingAuxiliaryOperatorIntoSeparateQDQClusterPass(NeutronEdgePass):
225222
Sigmoid,
226223
Tanh,
227224
],
228-
Convolution: [
225+
Conv: [
229226
HardTanh,
230227
Relu,
231228
Sigmoid,
@@ -239,15 +236,9 @@ class MoveTrailingAuxiliaryOperatorIntoSeparateQDQClusterPass(NeutronEdgePass):
239236
ViewCopy,
240237
SqueezeCopy,
241238
],
242-
# MaxPool1D is represented in edge as Unsqueeze -> MaxPool2D -> GetItem -> Squeeze. The reshaping nodes must be moved out
239+
# MaxPool1D is represented in edge as Unsqueeze -> MaxPool2D -> Getitem -> Squeeze. The reshaping nodes must be moved out
243240
# of the cluster. Instead of [Un]squeeze, ViewCopy can be used as well.
244-
GetItem: [
245-
ViewCopy,
246-
SqueezeCopy,
247-
],
248-
# AdaptiveAvgPool1D is represented in edge as Unsqueeze -> AdaptiveAvgPool2D -> Squeeze. The reshaping nodes
249-
# must be moved out of the cluster. Instead of [Un]squeeze, ViewCopy can be used as well.
250-
AdaptiveAvgPool2D: [
241+
Getitem: [
251242
ViewCopy,
252243
SqueezeCopy,
253244
],
@@ -287,7 +278,7 @@ def run(self, graph_module: torch.fx.GraphModule) -> PassResult:
287278
# satisfy the requirements of the `QDQClusterRecognizer`.
288279
actual_main_cluster_node = (
289280
main_cluster_node
290-
if main_cluster_node.target != GetItem
281+
if main_cluster_node.target != Getitem
291282
else main_cluster_node.args[0]
292283
)
293284
cluster = QDQClusterRecognizer().get_qdq_cluster(actual_main_cluster_node)

‎backends/nxp/quantizer/neutron_quantizer.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
from executorch.backends.nxp.quantizer.patterns import (
1414
AbsPattern,
1515
ActivationsConcatClusterPattern,
16-
AdaptiveAvgPool1DPattern,
17-
AdaptiveAvgPool2DPattern,
16+
AdaptiveAvgPoolPattern,
1817
AddmmPattern,
1918
AddTensorPattern,
2019
AmaxPattern,
@@ -268,8 +267,7 @@ def __init__(self, neutron_target_spec: NeutronTargetSpec, is_qat: bool = False)
268267
super().__init__(
269268
[
270269
OpQuantizer(AbsPattern(is_qat=is_qat), static_qconfig),
271-
OpQuantizer(AdaptiveAvgPool1DPattern(is_qat=is_qat), static_qconfig),
272-
OpQuantizer(AdaptiveAvgPool2DPattern(is_qat=is_qat), static_qconfig),
270+
OpQuantizer(AdaptiveAvgPoolPattern(is_qat=is_qat), static_qconfig),
273271
OpQuantizer(AddTensorPattern(is_qat=is_qat), static_qconfig),
274272
OpQuantizer(AddmmPattern(self, is_qat=is_qat), static_fc_qconfig),
275273
OpQuantizer(AmaxPattern(is_qat=is_qat), static_qconfig),

‎backends/nxp/quantizer/patterns.py‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,7 @@ def partition_types(self):
279279
return [torch.ops.aten.abs.default]
280280

281281

282-
class AdaptiveAvgPool1DPattern(SharedSpecPattern):
283-
"""
284-
Quantizer for AdaptiveAvgPool1D operator.
285-
"""
286-
287-
def partition_types(self):
288-
return [torch.ops.aten.adaptive_avg_pool1d.default]
289-
290-
291-
class AdaptiveAvgPool2DPattern(SharedSpecPattern):
282+
class AdaptiveAvgPoolPattern(SharedSpecPattern):
292283
"""
293284
Quantizer for AdaptiveAvgPool2D operator.
294285
"""

‎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,13 +15,6 @@
1515
from executorch.backends.nxp.aten_passes.neutron_aten_pass_manager import (
1616
NeutronAtenPassManager,
1717
)
18-
from executorch.backends.nxp.ops_aliases import (
19-
AdaptiveAvgPool2D,
20-
AvgPool2D,
21-
GetItem,
22-
MaxPool2DWithIndices,
23-
ViewCopy,
24-
)
2518
from executorch.backends.nxp.tests.dataset_creator import RandomDatasetCreator
2619
from executorch.backends.nxp.tests.executorch_pipeline import neutron_target_spec
2720
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
@@ -35,6 +28,13 @@
3528
MaxPool2dModule,
3629
)
3730
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,7 +13,6 @@
1313
ConvertDivToMulPass,
1414
NeutronAtenPassManager,
1515
)
16-
from executorch.backends.nxp.ops_aliases import MulTensor
1716
from executorch.backends.nxp.tests.dataset_creator import RandomDatasetCreator
1817
from executorch.backends.nxp.tests.executorch_pipeline import neutron_target_spec
1918
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
@@ -23,6 +22,7 @@
2322
StaticDivLinearModel,
2423
)
2524
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)

0 commit comments

Comments
 (0)