diff --git a/paddle/phi/kernels/funcs/activation_functor.h b/paddle/phi/kernels/funcs/activation_functor.h index 69e85edc76586a..50b2c1091d2a2a 100644 --- a/paddle/phi/kernels/funcs/activation_functor.h +++ b/paddle/phi/kernels/funcs/activation_functor.h @@ -1803,8 +1803,9 @@ struct ThresholdedReluFunctor : public BaseActivationFunctor { template void operator()(Device d, X x, Out out) const { auto th = static_cast(threshold); // NOLINT - auto va = static_cast(value); // NOLINT - out.device(d) = (x > th).template cast() * x + (x <= th).template cast() * va; + auto va = static_cast(value); // NOLINT + out.device(d) = + (x > th).template cast() * x + (x <= th).template cast() * va; } }; diff --git a/test/legacy_test/test_activation_op.py b/test/legacy_test/test_activation_op.py index 0513f1a2d5d8fa..e583e858c53def 100644 --- a/test/legacy_test/test_activation_op.py +++ b/test/legacy_test/test_activation_op.py @@ -4358,11 +4358,15 @@ def test_static_api(self): with paddle.static.program_guard(paddle.static.Program()): x = paddle.static.data('X', self.x_np.shape, self.x_np.dtype) out1 = F.thresholded_relu(x, self.threshold, self.value) - thresholded_relu = paddle.nn.ThresholdedReLU(self.threshold, self.value) + thresholded_relu = paddle.nn.ThresholdedReLU( + self.threshold, self.value + ) out2 = thresholded_relu(x) exe = paddle.static.Executor(self.place) res = exe.run(feed={'X': self.x_np}, fetch_list=[out1, out2]) - out_ref = ref_thresholded_relu(self.x_np, self.threshold, self.value) + out_ref = ref_thresholded_relu( + self.x_np, self.threshold, self.value + ) for r in res: np.testing.assert_allclose(out_ref, r, rtol=1e-05) @@ -4370,9 +4374,13 @@ def test_dygraph_api(self): with dynamic_guad(): x = paddle.to_tensor(self.x_np) out1 = F.thresholded_relu(x, self.threshold, self.value) - thresholded_relu = paddle.nn.ThresholdedReLU(self.threshold, self.value) + thresholded_relu = paddle.nn.ThresholdedReLU( + self.threshold, self.value + ) out2 = thresholded_relu(x) - out_ref = ref_thresholded_relu(self.x_np, self.threshold, self.value) + out_ref = ref_thresholded_relu( + self.x_np, self.threshold, self.value + ) for r in [out1, out2]: np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05)