2424import hypothesis .strategies as st
2525import argparse
2626
27+ import numpy as np
28+ from functools import partial
29+
2730
2831class TestPool2dOp (AutoScanTest ):
2932 def __init__ (self , * args , ** kwargs ):
@@ -87,13 +90,15 @@ def sample_program_configs(self, draw):
8790 ksize = draw (
8891 st .lists (
8992 st .integers (
90- min_value = 1 , max_value = 32 ), min_size = 2 , max_size = 2 ))
93+ min_value = 1 , max_value = 7 ), min_size = 2 , max_size = 2 ))
9194 strides = draw (
9295 st .lists (
9396 st .integers (
94- min_value = 1 , max_value = 2 ), min_size = 2 , max_size = 2 ))
97+ min_value = 1 , max_value = 16 ), min_size = 2 , max_size = 2 ))
9598 paddings = draw (
96- st .sampled_from ([[0 , 0 ], [0 , 0 , 0 , 0 ], [1 , 1 ], [1 , 1 , 1 , 1 ]]))
99+ st .lists (
100+ st .integers (
101+ min_value = 0 , max_value = 16 ), min_size = 2 , max_size = 2 ))
97102 padding_algorithm = draw (
98103 st .sampled_from (["EXPLICIT" , "VALID" , "SAME" ]))
99104 pooling_type = draw (st .sampled_from (["max" , "avg" ]))
@@ -104,21 +109,18 @@ def sample_program_configs(self, draw):
104109 use_cudnn = False
105110 use_mkldnn = False
106111 use_quantizer = False
107- is_test = False
112+ is_test = True
108113 data_format = "NCHW"
109- assume (ksize [0 ] <= (in_shape [2 ] - strides [0 ] - 1 ))
110- assume (ksize [1 ] <= (in_shape [3 ] - strides [1 ] - 1 ))
111- if paddings [0 ] == 1 :
112- assume ((ksize [0 ] != 1 and ksize [1 ] != 1 ))
113114
114- #This is the correct input when adaptive
115- if adaptive :
116- assume (in_shape [2 ] / ksize [0 ] == strides [0 ])
117- assume (in_shape [3 ] / ksize [1 ] == strides [1 ])
115+ assume (ksize [0 ] <= in_shape [2 ])
116+ assume (ksize [1 ] <= in_shape [3 ])
117+ if adaptive == False :
118+ assume (ksize [0 ] > paddings [0 ] and ksize [1 ] > paddings [1 ])
119+ if adaptive == False and ceil_mode == True :
120+ assume (strides [0 ] > 1 and strides [1 ] > 1 )
118121
119- #both paddle and lite have invalid output, so it is an invalid input.
120- if paddings == [0 , 0 ] or paddings == [0 , 0 , 0 , 0 ]:
121- assume (ceil_mode == False )
122+ def generate_input (* args , ** kwargs ):
123+ return np .random .normal (0.0 , 1.0 , in_shape ).astype (np .float32 )
122124
123125 build_ops = OpConfig (
124126 type = "pool2d" ,
@@ -143,7 +145,9 @@ def sample_program_configs(self, draw):
143145 program_config = ProgramConfig (
144146 ops = [build_ops ],
145147 weights = {},
146- inputs = {"input_data" : TensorConfig (shape = in_shape )},
148+ inputs = {
149+ "input_data" : TensorConfig (data_gen = partial (generate_input ))
150+ },
147151 outputs = ["output_data" ])
148152 return program_config
149153
@@ -167,9 +171,6 @@ def teller1(program_config, predictor_config):
167171 if program_config .ops [0 ].attrs ["ceil_mode" ] == True \
168172 and strides [0 ] != strides [1 ]:
169173 return True
170- if predictor_config .target () == TargetType .OpenCL :
171- if program_config .ops [0 ].attrs ["adaptive" ] == True :
172- return True
173174
174175 self .add_ignore_check_case (
175176 teller1 , IgnoreReasons .ACCURACY_ERROR ,
@@ -193,11 +194,7 @@ def teller2(program_config, predictor_config):
193194
194195 def teller3 (program_config , predictor_config ):
195196 if predictor_config .target () == TargetType .ARM :
196- # This is an paddle error, when padding_algorithm == "Valid" with exclusive is False
197- if program_config .ops [0 ].attrs [
198- "padding_algorithm" ] == "VALID" and program_config .ops [
199- 0 ].attrs ["exclusive" ] == False :
200- return True
197+ return True
201198
202199 self .add_ignore_check_case (
203200 teller3 , IgnoreReasons .PADDLE_NOT_SUPPORT ,
@@ -209,7 +206,7 @@ def test(self, *args, **kwargs):
209206 max_examples = 100
210207 if target_str == "OpenCL" :
211208 # Make sure to generate enough valid cases for OpenCL
212- max_examples = 300
209+ max_examples = 200
213210 if target_str == "Metal" :
214211 # Make sure to generate enough valid cases for Metal
215212 max_examples = 500
0 commit comments