Skip to content

Commit dfec1df

Browse files
committed
address comments
1 parent 8ebfc15 commit dfec1df

File tree

2 files changed

+41
-87
lines changed

2 files changed

+41
-87
lines changed

python/paddle/fluid/tests/unittests/test_conv2d_op.py

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ def conv2d_forward_naive(input, filter, group, conv_param):
6363

6464
class TestConv2dOp(OpTest):
6565
def setUp(self):
66+
self.op_type = "conv2d"
6667
self.use_cudnn = False
6768
self.use_mkldnn = False
6869
self.dtype = np.float32
69-
self.init_op_type()
70+
self.init_kernel_type()
7071
self.init_group()
7172
self.init_dilation()
7273
self.init_test_case()
@@ -165,8 +166,8 @@ def init_dilation(self):
165166
def init_group(self):
166167
self.groups = 1
167168

168-
def init_op_type(self):
169-
self.op_type = "conv2d"
169+
def init_kernel_type(self):
170+
pass
170171

171172

172173
class TestWithPad(TestConv2dOp):
@@ -238,15 +239,13 @@ def init_group(self):
238239

239240
#----------------Conv2dCUDNN----------------
240241
class TestCUDNN(TestConv2dOp):
241-
def init_op_type(self):
242+
def init_kernel_type(self):
242243
self.use_cudnn = True
243-
self.op_type = "conv2d"
244244

245245

246246
class TestFP16CUDNN(TestConv2dOp):
247-
def init_op_type(self):
247+
def init_kernel_type(self):
248248
self.use_cudnn = True
249-
self.op_type = "conv2d"
250249
self.dtype = np.float16
251250

252251
def test_check_output(self):
@@ -257,15 +256,13 @@ def test_check_output(self):
257256

258257

259258
class TestCUDNNWithPad(TestWithPad):
260-
def init_op_type(self):
259+
def init_kernel_type(self):
261260
self.use_cudnn = True
262-
self.op_type = "conv2d"
263261

264262

265263
class TestFP16CUDNNWithPad(TestWithPad):
266-
def init_op_type(self):
264+
def init_kernel_type(self):
267265
self.use_cudnn = True
268-
self.op_type = "conv2d"
269266
self.dtype = np.float16
270267

271268
def test_check_output(self):
@@ -276,15 +273,13 @@ def test_check_output(self):
276273

277274

278275
class TestCUDNNWithStride(TestWithStride):
279-
def init_op_type(self):
276+
def init_kernel_type(self):
280277
self.use_cudnn = True
281-
self.op_type = "conv2d"
282278

283279

284280
class TestFP16CUDNNWithStride(TestWithStride):
285-
def init_op_type(self):
281+
def init_kernel_type(self):
286282
self.use_cudnn = True
287-
self.op_type = "conv2d"
288283
self.dtype = np.float16
289284

290285
def test_check_output(self):
@@ -295,15 +290,13 @@ def test_check_output(self):
295290

296291

297292
class TestCUDNNWithGroup(TestWithGroup):
298-
def init_op_type(self):
293+
def init_kernel_type(self):
299294
self.use_cudnn = True
300-
self.op_type = "conv2d"
301295

302296

303297
class TestFP16CUDNNWithGroup(TestWithGroup):
304-
def init_op_type(self):
298+
def init_kernel_type(self):
305299
self.use_cudnn = True
306-
self.op_type = "conv2d"
307300
self.dtype = np.float16
308301

309302
def test_check_output(self):
@@ -314,15 +307,13 @@ def test_check_output(self):
314307

315308

316309
class TestCUDNNWith1x1(TestWith1x1):
317-
def init_op_type(self):
310+
def init_kernel_type(self):
318311
self.use_cudnn = True
319-
self.op_type = "conv2d"
320312

321313

322314
class TestFP16CUDNNWith1x1(TestWith1x1):
323-
def init_op_type(self):
315+
def init_kernel_type(self):
324316
self.use_cudnn = True
325-
self.op_type = "conv2d"
326317
self.dtype = np.float16
327318

328319
def test_check_output(self):
@@ -333,15 +324,13 @@ def test_check_output(self):
333324

334325

335326
class TestCUDNNWithInput1x1Filter1x1(TestWithInput1x1Filter1x1):
336-
def init_op_type(self):
327+
def init_kernel_type(self):
337328
self.use_cudnn = True
338-
self.op_type = "conv2d"
339329

340330

