From ff48a2f09cb24ffcc795a59968ecdca1f8265226 Mon Sep 17 00:00:00 2001 From: Juhyun Lee Date: Wed, 4 Sep 2024 19:39:32 -0700 Subject: [PATCH] Fix tanh for large inputs PiperOrigin-RevId: 671189741 --- tensorflow/lite/delegates/gpu/common/tasks/elementwise.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/lite/delegates/gpu/common/tasks/elementwise.cc b/tensorflow/lite/delegates/gpu/common/tasks/elementwise.cc index ff8cf35fd4b56b..4a2607f6657380 100644 --- a/tensorflow/lite/delegates/gpu/common/tasks/elementwise.cc +++ b/tensorflow/lite/delegates/gpu/common/tasks/elementwise.cc @@ -144,8 +144,8 @@ std::string GetOneInputCode(const GpuInfo& gpu_info, "FLT4 exp_val = convert_half4(native_exp(2.0f * " "convert_float4($1)));\n"; result += - "$0 = ((exp_val - INIT_FLT4(1.0f)) / (exp_val + " - "INIT_FLT4(1.0f)));"; + "$0 = isinf(exp_val) ? sign($1) : ((exp_val - INIT_FLT4(1.0f)) / " + "(exp_val + INIT_FLT4(1.0f)));\n"; } else { result = "$0 = tanh($1);"; }