From 27edf0b28d157c0a0446ada53dafcf5411e5e040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=91=A8=E5=91=A8?= <39978853+zhoutianzi666@users.noreply.github.com> Date: Tue, 20 Jun 2023 13:47:10 +0800 Subject: [PATCH] commit (#54594) --- paddle/fluid/framework/ir/identity_op_clean_pass.cc | 2 +- paddle/fluid/inference/tensorrt/convert/scale_op.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/framework/ir/identity_op_clean_pass.cc b/paddle/fluid/framework/ir/identity_op_clean_pass.cc index 720198576d8..c9ca6270c13 100644 --- a/paddle/fluid/framework/ir/identity_op_clean_pass.cc +++ b/paddle/fluid/framework/ir/identity_op_clean_pass.cc @@ -58,7 +58,7 @@ void IdentityOpCleanPass::ApplyImpl(ir::Graph* graph) const { if (x->Op()->Type() == "scale") { auto scale = x->Op()->GetAttrIfExists("scale"); auto bias = x->Op()->GetAttrIfExists("bias"); - if (std::abs(bias) <= 1e-6 && std::abs(scale - 1) <= 1e-6) { + if (bias == 0 && scale == 1) { return true; } } diff --git a/paddle/fluid/inference/tensorrt/convert/scale_op.cc b/paddle/fluid/inference/tensorrt/convert/scale_op.cc index 054964419d2..d75eb4128b2 100644 --- a/paddle/fluid/inference/tensorrt/convert/scale_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/scale_op.cc @@ -46,7 +46,7 @@ class ScaleOpConverter : public OpConverter { is_int ? Add1DConstantLayer( static_cast(bias > 0 ? bias + 0.5 : bias - 0.5)) : Add1DConstantLayer(bias); - bool is_bias_0 = (bias < 1e-06 && bias > -1e-06); + bool is_bias_0 = bias == 0; std::vector bias_shapes(input->getDimensions().nbDims, 1); auto* bias_shapes_tensor = Add1DConstantLayer(bias_shapes); @@ -69,7 +69,7 @@ class ScaleOpConverter : public OpConverter { scale_tensor = is_int ? Add1DConstantLayer(static_cast( scale > 0 ? scale + 0.5 : scale - 0.5)) : Add1DConstantLayer(scale); - is_scale_1 = ((scale - 1.0) < 1e-06 && (scale - 1.0) > -1e-06); + is_scale_1 = scale == 1; } std::vector scale_shapes(input->getDimensions().nbDims, 1); -- GitLab