From ec72f5b235a2571121c678bdf1fa4409a8cb6f80 Mon Sep 17 00:00:00 2001 From: Qi Li Date: Tue, 2 Mar 2021 18:13:53 +0800 Subject: [PATCH] fix ELU output for nan, test=develop (#31132) --- paddle/fluid/operators/activation_op.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/operators/activation_op.h b/paddle/fluid/operators/activation_op.h index 289cc70392..bc7def61b2 100644 --- a/paddle/fluid/operators/activation_op.h +++ b/paddle/fluid/operators/activation_op.h @@ -1184,9 +1184,9 @@ struct ELUFunctor : public BaseActivationFunctor { template void operator()(Device d, X x, Out out) const { - out.device(d) = x.cwiseMax(static_cast(0)) + - (static_cast(alpha) * (x.exp() - static_cast(1))) - .cwiseMin(static_cast(0)); + out.device(d) = + (x < static_cast(0)) + .select(static_cast(alpha) * (x.exp() - static_cast(1)), x); } }; -- GitLab