@@ -82,18 +82,9 @@ def setUp(self):
82
82
output = conv2d_forward_naive (input , filter , self .groups ,
83
83
conv2d_param ).astype (self .dtype )
84
84
85
- # numpy float16 is binded to paddle::platform::float16
86
- # in tensor_py.h via the help of numpy uint16 because
87
- # the internal memory representation of float16 is
88
- # uint16_t in paddle or np.uint16 in numpy, which are
89
- # themselves binded together.
90
85
self .inputs = {
91
- #'Input': (input.view(np.uint16)
92
- # if self.dtype == np.float16 else input),
93
- #'Filter': (filter.view(np.uint16)
94
- # if self.dtype == np.float16 else filter)
95
- 'Input' : OpTest .create_view (input ),
96
- 'Filter' : OpTest .create_view (filter )
86
+ 'Input' : OpTest .np_dtype_to_fluid_dtype (input ),
87
+ 'Filter' : OpTest .np_dtype_to_fluid_dtype (filter )
97
88
}
98
89
self .attrs = {
99
90
'strides' : self .stride ,
@@ -113,6 +104,8 @@ def test_check_output(self):
113
104
self .check_output ()
114
105
115
106
def test_check_grad (self ):
107
+ if self .dtype == np .float16 :
108
+ return
116
109
if self .use_cudnn :
117
110
place = core .CUDAPlace (0 )
118
111
self .check_grad_with_place (
@@ -125,6 +118,8 @@ def test_check_grad(self):
125
118
set (['Input' , 'Filter' ]), 'Output' , max_relative_error = 0.02 )
126
119
127
120
def test_check_grad_no_filter (self ):
121
+ if self .dtype == np .float16 :
122
+ return
128
123
if self .use_cudnn :
129
124
place = core .CUDAPlace (0 )
130
125
self .check_grad_with_place (
@@ -140,6 +135,8 @@ def test_check_grad_no_filter(self):
140
135
no_grad_set = set (['Filter' ]))
141
136
142
137
def test_check_grad_no_input (self ):
138
+ if self .dtype == np .float16 :
139
+ return
143
140
if self .use_cudnn :
144
141
place = core .CUDAPlace (0 )
145
142
self .check_grad_with_place (
@@ -259,46 +256,92 @@ def test_check_output(self):
259
256
if core .is_float16_supported (place ):
260
257
self .check_output_with_place (place , atol = 2e-2 )
261
258
262
- def test_check_grad (self ):
263
- pass
264
-
265
- def test_check_grad_no_filter (self ):
266
- pass
267
-
268
- def test_check_grad_no_input (self ):
269
- pass
270
-
271
259
272
260
class TestCUDNNWithPad (TestWithPad ):
273
261
def init_op_type (self ):
274
262
self .use_cudnn = True
275
263
self .op_type = "conv2d"
276
264
277
265
266
+ class TestFP16CUDNNWithPad (TestCUDNNWithPad ):
267
+ def init_data_type (self ):
268
+ self .dtype = np .float16
269
+
270
+ def test_check_output (self ):
271
+ if core .is_compiled_with_cuda ():
272
+ place = core .CUDAPlace (0 )
273
+ if core .is_float16_supported (place ):
274
+ self .check_output_with_place (place , atol = 2e-2 )
275
+
276
+
278
277
class TestCUDNNWithStride (TestWithStride ):
279
278
def init_op_type (self ):
280
279
self .use_cudnn = True
281
280
self .op_type = "conv2d"
282
281
283
282
283
+ class TestFP16CUDNNWithStride (TestCUDNNWithStride ):
284
+ def init_data_type (self ):
285
+ self .dtype = np .float16
286
+
287
+ def test_check_output (self ):
288
+ if core .is_compiled_with_cuda ():
289
+ place = core .CUDAPlace (0 )
290
+ if core .is_float16_supported (place ):
291
+ self .check_output_with_place (place , atol = 2e-2 )
292
+
293
+
284
294
class TestCUDNNWithGroup (TestWithGroup ):
285
295
def init_op_type (self ):
286
296
self .use_cudnn = True
287
297
self .op_type = "conv2d"
288
298
289
299
300
+ class TestFP16CUDNNWithGroup (TestCUDNNWithGroup ):
301
+ def init_data_type (self ):
302
+ self .dtype = np .float16
303
+
304
+ def test_check_output (self ):
305
+ if core .is_compiled_with_cuda ():
306
+ place = core .CUDAPlace (0 )
307
+ if core .is_float16_supported (place ):
308
+ self .check_output_with_place (place , atol = 2e-2 )
309
+
310
+
290
311
class TestCUDNNWith1x1 (TestWith1x1 ):
291
312
def init_op_type (self ):
292
313
self .use_cudnn = True
293
314
self .op_type = "conv2d"
294
315
295
316
317
+ class TestFP16CUDNNWith1x1 (TestCUDNNWith1x1 ):
318
+ def init_data_type (self ):
319
+ self .dtype = np .float16
320
+
321
+ def test_check_output (self ):
322
+ if core .is_compiled_with_cuda ():
323
+ place = core .CUDAPlace (0 )
324
+ if core .is_float16_supported (place ):
325
+ self .check_output_with_place (place , atol = 2e-2 )
326
+
327
+
296
328
class TestCUDNNWithInput1x1Filter1x1 (TestWithInput1x1Filter1x1 ):
297
329
def init_op_type (self ):
298
330
self .use_cudnn = True
299
331
self .op_type = "conv2d"
300
332
301
333
334
+ class TestFP16CUDNNWithInput1x1Filter1x1 (TestCUDNNWithInput1x1Filter1x1 ):
335
+ def init_data_type (self ):
336
+ self .dtype = np .float16
337
+
338
+ def test_check_output (self ):
339
+ if core .is_compiled_with_cuda ():
340
+ place = core .CUDAPlace (0 )
341
+ if core .is_float16_supported (place ):
342
+ self .check_output_with_place (place , atol = 2e-2 )
343
+
344
+
302
345
class TestDepthwiseConv (TestConv2dOp ):
303
346
def init_test_case (self ):
304
347
self .pad = [1 , 1 ]
0 commit comments