From a6ef875885486eea5573e4da52ec2c1c02f1d1e7 Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Mon, 11 Dec 2017 14:05:15 +0800 Subject: [PATCH] refine conv --- paddle/operators/conv_op.h | 7 +++++-- paddle/operators/conv_transpose_op.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/paddle/operators/conv_op.h b/paddle/operators/conv_op.h index 09bff0a68db..66728d75a66 100644 --- a/paddle/operators/conv_op.h +++ b/paddle/operators/conv_op.h @@ -260,8 +260,11 @@ class GemmConvGradKernel : public framework::OpKernel { if (input_grad) { input_grad->mutable_data(context.GetPlace()); - set_zero(context.device_context(), input_grad, static_cast(0)); - + // if is_expand is false, the operation of set_zero is unnecessary, + // because math::matmul will reset input_grad. + if (is_expand) { + set_zero(context.device_context(), input_grad, static_cast(0)); + } math::Col2VolFunctor col2vol; math::Col2ImFunctor col2im; diff --git a/paddle/operators/conv_transpose_op.h b/paddle/operators/conv_transpose_op.h index 1cacb770e6a..a43dd5b8c0d 100644 --- a/paddle/operators/conv_transpose_op.h +++ b/paddle/operators/conv_transpose_op.h @@ -225,7 +225,7 @@ class GemmConvTransposeGradKernel : public framework::OpKernel { if (input_grad) { input_grad->mutable_data(context.GetPlace()); - set_zero(context.device_context(), input_grad, static_cast(0)); + // set_zero is unnecessary, math::matmul will reset input_grad. } if (filter_grad) { // filter size (m, c, k_h, k_w) filter_grad->mutable_data(context.GetPlace()); -- GitLab