[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: This operator is used for permutation computation in MoE. It passes tokens and expert labels as [object Object] and sorts the tokens and optional [object Object] based on routingMap after broadcasting them.

  • Formula:

    [object Object] indicates the size of the zeroth dimension of [object Object], and [object Object] indicates the size of the first dimension of [object Object]. When [object Object] is set to [object Object]:

    expertIndex=arange(tokens_num).expand(expert_num,1)expertIndex=arange(tokens\_num).expand(expert\_num,-1) sortedIndicesFirst=expertIndex.masked_select(routingMap.T)sortedIndicesFirst=expertIndex.masked\_select(routingMap.T) sortedIndicesOut=argsort(sortedIndicesFirst)sortedIndicesOut=argsort(sortedIndicesFirst) topK=numOutTokens//tokens_numtopK = numOutTokens // tokens\_num outToken=topKtokens_numoutToken = topK * tokens\_num permuteTokensOut[sortedIndicesOut[i]]=tokens[i//topK]permuteTokensOut[sortedIndicesOut[i]]=tokens[i//topK]

    If [object Object] is not set to [object Object]:

    permuteProbsOutOptional=probsOptional.T.masked_select(routingMap.T)permuteProbsOutOptional=probsOptional.T.masked\_select(routingMap.T)

    When [object Object] is set to [object Object]:

    capacity=numOutTokens//expert_numcapacity = numOutTokens // expert\_num outToken=capacityexpert_numoutToken = capacity * expert\_num sortedIndicesOut=argsort(routingMap.T,dim=1)[:,:capacity]sortedIndicesOut = argsort(routingMap.T,dim=-1)[:, :capacity] permutedTokensOut=tokens.index_select(0,sortedIndicesOut)permutedTokensOut = tokens.index\_select(0, sortedIndicesOut)

    If [object Object] is not set to [object Object]:

    probs_T_1D=probsOptional.T.view(1)probs\_T\_1D = probsOptional.T.view(-1) indices_dim0=arange(expert_num).view(expert_num,1)indices\_dim0 = arange(expert\_num).view(expert\_num, 1) indices_dim1=sortedIndicesOut.view(expert_num,capacity)indices\_dim1 = sortedIndicesOut.view(expert\_num, capacity) indices_1D=(indices_dim0tokens_num+indices_dim1).view(1)indices\_1D = (indices\_dim0 * tokens\_num + indices\_dim1).view(-1) permuteProbsOutOptional=probs_T_1D.index_select(0,indices_1D)permuteProbsOutOptional = probs\_T\_1D.index\_select(0, indices\_1D)
[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]
  • Returns:

    aclnnStatus: status code. For details, see [object Object]aclnn Return Codes[object Object].

    The first-phase API implements input parameter verification. The following errors may be thrown.

    [object Object]
[object Object]
  • Parameters:

    [object Object]
  • Returns:

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

[object Object]
  • Deterministic computation:

    • [object Object] defaults to deterministic implementation.
  • The values of [object Object] and [object Object] must be less than [object Object]. When [object Object] is set to [object Object], the number of 1s or [object Object] values in each row of [object Object] is fixed and less than [object Object].

[object Object]

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

[object Object]