From f551d9fe13fa061d40a326e07941af9f6323b4dd Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Fri, 10 Jun 2022 08:50:12 -0500 Subject: [PATCH] [Phi] Fix depthwise conv yaml error (#43379) * fix depthwise conv yaml error * fix depthwise conv double grad error --- .../kernels/gpudnn/conv_grad_grad_kernel.cu | 18 +++++++++--------- paddle/phi/ops/compat/depthwise_conv2d_sig.cc | 4 ++-- python/paddle/nn/functional/conv.py | 2 +- python/paddle/utils/code_gen/api.yaml | 15 ++++++++------- python/paddle/utils/code_gen/backward.yaml | 19 ++++++++++++------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/paddle/phi/kernels/gpudnn/conv_grad_grad_kernel.cu b/paddle/phi/kernels/gpudnn/conv_grad_grad_kernel.cu index e5552f28f88..13d85ed1d36 100644 --- a/paddle/phi/kernels/gpudnn/conv_grad_grad_kernel.cu +++ b/paddle/phi/kernels/gpudnn/conv_grad_grad_kernel.cu @@ -663,13 +663,13 @@ void ConvCudnnGradGradKernel( } template -void DepthwiseConvCudnnGradGradKernel( +void DepthwiseConvDoubleGradGPUDNNKernel( const Context& ctx, - const paddle::optional& input_grad_grad, - const paddle::optional& filter_grad_grad, - const DenseTensor& out_grad, const DenseTensor& input, const DenseTensor& filter, + const DenseTensor& out_grad, + const paddle::optional& input_grad_grad, + const paddle::optional& filter_grad_grad, const std::vector& strides, const std::vector& paddings_t, const std::string& padding_algorithm, @@ -680,9 +680,9 @@ void DepthwiseConvCudnnGradGradKernel( int workspace_size_MB, bool exhaustive_search_t, bool fuse_relu, - DenseTensor* out_grad_grad, DenseTensor* input_grad, - DenseTensor* filter_grad) { + DenseTensor* filter_grad, + DenseTensor* out_grad_grad) { ConvCudnnGradGradKernel(ctx, input, filter, @@ -763,7 +763,7 @@ PD_REGISTER_KERNEL(conv3d_grad_grad, PD_REGISTER_KERNEL(depthwise_conv2d_grad_grad, GPU, ALL_LAYOUT, - phi::DepthwiseConvCudnnGradGradKernel, + phi::DepthwiseConvDoubleGradGPUDNNKernel, float, phi::dtype::float16) {} #else @@ -789,7 +789,7 @@ PD_REGISTER_KERNEL(conv3d_grad_grad, PD_REGISTER_KERNEL(depthwise_conv2d_grad_grad, GPU, ALL_LAYOUT, - phi::DepthwiseConvCudnnGradGradKernel, + phi::DepthwiseConvDoubleGradGPUDNNKernel, float, double, phi::dtype::float16, @@ -816,7 +816,7 @@ PD_REGISTER_KERNEL(conv3d_grad_grad, PD_REGISTER_KERNEL(depthwise_conv2d_grad_grad, GPU, ALL_LAYOUT, - phi::DepthwiseConvCudnnGradGradKernel, + phi::DepthwiseConvDoubleGradGPUDNNKernel, float, double, phi::dtype::float16) {} diff --git a/paddle/phi/ops/compat/depthwise_conv2d_sig.cc b/paddle/phi/ops/compat/depthwise_conv2d_sig.cc index 1014d45e70a..f7558499fd8 100644 --- a/paddle/phi/ops/compat/depthwise_conv2d_sig.cc +++ b/paddle/phi/ops/compat/depthwise_conv2d_sig.cc @@ -53,7 +53,7 @@ KernelSignature DepthwiseConv2dGradOpArgumentMapping( KernelSignature DepthwiseConv2dDoubleGradOpArgumentMapping( const ArgumentMappingContext& ctx) { return KernelSignature("depthwise_conv2d_grad_grad", - {"DDInput", "DDFilter", "DOutput", "Input", "Filter"}, + {"Input", "Filter", "DOutput", "DDInput", "DDFilter"}, {"strides", "paddings", "padding_algorithm", @@ -64,7 +64,7 @@ KernelSignature DepthwiseConv2dDoubleGradOpArgumentMapping( "workspace_size_MB", "exhaustive_search", "fuse_relu_before_depthwise_conv"}, - {"DDOutput", "DInput", "DFilter"}); + {"DInput", "DFilter", "DDOutput"}); } } // namespace phi diff --git a/python/paddle/nn/functional/conv.py b/python/paddle/nn/functional/conv.py index f1d66a9e3a1..d8dc68376d1 100644 --- a/python/paddle/nn/functional/conv.py +++ b/python/paddle/nn/functional/conv.py @@ -143,7 +143,7 @@ def _conv_nd(x, if in_dygraph_mode() and op_type == "depthwise_conv2d": pre_bias = _C_ops.final_state_depthwise_conv2d( x, weight, stride, padding, padding_algorithm, groups, dilation, - data_format, False, -1, False, False) + data_format, False, -1, False, False, use_cudnn) if bias is not None: channel_dim = channel_dim + len( x.shape) if channel_dim < 0 else channel_dim diff --git a/python/paddle/utils/code_gen/api.yaml b/python/paddle/utils/code_gen/api.yaml index dfb5f6acedc..2b8cff3543e 100644 --- a/python/paddle/utils/code_gen/api.yaml +++ b/python/paddle/utils/code_gen/api.yaml @@ -499,15 +499,16 @@ backward : deformable_conv_grad - api : depthwise_conv2d - args : (Tensor x, Tensor filter, int[] strides, int[] paddings, str padding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu) + args : (Tensor x, Tensor filter, int[] strides, int[] paddings, str padding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu, bool use_gpudnn) output : Tensor(out) - invoke : conv2d_impl(x, filter, strides, paddings, padding_algorithm, groups, dilations, data_format, use_addto, workspace_size_MB, exhaustive_search) + infer_meta : + func : ConvInferMeta + param : [x, filter, strides, paddings, padding_algorithm, groups, dilations, data_format, use_addto, workspace_size_MB, exhaustive_search] + kernel : + func : depthwise_conv2d + param : [x, filter, strides, paddings, padding_algorithm, groups, dilations, data_format, use_addto, workspace_size_MB, exhaustive_search, fuse_relu] + use_gpudnn : use_gpudnn backward : depthwise_conv2d_grad - # infer_meta : - # func : ConvTransposeInferMeta - # prams: [x, filter, strides, paddings, padding_algorithm, groups, dilations, data_format, use_addto, workspace_size_MB, exhaustive_search] - # kernel : - # func : depthwise_conv2d - api : depthwise_conv2d_transpose args : (Tensor x, Tensor filter, int[] strides, int[] paddings, int[] output_padding, int[] output_size, str padding_algorithm, int groups, int[] dilations, str data_format) diff --git a/python/paddle/utils/code_gen/backward.yaml b/python/paddle/utils/code_gen/backward.yaml index 0d14560d605..8e20b05110e 100644 --- a/python/paddle/utils/code_gen/backward.yaml +++ b/python/paddle/utils/code_gen/backward.yaml @@ -495,22 +495,27 @@ optional : mask - backward_api : depthwise_conv2d_grad - forward : depthwise_conv2d (Tensor input, Tensor filter, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu) -> Tensor(out) - args : (Tensor input, Tensor filter, Tensor out_grad, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu) + forward : depthwise_conv2d (Tensor input, Tensor filter, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu, bool use_gpudnn) -> Tensor(out) + args : (Tensor input, Tensor filter, Tensor out_grad, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu, bool use_gpudnn) output : Tensor(input_grad), Tensor(filter_grad) - invoke : conv2d_grad_impl(input, filter, out_grad, strides, paddings, paddding_algorithm, groups, dilations, data_format, use_addto, workspace_size_MB, exhaustive_search, input_grad, filter_grad) + infer_meta : + func : GeneralBinaryGradInferMeta + param : [input, filter] + kernel : + func : depthwise_conv2d_grad + param : [input, filter, out_grad, strides, paddings, paddding_algorithm, groups, dilations, data_format, use_addto, workspace_size_MB, exhaustive_search, fuse_relu] + use_gpudnn : use_gpudnn backward : depthwise_conv2d_grad_grad - backward_api : depthwise_conv2d_grad_grad - forward : depthwise_conv2d_grad (Tensor input, Tensor filter, Tensor grad_out, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu) -> Tensor(grad_input), Tensor(grad_filter) - args : (Tensor input, Tensor filter, Tensor grad_out, Tensor grad_input_grad, Tensor grad_filter_grad, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search) + forward : depthwise_conv2d_grad (Tensor input, Tensor filter, Tensor grad_out, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu, bool use_gpudnn) -> Tensor(grad_input), Tensor(grad_filter) + args : (Tensor input, Tensor filter, Tensor grad_out, Tensor grad_input_grad, Tensor grad_filter_grad, int[] strides, int[] paddings, str paddding_algorithm, int groups, int[] dilations, str data_format, bool use_addto, int workspace_size_MB, bool exhaustive_search, bool fuse_relu) output : Tensor(input_grad), Tensor(filter_grad), Tensor(grad_out_grad) infer_meta : func : GeneralTernaryGradInferMeta param: [input, filter, grad_out] kernel : - func : conv2d_grad_grad - use_gpudnn : true + func : depthwise_conv2d_grad_grad optional : grad_input_grad, grad_filter_grad - backward_api : depthwise_conv2d_transpose_grad -- GitLab