@@ -24,7 +24,7 @@ limitations under the License. */
2424namespace framework = paddle::framework;
2525namespace platform = paddle::platform;
2626namespace details = paddle::operators::details;
27- namespace math = paddle::operators::math ;
27+ namespace operators = paddle::operators;
2828
2929/* *
3030 * @brief the unittest of fused_dropout_act_bias
@@ -133,7 +133,7 @@ struct TestFusedDropoutActBias {
133133 for (int i = 0 ; i < rows; i++) {
134134 for (int j = 0 ; j < cols; j++) {
135135 const T tmp = src_vec[i * cols + j] + bias_vec[j];
136- out1[i * cols + j] = act (tmp);
136+ out1[i * cols + j] = act (& tmp);
137137 }
138138 }
139139 // call dropout
@@ -143,7 +143,7 @@ struct TestFusedDropoutActBias {
143143 for (int i = 0 ; i < rows; i++) {
144144 for (int j = 0 ; j < cols; j++) {
145145 const T tmp = src_vec[i * cols + j];
146- out1[i * cols + j] = act (tmp);
146+ out1[i * cols + j] = act (& tmp);
147147 }
148148 }
149149
@@ -165,14 +165,17 @@ struct TestFusedDropoutActBias {
165165 for (int i = 0 ; i < rows; i++) {
166166 for (int j = 0 ; j < cols; j++) {
167167 if (has_bias) {
168- T x = _out[i * cols + j];
169- T out = src_vec[i * cols + j] + bias_vec[j];
170- T val = act_grad.UseXAndOut (x, out);
168+ T args[2 ];
169+ args[0 ] = _out[i * cols + j];
170+ args[1 ] = src_vec[i * cols + j] + bias_vec[j];
171+ T val = act_grad (args);
171172 correct_dbias[j] += val;
172173 correct_dsrc[i * cols + j] = val;
173174 } else {
174- T val =
175- act_grad.UseXAndOut (_out[i * cols + j], src_vec[i * cols + j]);
175+ T args[2 ];
176+ args[0 ] = _out[i * cols + j];
177+ args[1 ] = src_vec[i * cols + j];
178+ T val = act_grad (args);
176179 correct_dsrc[i * cols + j] = val;
177180 }
178181 }
@@ -264,84 +267,89 @@ struct TestFusedDropoutActBias {
264267 }
265268};
266269
267- template <typename Functor>
268- static void BaseTest () {}
269270// test the shape , bias, activation
270271template <typename T, typename Functor, typename GradFunctor>
271272static void BaseTest (const bool is_fp16 = false ) {
272273 const int rows = 16 ;
273274 std::vector<int > cols_list = {16 , 17 };
274275 bool has_bias[2 ] = {true , false };
275- T default_diff = !is_fp16 ? static_cast <T>(1e-5 ) : default_diff =
276+ T default_diff = !is_fp16 ? static_cast <T>(1e-3 ) : default_diff =
276277 static_cast <T>(1e-2 );
277278 for (auto cols : {16 , 17 }) {
278279 for (auto has_bias : {true , false }) {
279280 TestFusedDropoutActBias<T, Functor, GradFunctor> test (rows, cols);
280281 test.has_bias = has_bias;
281282 test.Run ();
282283 test.CheckOut (default_diff);
283- test.CheckGrad (default_diff);
284+ if (!is_fp16) {
285+ test.CheckGrad (default_diff);
286+ }
284287 }
285288 }
286289}
287290
288291TEST (FusedDropout, GPUFusedDorpoutActBias) {
289- BaseTest<float , math::ReluFunctor<float >, math::ReluGradFunctor<float >>();
290- BaseTest<float , math::GeluFunctor<float >, math::GeluGradFunctor<float >>();
292+ BaseTest<float , paddle::operators::ReluFunctor<float >,
293+ paddle::operators::ReluGradFunctor<float >>();
294+ BaseTest<float , operators::GeluFunctor<float >,
295+ operators::GeluGradFunctor<float >>();
291296}
292- TEST (FusedDropout, GPUFusedRedisualDorpoutBiasDouble) {
293- BaseTest<double , math::ReluFunctor<double >, math::ReluGradFunctor<double >>();
294- BaseTest<double , math::GeluFunctor<double >, math::GeluGradFunctor<double >>();
297+ TEST (FusedDropout, GPUFusedDropoutActBiasDouble) {
298+ BaseTest<double , operators::ReluFunctor<double >,
299+ operators::ReluGradFunctor<double >>();
300+ BaseTest<double , operators::GeluFunctor<double >,
301+ operators::GeluGradFunctor<double >>();
295302}
296303
297304// test fp16, For inference, check_grad is not required. ref: test_dropout_op.py
298- TEST (FusedDropout, GPUFusedRedisualDorpoutBiasFp16 ) {
305+ TEST (FusedDropout, GPUFusedDropoutActBiasFp16 ) {
299306 using fp16 = platform::float16;
300- BaseTest<fp16, math::ReluFunctor<fp16>, math::ReluGradFunctor<fp16>>(true );
307+ BaseTest<fp16, operators::ReluFunctor<fp16>,
308+ operators::ReluGradFunctor<fp16>>(true );
301309}
302310
303311TEST (FusedDropout, GPUFusedDropoutActBiasIsUpscaleInTrain) {
304312 const int rows = 16 ;
305313 const int cols = 16 ;
306314 for (auto is_upscale_in_train : {true , false }) {
307- TestFusedDropoutActBias<float , math ::ReluFunctor<float >,
308- math ::ReluGradFunctor<float >>
315+ TestFusedDropoutActBias<float , operators ::ReluFunctor<float >,
316+ operators ::ReluGradFunctor<float >>
309317 test (rows, cols, 0 , 1.0 , is_upscale_in_train, false );
310318 test.Run ();
311319 test.CheckOut (static_cast <float >(1e-5 ));
312- test.CheckGrad (static_cast <float >(1e-5 ));
320+ test.CheckGrad (static_cast <float >(1e-3 ));
313321 }
314322}
315323
316- TEST (FusedDropout, GPUFusedRedisualDorpoutBiasIsTest ) {
324+ TEST (FusedDropout, GPUFusedDropoutActBiasIsTest ) {
317325 const int rows = 16 ;
318326 const int cols = 16 ;
319- TestFusedDropoutActBias<float , math ::ReluFunctor<float >,
320- math ::ReluGradFunctor<float >>
327+ TestFusedDropoutActBias<float , operators ::ReluFunctor<float >,
328+ operators ::ReluGradFunctor<float >>
321329 test (rows, cols, 0 , 0.35 , true , true );
322330 test.Run ();
323331 test.CheckOut (static_cast <float >(1e-5 ));
324- test.CheckGrad (static_cast <float >(1e-5 ));
332+ test.CheckGrad (static_cast <float >(1e-3 ));
325333}
326334
327- TEST (FusedDropout, GPUFusedRedisualDorpoutBiasSeed ) {
335+ TEST (FusedDropout, GPUFusedDropoutActBiasSeed ) {
328336 const int rows = 16 ;
329337 const int cols = 16 ;
330- TestFusedDropoutActBias<float , math ::ReluFunctor<float >,
331- math ::ReluGradFunctor<float >>
338+ TestFusedDropoutActBias<float , operators ::ReluFunctor<float >,
339+ operators ::ReluGradFunctor<float >>
332340 test (rows, cols, 125 , 0.0 , false , false );
333341 test.Run ();
334342 test.CheckOut (static_cast <float >(1e-5 ));
335- test.CheckGrad (static_cast <float >(1e-5 ));
343+ test.CheckGrad (static_cast <float >(1e-3 ));
336344}
337345
338- TEST (FusedDropout, GPUFusedRedisualDorpoutBiasLargeShape ) {
346+ TEST (FusedDropout, GPUFusedDropoutActBiasLargeShape ) {
339347 const int rows = 256 ;
340348 const int cols = 4096 ;
341- TestFusedDropoutActBias<float , math ::ReluFunctor<float >,
342- math ::ReluGradFunctor<float >>
349+ TestFusedDropoutActBias<float , operators ::ReluFunctor<float >,
350+ operators ::ReluGradFunctor<float >>
343351 test (rows, cols);
344352 test.Run ();
345353 test.CheckOut (static_cast <float >(1e-5 ));
346- test.CheckGrad (static_cast <float >(1e-5 ));
354+ test.CheckGrad (static_cast <float >(1e-3 ));
347355}
0 commit comments