diff --git a/paddle/fluid/framework/ir/identity_op_clean_pass.cc b/paddle/fluid/framework/ir/identity_op_clean_pass.cc index 720198576d8a88a8dd1adc21134532b779e24770..c9ca6270c13baab56ce3e4e93a79c5fb1166eb2d 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 054964419d2d94a702f2f50c87bd595770701d61..d75eb4128b2e566236b5db4c06f630b839ff73b0 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);