341331
class TestFP16CUDNNWithInput1x1Filter1x1(TestWithInput1x1Filter1x1):
342-
def init_op_type(self):
332+
def init_kernel_type(self):
343333
self.use_cudnn = True
344-
self.op_type = "conv2d"
345334
self.dtype = np.float16
346335

347336
def test_check_output(self):
@@ -384,21 +373,18 @@ def init_test_case(self):
384373

385374
#----------------Conv2dMKLDNN----------------
386375
class TestMKLDNN(TestConv2dOp):
387-
def init_op_type(self):
376+
def init_kernel_type(self):
388377
self.use_mkldnn = True
389-
self.op_type = "conv2d"
390378

391379

392380
class TestMKLDNNWithPad(TestWithPad):
393-
def init_op_type(self):
381+
def init_kernel_type(self):
394382
self.use_mkldnn = True
395-
self.op_type = "conv2d"
396383

397384

398385
class TestMKLDNNWithStride(TestWithStride):
399-
def init_op_type(self):
386+
def init_kernel_type(self):
400387
self.use_mkldnn = True
401-
self.op_type = "conv2d"
402388

403389

404390
if __name__ == '__main__':

python/paddle/fluid/tests/unittests/test_pool2d_op.py

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ def avg_pool2D_forward_naive(x,
7878

7979
class TestPool2d_Op(OpTest):
8080
def setUp(self):
81+
self.op_type = "pool2d"
8182
self.use_cudnn = False
8283
self.use_mkldnn = False
8384
self.dtype = np.float32
8485
self.init_test_case()
8586
self.init_global_pool()
86-
self.init_op_type()
87+
self.init_kernel_type()
8788
self.init_pool_type()
8889
self.init_ceil_mode()
8990
if self.global_pool:
@@ -131,8 +132,8 @@ def init_test_case(self):
131132
self.strides = [1, 1]
132133
self.paddings = [0, 0]
133134

134-
def init_op_type(self):
135-
self.op_type = "pool2d"
135+
def init_kernel_type(self):
136+
pass
136137

137138
def init_pool_type(self):
138139
self.pool_type = "avg"
@@ -152,9 +153,6 @@ def init_test_case(self):
152153
self.strides = [1, 1]
153154
self.paddings = [0, 0]
154155

155-
def init_op_type(self):
156-
self.op_type = "pool2d"
157-
158156
def init_pool_type(self):
159157
self.pool_type = "avg"
160158
self.pool2D_forward_naive = avg_pool2D_forward_naive
@@ -170,9 +168,6 @@ def init_test_case(self):
170168
self.strides = [1, 1]
171169
self.paddings = [1, 1]
172170

173-
def init_op_type(self):
174-
self.op_type = "pool2d"
175-
176171
def init_pool_type(self):
177172
self.pool_type = "avg"
178173
self.pool2D_forward_naive = avg_pool2D_forward_naive
@@ -182,43 +177,32 @@ def init_global_pool(self):
182177

183178

184179
class TestCase3(TestPool2d_Op):
185-
def init_op_type(self):
186-
self.op_type = "pool2d"
187-
188180
def init_pool_type(self):
189181
self.pool_type = "max"
190182
self.pool2D_forward_naive = max_pool2D_forward_naive
191183

192184

193185
class TestCase4(TestCase1):
194-
def init_op_type(self):
195-
self.op_type = "pool2d"
196-
197186
def init_pool_type(self):
198187
self.pool_type = "max"
199188
self.pool2D_forward_naive = max_pool2D_forward_naive
200189

201190

202191
class TestCase5(TestCase2):
203-
def init_op_type(self):
204-
self.op_type = "pool2d"
205-
206192
def init_pool_type(self):
207193
self.pool_type = "max"
208194
self.pool2D_forward_naive = max_pool2D_forward_naive
209195

210196

211197
#--------------------test pool2d--------------------
212198
class TestCUDNNCase1(TestPool2d_Op):
213-
def init_op_type(self):
199+
def init_kernel_type(self):
214200
self.use_cudnn = True
215-
self.op_type = "pool2d"
216201

217202

218203
class TestFP16CUDNNCase1(TestPool2d_Op):
219-
def init_op_type(self):
204+
def init_kernel_type(self):
220205
self.use_cudnn = True
221-
self.op_type = "pool2d"
222206
self.dtype = np.float16
223207

224208
def test_check_output(self):
@@ -229,15 +213,13 @@ def test_check_output(self):
229213

230214

231215
class TestCUDNNCase2(TestCase1):
232-
def init_op_type(self):
216+
def init_kernel_type(self):
233217
self.use_cudnn = True
234-
self.op_type = "pool2d"
235218

236219

237220
class TestFP16CUDNNCase2(TestCase1):
238-
def init_op_type(self):
221+
def init_kernel_type(self):
239222
self.use_cudnn = True
240-
self.op_type = "pool2d"
241223
self.dtype = np.float16
242224

243225
def test_check_output(self):
@@ -248,15 +230,13 @@ def test_check_output(self):
248230

249231

250232
class TestCUDNNCase3(TestCase2):
251-
def init_op_type(self):
233+
def init_kernel_type(self):
252234
self.use_cudnn = True
253-
self.op_type = "pool2d"
254235

255236

256237
class TestFP16CUDNNCase3(TestCase2):
257-
def init_op_type(self):
238+
def init_kernel_type(self):
258239
self.use_cudnn = True
259-
self.op_type = "pool2d"
260240
self.dtype = np.float16
261241

262242
def test_check_output(self):
@@ -267,15 +247,13 @@ def test_check_output(self):
267247

268248

269249
class TestCUDNNCase4(TestCase3):
270-
def init_op_type(self):
250+
def init_kernel_type(self):
271251
self.use_cudnn = True
272-
self.op_type = "pool2d"
273252

274253

275254
class TestFP16CUDNNCase4(TestCase3):
276-
def init_op_type(self):
255+
def init_kernel_type(self):
277256
self.use_cudnn = True
278-
self.op_type = "pool2d"
279257
self.dtype = np.float16
280258

281259
def test_check_output(self):
@@ -286,15 +264,13 @@ def test_check_output(self):
286264

287265

288266
class TestCUDNNCase5(TestCase4):
289-
def init_op_type(self):
267+
def init_kernel_type(self):
290268
self.use_cudnn = True
291-
self.op_type = "pool2d"
292269

293270

294271
class TestFP16CUDNNCase5(TestCase4):
295-
def init_op_type(self):
272+
def init_kernel_type(self):
296273
self.use_cudnn = True
297-
self.op_type = "pool2d"
298274
self.dtype = np.float16
299275

300276
def test_check_output(self):
@@ -305,15 +281,13 @@ def test_check_output(self):
305281

306282

307283
class TestCUDNNCase6(TestCase5):
308-
def init_op_type(self):
284+
def init_kernel_type(self):
309285
self.use_cudnn = True
310-
self.op_type = "pool2d"
311286

312287

313288
class TestFP16CUDNNCase6(TestCase5):
314-
def init_op_type(self):
289+
def init_kernel_type(self):
315290
self.use_cudnn = True
316-
self.op_type = "pool2d"
317291
self.dtype = np.float16
318292

319293
def test_check_output(self):
@@ -345,39 +319,33 @@ def init_ceil_mode(self):
345319

346320
#--------------------test pool2d MKLDNN--------------------
347321
class TestMKLDNNCase1(TestPool2d_Op):
348-
def init_op_type(self):
322+
def init_kernel_type(self):
349323
self.use_mkldnn = True
350-
self.op_type = "pool2d"
351324

352325

353326
class TestMKLDNNCase2(TestCase1):
354-
def init_op_type(self):
327+
def init_kernel_type(self):
355328
self.use_mkldnn = True
356-
self.op_type = "pool2d"
357329

358330

359331
class TestMKLDNNCase3(TestCase2):
360-
def init_op_type(self):
332+
def init_kernel_type(self):
361333
self.use_mkldnn = True
362-
self.op_type = "pool2d"
363334

364335

365336
class TestMKLDNNCase4(TestCase3):
366-
def init_op_type(self):
337+
def init_kernel_type(self):
367338
self.use_mkldnn = True
368-
self.op_type = "pool2d"
369339

370340

371341
class TestMKLDNNCase5(TestCase4):
372-
def init_op_type(self):
342+
def init_kernel_type(self):
373343
self.use_mkldnn = True
374-
self.op_type = "pool2d"
375344

376345

377346
class TestMKLDNNCase6(TestCase5):
378-
def init_op_type(self):
347+
def init_kernel_type(self):
379348
self.use_mkldnn = True
380-
self.op_type = "pool2d"
381349

382350

383351
if __name__ == '__main__':

0 commit comments

Comments
 (0)