88"""
99Tests for max_pool1d operation.
1010
11- max_pool1d is decomposed by PyTorch into:
12- unsqueeze -> max_pool2d_with_indices -> getitem -> squeeze
11+ max_pool1d is decomposed by DecomposeMaxPool1dPass into:
12+ view_copy -> max_pool2d -> view_copy
1313
14- This test verifies that the decomposed pattern is correctly quantized and
14+ This is done before quantization to ensure proper qparams propagation.
15+ The test verifies that the decomposed pattern is correctly quantized and
1516delegated to the Arm backend (U55/U85).
1617"""
1718
18- import pytest
1919from typing import Tuple
2020
2121import torch
@@ -50,6 +50,7 @@ def forward(self, x):
5050 return self .max_pool_1d (x )
5151
5252
53+ # Test data for TOSA pipelines (no stride constraints)
5354test_data_suite = {
5455 # (test_name, test_data, [kernel_size, stride, padding])
5556 "simple" : lambda : (torch .rand (1 , 16 , 50 ), [4 , 2 , 0 ]),
@@ -59,65 +60,82 @@ def forward(self, x):
5960 "multi_batch" : lambda : (torch .rand (4 , 16 , 50 ), [4 , 2 , 0 ]),
6061}
6162
62- # After PyTorch decomposition, max_pool1d becomes max_pool2d_with_indices
63- # After to_edge, becomes max_pool2d in edge dialect
64- aten_op = "torch.ops.aten.max_pool1d.default"
63+ # Test data for U55/U85 pipelines (stride must be <= 3)
64+ test_data_suite_u55 = {
65+ # (test_name, test_data, [kernel_size, stride, padding])
66+ "simple" : lambda : (torch .rand (1 , 16 , 50 ), [4 , 2 , 0 ]),
67+ "with_padding" : lambda : (torch .rand (1 , 16 , 50 ), [3 , 2 , 1 ]),
68+ "stride_1" : lambda : (torch .rand (1 , 8 , 32 ), [3 , 1 , 0 ]),
69+ "stride_3" : lambda : (torch .rand (1 , 4 , 64 ), [8 , 3 , 0 ]),
70+ }
71+
72+ # max_pool1d is decomposed before quantization by DecomposeMaxPool1dPass
73+ # After the pass, max_pool1d becomes view_copy -> max_pool2d -> view_copy
74+ # So for the INT (quantized) tests we should not expect max_pool1d
75+ aten_op_INT = "torch.ops.aten.view_copy.default"
76+ # For FP (non-quantized) tests, max_pool1d remains
77+ aten_op_FP = "torch.ops.aten.max_pool1d.default"
78+ # After decomposition and passes, becomes max_pool2d in edge dialect
6579exir_op = "executorch_exir_dialects_edge__ops_aten_max_pool2d_default"
6680
6781
6882@common .parametrize ("test_data" , test_data_suite )
69- @pytest .mark .xfail (reason = "MaxPool1D not yet supported" , strict = False )
7083def test_max_pool1d_tosa_FP (test_data : torch .Tensor ):
7184 """Test max_pool1d with TOSA FP pipeline."""
7285 test_data , model_params = test_data ()
7386 pipeline = TosaPipelineFP [input_t1 ](
7487 MaxPool1d (* model_params ),
7588 (test_data ,),
76- aten_op ,
89+ aten_op_FP ,
7790 exir_op ,
7891 )
7992 pipeline .run ()
8093
8194
8295@common .parametrize ("test_data" , test_data_suite )
83- @pytest .mark .xfail (reason = "MaxPool1D not yet supported" , strict = False )
8496def test_max_pool1d_tosa_INT (test_data : torch .Tensor ):
8597 """Test max_pool1d with TOSA INT pipeline (quantized)."""
8698 test_data , model_params = test_data ()
8799 pipeline = TosaPipelineINT [input_t1 ](
88100 MaxPool1d (* model_params ),
89101 (test_data ,),
90- aten_op ,
102+ aten_op_INT ,
91103 exir_op ,
92104 )
93105 pipeline .run ()
94106
95107
96- @common .parametrize ("test_data" , test_data_suite )
97- @pytest .mark .xfail (reason = "MaxPool1D not yet supported" , strict = False )
108+ @common .parametrize ("test_data" , test_data_suite_u55 )
98109@common .XfailIfNoCorstone300
99110def test_max_pool1d_u55_INT (test_data : torch .Tensor ):
100- """Test max_pool1d on Ethos-U55 (quantized)."""
111+ """Test max_pool1d on Ethos-U55 (quantized).
112+
113+ Note: U55 has stride constraint <= 3, so we use test_data_suite_u55
114+ which excludes larger_kernel (stride=4).
115+ """
101116 test_data , model_params = test_data ()
102117 pipeline = EthosU55PipelineINT [input_t1 ](
103118 MaxPool1d (* model_params ),
104119 (test_data ,),
105- aten_op ,
120+ aten_op_INT ,
106121 exir_ops = [],
107122 )
108123 pipeline .run ()
109124
110125
111- @common .parametrize ("test_data" , test_data_suite )
112- @pytest .mark .xfail (reason = "MaxPool1D not yet supported" , strict = False )
126+ @common .parametrize ("test_data" , test_data_suite_u55 )
113127@common .XfailIfNoCorstone320
114128def test_max_pool1d_u85_INT (test_data : torch .Tensor ):
115- """Test max_pool1d on Ethos-U85 (quantized)."""
129+ """Test max_pool1d on Ethos-U85 (quantized).
130+
131+ Note: U85 has stride constraint <= 3, so we use test_data_suite_u55
132+ which excludes larger_kernel (stride=4).
133+ """
116134 test_data , model_params = test_data ()
117135 pipeline = EthosU85PipelineINT [input_t1 ](
118136 MaxPool1d (* model_params ),
119137 (test_data ,),
120- aten_op ,
138+ aten_op_INT ,
121139 exir_ops = [],
122140 )
123141 pipeline .run ()
0 commit comments