szha commented on a change in pull request #17849: Fix SoftReLU fused operator 
numerical stability
URL: https://github.com/apache/incubator-mxnet/pull/17849#discussion_r393296479
 
 

 ##########
 File path: src/operator/fusion/fused_op-inl.h
 ##########
 @@ -550,7 +550,10 @@ __device__ inline DType sigmoid(const DType val) {
 
 template <typename DType>
 __device__ inline DType softrelu(const DType val) {
-  return logf(1 + expf(val));
+  // Avoid overflow of exp for large inputs.
+  // The threshold 20 is chosen such that softrelu(a) = a
+  // for a > 20 using floating precision.
+  return val > 20 ? val : logf(1 + expf(val));
 
 Review comment:
   OK

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to