[object Object][object Object][object Object]undefined
[object Object]
  • Description: Computes the backpropagation of [object Object].

  • Formula:

    • If [object Object] is not set to [object Object], the formula is as follows, where i0,1,2,...,num_tokens1i \in {0, 1, 2, ..., num\_tokens – 1}:

      • First, calculate [object Object].

        • When the condition rangeOptional[0] ≤ sortedIndices[i] < rangeOptional[1] is met,

          unpermutedTokens[i]=permutedTokensOptional[sortedIndices[i]rangeOptional[0]]unpermutedTokens[i] = permutedTokensOptional[sortedIndices[i]-rangeOptional[0]]
        • Otherwise,

          unpermutedTokens[i]=0unpermutedTokens[i] = 0
      • Then, compute the following:

        unpermutedTokens=unpermutedTokens.reshape(1,topkNum,hiddenSize)unpermutedTokens = unpermutedTokens.reshape(-1, topkNum, hiddenSize) unpermutedTokens=unpermutedTokensGrad.unsqueeze(1)unpermutedTokensunpermutedTokens = unpermutedTokensGrad.unsqueeze(1) * unpermutedTokens probsGrad=k=0topkNum(unpermutedTokensi,j,k)probsGrad = \sum_{k=0}^{topkNum}(unpermutedTokens_{i,j,k})
      • Finally, when the condition rangeOptional[0] ≤ sortedIndices[i] < rangeOptional[1] is met,

      permutedTokensGradOut[sortedIndices[i]]=((unpermutedTokensGrad.unsqueeze(1)probs.unsqueeze(1)).reshape(1,hiddenSize))[i]permutedTokensGradOut[sortedIndices[i]] = ((unpermutedTokensGrad.unsqueeze(1) * probs.unsqueeze(-1)).reshape(-1, hiddenSize))[i]
    • If [object Object] is set to [object Object], the formula is as follows, where i0,1,2,...,num_tokens1i \in {0, 1, 2, ..., num\_tokens – 1}:

      • When the condition rangeOptional[0] ≤ sortedIndices[i] < rangeOptional[1] is met,
      permutedTokensGradOut[sortedIndices[i]rangeOptional[0]]=unpermutedOutputGrad[i]permutedTokensGradOut[sortedIndices[i]-rangeOptional[0]] = unpermutedOutputGrad[i]
[object Object]

Each operator has calls. First, [object Object] is called to obtain the workspace size required for computation and the executor that contains the operator computation process. Then, [object Object] is called to perform computation.

  • [object Object]
  • [object Object]
[object Object]
  • Parameters:

    • [object Object] (aclTensor*, computation input): aclTensor on the device, that is, [object Object] in the formula. It indicates the gradient of the forward output [object Object]. The value must be a 2D tensor with shape (tokens_num, hidden_size). [object Object] indicates the number of tokens, and [object Object] indicates the token dimension size. The data type can be BFLOAT16, FLOAT16, or FLOAT32. The must be ND. are supported.
    • [object Object] (aclTensor*, computation input): aclTensor on the device, that is, [object Object] in the formula. The value must be a 1D shape with size (tokens_num * topkNum). The data type can be INT32. The must be ND. The index value range is [0, tokens_num * topkNum – 1]. are supported.
    • [object Object] (aclTensor*, computation input): aclTensor on the device, that is, [object Object] in the formula. This input is optional. The value must be a 2D tensor with shape (tokens_num * topkNum, hidden_size), where the value of [object Object] is less than or equal to [object Object]. The data type is the same as that of [object Object]. The must be ND. are supported.
    • [object Object] (aclTensor*, computation input): aclTensor on the device, that is, [object Object] in the formula. This input is optional. The value must be a 2D shape with size (tokens_num, topkNum). The data type can be BFLOAT16, FLOAT16, or FLOAT32. The must be ND. When [object Object] is passed, the value of [object Object] equals the second dimension of [object Object]. When [object Object] is not passed, the value of [object Object] is [object Object]. are supported.
    • [object Object] (bool, computation input): [object Object] in the formula. The value [object Object] indicates that [object Object] is enabled, and the value [object Object] indicates that [object Object] is disabled. For details about [object Object], see the description of the [object Object] parameter. Currently, only [object Object] is supported.
    • [object Object] (aclIntArray*, computation input): [object Object] in the formula. This parameter takes effect only when [object Object] is set to [object Object]. Otherwise, no operation is performed on this parameter. When [object Object] is set to [object Object], the shape is the same as that of [object Object]. Currently, only [object Object] is supported.
    • [object Object] (aclIntArray*, computation input): [object Object] in the formula, which indicates the valid range of EP slicing. The start position represented by [object Object] must be less than the end position represented by [object Object]. The size is [object Object]. This parameter does not take effect when it is left empty.
    • [object Object] (int64_t, computation input): [object Object] in the formula, which indicates the number of experts selected for each token.
    • [object Object] (aclTensor*, computation output): gradient of the input [object Object]. The value must be a 2D tensor with shape (tokens_num * topkNum, hidden_size). The data type is the same as that of [object Object]. The data type can be BFLOAT16, FLOAT16, or FLOAT32. The must be ND. Non-contiguous output is not supported.
    • [object Object] (aclTensor*, computation output): optional output, which is the gradient of the input [object Object]. The value must be a 2D tensor with shape (tokens_num, topkNum). The data type is the same as that of [object Object]. The data type can be BFLOAT16, FLOAT16, or FLOAT32. The must be ND. Non-contiguous output is not supported.
    • [object Object] (uint64_t *, output): size of the workspace to be allocated on the device.
    • [object Object] (aclOpExecutor **, output): operator executor, containing the operator computation process.
  • Returns:

    [object Object]: status code. For details, see .

[object Object]
[object Object]
  • Parameters:

    • [object Object] (void*, input): address of the workspace to be allocated on the device.
    • [object Object] (uint64_t, input): size of the workspace to be allocated on the device, which is obtained by calling the first-phase API [object Object].
    • [object Object] (aclOpExecutor*, input): operator executor, containing the operator computation process.
    • [object Object] (aclrtStream, input): stream for executing the task.
  • Returns:

    [object Object] status code. For details, see .

[object Object]
  • Deterministic computation:
    • [object Object] defaults to deterministic implementation.
  • The value of [object Object] is less than or equal to [object Object].
[object Object]

The following example is for reference only. For details, see .

[object Object]