haojin2 commented on a change in pull request #15169: Softmax with length
URL: https://github.com/apache/incubator-mxnet/pull/15169#discussion_r303657013
 
 

 ##########
 File path: src/operator/nn/softmax-inl.h
 ##########
 @@ -177,6 +231,51 @@ inline void SoftmaxGrad(Stream<cpu> *s, OType *out, OType 
*ograd,
   }
 }
 
+template<typename OP1, typename OP2, int Req, bool negate,
+  typename AType, typename DType, typename OType, typename IType, int ndim>
+inline void SoftmaxWithLengthGrad(Stream<cpu> *s, OType *out, OType *ograd,
+                                  DType *igrad, IType *length, Shape<ndim> 
shape,
+                                  int axis, const DType temperature) {
+  index_t M = shape[axis];
+  index_t N = shape.Size()/M;
+  Shape<ndim> stride = calc_stride(shape);
+  Shape<ndim> sshape = shape;
+  sshape[axis] = 1;
+  index_t sa = stride[axis];
+
+  #pragma omp parallel for
+  for (int i = 0; i < static_cast<int>(N); ++i) {
+    index_t base = unravel_dot(i, sshape, stride);
+    IType len = length[i];
 
 Review comment:
   Why does it have to be the same data type as `M`? It's a tensor provided by 
the user so the user could be providing a tensor of any data type.

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


With regards,
Apache Git Services

Reply via email to