FilesLast commitLast update
14 days ago
3 months ago
11 days ago
2 months ago
17 days ago
22 days ago
1 month ago
15 days ago
README

ExpSegsumGrad

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products ×
Atlas inference products ×
Atlas training products ×

Function Description

  • Operator function: the backward computation of Segsum.

  • Computation formula (taking 5D input as an example):

    1. The input gradOutput (N1,N2,N3,N4,N4) is multiplied by the input gradSelf (the output of the forward computation).

      out_mul=gradOutput∗gradSelfout\_mul = gradOutput * gradSelf

    2. Generate the triangular matrix A of the (N4,N4) bool type, where the upper triangle is True, the lower triangle is False, and the diagonal is True.

    3. Fill with 0 the elements in the input out_mulout\_mul corresponding to the positions with the value True in matrix A.

      out_muli={out_muli,Ai==False0,Ai==Trueout\_mul_i= \begin{cases}out\_mul_i,\quad A_i==False \\0, \quad A_i==True \end{cases}

    4. Reverse the second-to-last dimension of out_mul to generate out_flip.

    5. Perform the cumsum accumulation on the second-to-last dimension of out_flipout\_flip. out_cumsum_iout\_cumsum\_{i} is the element at the corresponding position in the output tensor viewed from the dimension perspective (the subscripts of other dimensions remain unchanged, and the subscripts of the current dimension increase in sequence).

      out_cumsumi=out_flip1+out_flip2+out_flip3+......+out_flipiout\_cumsum_{i} = out\_flip_{1} + out\_flip_{2} + out\_flip_{3} + ...... + out\_flip_{i}

    6. Reverse the -2 dimension of out_cumsumout\_cumsum to generate out_flip2.

    7. Generate the triangular matrix B of the (N4,N4) bool type, where the upper triangle is True, the lower triangle is False, and the diagonal is True.

    8. Fill with 0 the elements in out_flip2out\_flip2 corresponding to the positions with the value True in matrix B.

      out_flip2i={out_flip2i,Bi==False0,Bi==Trueout\_flip2_i= \begin{cases}out\_flip2_i,\quad B_i==False \\0, \quad B_i==True \end{cases}

    9. Return gradInput as the sum of each row along the last dimension of out_flip2.

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
grad_output Input The gradient for the backward computation, which corresponds to `gradOutput` in the formula. The input supports 4D or 5D dimensions, and the sizes of the last two dimensions are the same. FLOAT32, FLOAT16, BFLOAT16 ND
grad_self Input The output of the forward computation, which corresponds to `gradSelf` in the formula. Its shape and data type are the same as those of the input `grad_output`. FLOAT32, FLOAT16, BFLOAT16 ND
grad_input Output The output of the backward computation, which corresponds to `out` in the formula. The output must have one fewer dimension than the input, and 3D or 4D is supported. When the input `grad_output` is 4D, the output dimension sizes are the same as the first 3 dimensions of `grad_output`; when the input `grad_output` is 5D, the output dimension sizes are the same as the first 4 dimensions of `grad_output`. The data type is the same as that of the input `grad_output`. FLOAT32, FLOAT16, BFLOAT16 ND

Constraint Description

None

Invocation Description

Invocation Method Sample Code Description
aclnn API test_aclnn_exp_segsum_backward Invokes the ExpSegsumGrad operator through the aclnnExpSegsumBackward API.