You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/03/16 19:44:28 UTC

[GitHub] [incubator-mxnet] ptrendx commented on a change in pull request #17849: Fix SoftReLU fused operator numerical stability

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

 ##########
 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:
   From the test I did - difference between `logf(1 + expf(20)) - 20` is 0 already, so I think there should not be any difference (and if anything, going to max float should give less precision).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services