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_r393266735
 
 

 ##########
 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:
   There's reference implementation in mkldnn that uses a different threshold 
and also does type cast. 
https://github.com/intel/mkl-dnn/commit/23f45a2e4cb4158e6111d3e59d91b66038636edb#diff-b476290dff3dd01b30438be4ae713928R174
   
   Shall we adopt the same logic for consistency?

----------------------------------------------------------------
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