From 85e697d74933d2251d25192a2bcf381adff7d433 Mon Sep 17 00:00:00 2001 From: Pei Yang Date: Tue, 27 Apr 2021 12:32:36 +0800 Subject: [PATCH] support depthwise_conv2d_transpose (#32593) --- .../inference/tensorrt/convert/conv2d_op.cc | 2 +- .../inference/tensorrt/convert/op_converter.h | 6 ++++++ paddle/fluid/inference/tensorrt/op_teller.cc | 7 +++++-- .../ir/inference/test_trt_conv_pass.py | 19 +++++++++++++++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc b/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc index ba47358b147..61199724bcf 100644 --- a/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc @@ -160,7 +160,7 @@ class Deconv2dOpConverter : public OpConverter { nvinfer1::DimsHW& ksize, TensorRTEngine::Weight& weight, TensorRTEngine::Weight& bias) -> nvinfer1::IDeconvolutionLayer* { auto* layer = - TRT_ENGINE_ADD_LAYER(engine_, Deconvolution, *inputs, n_input, + TRT_ENGINE_ADD_LAYER(engine_, Deconvolution, *inputs, n_output, ksize, weight.get(), bias.get()); return layer; }, diff --git a/paddle/fluid/inference/tensorrt/convert/op_converter.h b/paddle/fluid/inference/tensorrt/convert/op_converter.h index 8de16df0a2f..f72ae2c3ec2 100644 --- a/paddle/fluid/inference/tensorrt/convert/op_converter.h +++ b/paddle/fluid/inference/tensorrt/convert/op_converter.h @@ -109,6 +109,12 @@ class OpConverter { it, platform::errors::Unimplemented("no OpConverter for optype [%s]", op_desc.Type())); } + if (op_desc.Type() == "depthwise_conv2d_transpose") { + it = Registry::Global().Lookup("conv2d_transpose"); + PADDLE_ENFORCE_NOT_NULL( + it, platform::errors::Unimplemented("no OpConverter for optype [%s]", + op_desc.Type())); + } if (op_desc.Type() == "transpose2") { it = Registry::Global().Lookup("transpose"); PADDLE_ENFORCE_NOT_NULL( diff --git a/paddle/fluid/inference/tensorrt/op_teller.cc b/paddle/fluid/inference/tensorrt/op_teller.cc index c8dfc169535..48c7b7fdd0d 100644 --- a/paddle/fluid/inference/tensorrt/op_teller.cc +++ b/paddle/fluid/inference/tensorrt/op_teller.cc @@ -102,6 +102,7 @@ struct SimpleOpTypeSetTeller : public Teller { "dropout", "prelu", "conv2d_transpose", + "depthwise_conv2d_transpose", "leaky_relu", "fc", "shuffle_channel", @@ -172,7 +173,8 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8, } if (op_type == "conv2d" || op_type == "conv2d_transpose" || - op_type == "conv2d_fusion") { + op_type == "conv2d_fusion" || op_type == "depthwise_conv2d" || + op_type == "depthwise_conv2d_transpose") { std::vector paddings = BOOST_GET_CONST(std::vector, desc.GetAttr("paddings")); @@ -202,7 +204,8 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8, } } - if (op_type == "conv2d_transpose") { + if (op_type == "conv2d_transpose" || + op_type == "depthwise_conv2d_transpose") { if (!desc.HasAttr("dilations")) { return false; } else { diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py index 0821b390e5e..ec3955a9ae1 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py @@ -96,6 +96,7 @@ class TensorRTSubgraphPassConvTransposeTest(InferencePassTest): groups=self.conv_groups, padding=self.conv_padding, bias_attr=False, + use_cudnn=self.use_cudnn, act=None) self.feeds = { "data": np.random.random([1, 6, 64, 64]).astype("float32"), @@ -110,6 +111,7 @@ class TensorRTSubgraphPassConvTransposeTest(InferencePassTest): self.conv_filter_size = 6 self.conv_groups = 1 self.conv_padding = [1, 1] + self.use_cudnn = True def test_check_output(self): if core.is_compiled_with_cuda(): @@ -126,6 +128,7 @@ class TensorRTSubgraphPassConvTransposeValidPaddingTest( self.conv_filter_size = 6 self.conv_groups = 1 self.conv_padding = 'VALID' + self.use_cudnn = True class TensorRTSubgraphPassConvTransposeSamePaddingTest( @@ -135,15 +138,27 @@ class TensorRTSubgraphPassConvTransposeSamePaddingTest( self.conv_filter_size = 6 self.conv_groups = 1 self.conv_padding = 'SAME' + self.use_cudnn = True -class TensorRTSubgraphPassDepthwiseConvTransposeTest( +class TensorRTSubgraphPassConvTransposeMultiGroupTest( TensorRTSubgraphPassConvTransposeTest): def set_params(self): self.conv_num_filters = 6 self.conv_filter_size = 6 - self.conv_groups = 1 + self.conv_groups = 2 + self.conv_padding = [1, 1] + self.use_cudnn = True + + +class TensorRTSubgraphPassDepthwiseConvTransposeTest( + TensorRTSubgraphPassConvTransposeTest): + def set_params(self): + self.conv_num_filters = 6 + self.conv_filter_size = 4 + self.conv_groups = 6 self.conv_padding = [1, 1] + self.use_cudnn = False if __name__ == "__main__": -- GitLab