From d8edf487a0cacbc18a2546e79f6a3a9830a3b537 Mon Sep 17 00:00:00 2001 From: zhoutianzi666 <39978853+zhoutianzi666@users.noreply.github.com> Date: Thu, 22 Sep 2022 13:17:48 +0800 Subject: [PATCH] [Paddle-TRT]fix bug in fill_constant_batch_size_like op (#46334) * fix beta bug in fill_constant_batch_size_like --- .../tensorrt/convert/fill_constant_batch_size_like_op.cc | 6 +++++- .../tests/unittests/ir/inference/test_trt_convert_rnn.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/inference/tensorrt/convert/fill_constant_batch_size_like_op.cc b/paddle/fluid/inference/tensorrt/convert/fill_constant_batch_size_like_op.cc index 5f00777a66..b163cd5fec 100644 --- a/paddle/fluid/inference/tensorrt/convert/fill_constant_batch_size_like_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/fill_constant_batch_size_like_op.cc @@ -44,6 +44,10 @@ class FillConstantBatchSizeLikeOpConverter : public OpConverter { PADDLE_GET_CONST(std::string, op_desc.GetAttr("str_value")); std::vector shape = PADDLE_GET_CONST(std::vector, op_desc.GetAttr("shape")); + if (str_value == "") { + float value = PADDLE_GET_CONST(float, op_desc.GetAttr("value")); + str_value = std::to_string(value); + } float value = std::stof(str_value); auto* input_shape_tensor = Shape(input); @@ -65,7 +69,7 @@ class FillConstantBatchSizeLikeOpConverter : public OpConverter { auto layer = TRT_ENGINE_ADD_LAYER( engine_, Fill, nvinfer1::Dims{}, nvinfer1::FillOperation::kLINSPACE); std::vector value_vec(1, value); - std::vector beta_vec(3, 0.); + std::vector beta_vec(shape.size(), 0.); layer->setAlpha(value); layer->setBeta(0.f); layer->setInput(0, *out_shape_tensor); diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_rnn.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_rnn.py index 2a3c25bab1..a6000b1256 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_rnn.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_rnn.py @@ -87,7 +87,9 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest): "input_dim_idx": 0, "str_value": - "0.0", + "", + "value": + 0.0, "shape": [K * num_layers, -1, hidden_size], "output_dim_idx": 1, -- GitLab