aclnnMoeDistributeCombineTeardown
Applicable Products
Ascend 950DT products : Supported
Atlas A3 products : Not supported
Atlas A2 products : Not supported
Atlas 200I/500 A2 inference products : Not supported
Atlas inference products : Not supported
Atlas training products : Not supported
Function
Description: Receives data from aclnnMoeDistributeCombineSetup and integrates the data (multiplies by weights and then adds).
Formula:
$$ ataOut = AllToAllV(expandX)\\ xOut = Sum(expertScales * ataOut + expertScales * sharedExpertX) $$Data collected by the MoeDistributeDispatchSetup and MoeDistributeDispatchTeardown operators is returned along the original path. This operator only performs communication status confirmation and data sorting. It confirms the communication status of the data sent by the aclnnMoeDistributeCombineSetup API and performs a weighted sum based on the expert scale weights.
NOTE: This API must be used together with aclnnMoeDistributeDispatchSetup, aclnnMoeDistributeDispatchTeardown, and aclnnMoeDistributeCombineSetup.
Function Prototype
Each operator uses a two-phase API. First, call the "aclnnMoeDistributeCombineTeardownGetWorkspaceSize" API to obtain the input parameters, calculate the workspace size required for computation based on the computation process, and obtain the executor that contains the computation process. Then, call the "aclnnMoeDistributeCombineTeardown" API to execute the computation.
aclnnStatus aclnnMoeDistributeCombineTeardownGetWorkspaceSize(
const aclTensor* expandX,
const aclTensor* quantExpandX,
const aclTensor* expertIds,
const aclTensor* expandIdx,
const aclTensor* expertScales,
const aclTensor* commCmdInfo,
const aclTensor* xActiveMaskOptional,
const aclTensor* sharedExpertXOptional,
const char* groupEp,
int64_t epWorldSize,
int64_t epRankId,
int64_t moeExpertNum,
int64_t expertShardType,
int64_t sharedExpertNum,
int64_t sharedExpertRankNum,
int64_t globalBs,
int64_t commQuantMode,
int64_t commType,
const char* commAlg,
aclTensor* xOut,
uint64_t* workspaceSize,
aclOpExecutor** executor)aclnnStatus aclnnMoeDistributeCombineTeardown(
void* workspace,
uint64_t workspaceSize,
aclOpExecutor* executor,
aclrtStream stream)aclnnMoeDistributeCombineTeardownGetWorkspaceSize
Parameters
Parameter Input/Output Description Instruction Data Type Data Format Dimension Non-contiguous Tensor expandX (aclTensor*) Input Token features expanded based on expertIds. Empty tensors are not supported. FLOAT16, BFLOAT16 ND (A, H) √ quantExpandX (aclTensor*) Input Corresponds to the quantExpandX output of aclnnMoeDistributeCombineSetup. Empty tensors are not supported. INT8 ND (A, tokenMsgSize) √ expertIds(aclTensor*) Input topK expert indices of each token. Empty tensors are not supported. INT32 ND (Bs, K) √ expandIdx (aclTensor*) Input Corresponds to the expandIdx output of aclnnMoeDistributeDispatchSetup. Empty tensors are not supported. INT32 ND (BS * K, ) √ expertScales (aclTensor*) Input Weights of the topK experts of each token. Empty tensors are not supported. FLOAT32 ND (BS, K) √ commCmdInfo (aclTensor*) Input Output of aclnnMoeDistributeCombineSetup, containing cmd information for communication. Empty tensors are not supported. INT32 ND ((A + epWorldSize) * 16, ) √ xActiveMaskOptional (aclTensor*) Optional input Indicates whether tokens participate in communication. Empty tensors are not supported. Pass in valid data or a null pointer. A null pointer indicates that all tokens participate in communication. BOOL ND (BS, ) √ sharedExpertXOptional (aclTensor*) Optional input Indicates the token computed by the shared expert. Empty tensors are not supported. The input must be a 2D or 3D tensor. If the tensor is 2D, its shape is (BS,H). If the tensor is 3D, the product of the first two dimensions must equal BS, and the third dimension must equal H. The data type must be the same as that of expandX. Pass in valid data or a null pointer. If valid data is passed in, sharedExpertNum must be 0. FLOAT16, BFLOAT16 ND (BS, H) or (a, b, H) √ groupEp Input EP communicator name. String length: [1, 128) - - - - epWorldSize Input EP communicator size Value range: [2, 384] - - - - epRankId Input ID of the current device in the EP communicator. Value range [0, epWorldSize).
The epRankId of each device in the same EP communicator must be unique.- - - - moeExpertNum Input Number of MoE experts Value range: (0, 512].
Must satisfy moeExpertNum % (epWorldSize - sharedExpertRankNum) = 0.- - - - expertShardType Input Distribution type of shared expert cards. Currently only supports passing in 0, indicating that shared expert cards are placed before MoE expert cards. - - - - sharedExpertNum Input Number of shared experts Current value range: [0, 4]. 0 indicates no shared expert. Currently only supports no shared expert. - - - - sharedExpertRankNum Input Quantity of shared expert cards. Current value range [0, epWorldSize / 2]. - - - - globalBs Input Global batch size in the EP domain. If the Bs value is the same on each rank, globalBs = Bs * epWorldSize or globalBs = 0. If the Bs values differ across ranks, globalBs = maxBs * epWorldSize, among which maxBs indicates the maximum Bs on a single device. - - - - commQuantMode Input Communication quantization type. Value range [0, 2]. 0 indicates no quantization during communication. Currently only supports 0. - - - - commType Input Communication solution selection. Value range [0, 2]. 0 indicates the AICPU-SDMA solution, 1 indicates the CCU solution, and 2 indicates the URMA solution. Currently only supports 2. - - - - commAlg Input Communication algorithm selection. Only a null pointer or an empty string can be passed in. - - - - xOut (aclTensor*) Output Indicates the processed token. Empty tensors are not supported. The data type is the same as expandX. FLOAT16, BFLOAT16 ND (BS, H) √ workspaceSize Output Returns the size of the workspace to be allocated on the Device. - - - - - executor Output Returns the op executor, which contains the operator computation flow. - - - - - - Ascend 950DT products:
- The shared expert scenario is not supported.
- epWorldSize: the current value only supports 2 and 8.
- moeExpertNum indicates the MoE expert count. Currently, you can only pass in 32.
- expertShardType: only 0 is supported currently, indicating that shared expert devices are placed before MoE expert devices.
- sharedExpertNum indicates the shared expert count. Shared experts are currently not supported. You can only pass in 0.
- sharedExpertRankNum indicates the number of shared expert cards. Shared experts are currently not supported. You can only pass in 0.
- commQuantMode currently only supports 0, indicating that no quantization is performed.
- The value range of commType is [0, 2]. Currently only 2 is supported, indicating the URMA path.
- commAlg is not supported in the current version. Pass a null pointer.
- Atlas A3 products:
- The shared expert scenario is not supported.
- epWorldSize: the current value only supports 2 and 8.
- moeExpertNum indicates the MoE expert count. Currently, you can only pass in 32.
- expertShardType: only 0 is supported currently, indicating that shared expert devices are placed before MoE expert devices.
- sharedExpertNum indicates the shared expert count. Shared experts are currently not supported. You can only pass in 0.
- sharedExpertRankNum indicates the number of shared expert cards. Shared experts are currently not supported. You can only pass in 0.
- commQuantMode currently only supports 0, indicating that no quantization is performed.
- The value range of commType is [0, 2]. Currently only 2 is supported, indicating the URMA path.
- commAlg is not supported in the current version. Pass a null pointer.
- Ascend 950DT products:
Return Value
aclnnStatus: Returns the status code. For details, see aclnn return codes.
The first-phase API performs input parameter validation and returns an error in the following scenarios:
Return Value Error Code description ACLNN_ERR_PARAM_NULLPTR 161001 A required input or output tensor is a null pointer. ACLNN_ERR_PARAM_INVALID 161002 The data type of the input or output is not in the supported range. ACLNN_ERR_INNER_TILING_ERROR 561002 The shape of the input or output is not in the supported range. The parameter value is out of the supported range.
aclnnMoeDistributeCombineTeardown
Parameters:
Parameter Input/Output Description workspace Input Workspace memory address allocated on the Device. workspaceSize Input Workspace size allocated on the Device, obtained by the first-phase API aclnnMoeDistributeCombineTeardownGetWorkspaceSize. executor Input Op executor, which contains the computation process of the operator. Specifies the stream for executing tasks. Return value
Returns the aclnnStatus return code. For details, see aclnn Return Codes.
Constraints
Deterministic computation:
- aclnnMoeDistributeCombineTeardown defaults to a deterministic implementation.
The aclnnMoeDistributeDispatchSetup API, aclnnMoeDistributeDispatchTeardown API, aclnnMoeDistributeCombineSetup API, and aclnnMoeDistributeCombineTeardown API must be used together.
The values of the
groupEp,epWorldSize,moeExpertNum,expertShardType,sharedExpertNum,sharedExpertRankNum,globalBs,commQuantMode,commType, andcommAlgparameters used in the API call must remain consistent across all devices; the values of thegroupEp,epWorldSize,expertShardType,sharedExpertNum,sharedExpertRankNum,globalBs,commQuantMode,commType, andcommAlgparameters must also remain consistent across different layers in the network and with the corresponding parameters of the aclnnMoeDistributeDispatchSetup, aclnnMoeDistributeDispatchTeardown, and aclnnMoeDistributeCombineSetup APIs.Description of the shape format in Parameters:
- A: the maximum number of tokens that the current card needs to distribute. The value range is as follows:
- For shared experts, A must satisfy A = BS * epWorldSize * sharedExpertNum / sharedExpertRankNum; when globalBs is not 0, A must satisfy A = globalBs* sharedExpertNum / sharedExpertRankNum.
- For MoE experts, when globalBs is 0, A >= BS * epWorldSize * min(localExpertNum, K) must be satisfied; when globalBs is non-0, A >= globalBs * min(localExpertNum, K) must be satisfied.
- H: indicates the hidden size. The value range is [1024, 8196]. Currently only 4096 and 7168 are supported.
- HS: indicates the data size in communication, which is Align512( Align32(H) + Align8(H) / 8 *sizeof(float) ), where Align512(x) = ((x + 512 - 1) / 512) * 512, Align32(x) = ((x + 32 - 1) / 32) * 32, Align8(x) = ((x + 8 - 1) / 8) * 8.
- BS: indicates the batch sequence size, that is, the final number of tokens output by this device. The value range is 0 < BS ≤ 512. Currently only 8, 16, and 256 are supported.
- K: indicates selecting topK experts. The value range is 0 < K ≤ 16 and must satisfy 0 < K ≤ moeExpertNum. Currently only 6 and 8 are supported.
- localExpertNum: indicates the number of experts on the current card.
- For a shared expert card, localExpertNum = 1.
- For MoE expert cards, localExpertNum = moeExpertNum / (epWorldSize - sharedExpertRankNum). moeExpertNum currently only supports 32.
- tokenMsgSize: indicates the dimension information of each token during data communication. The calculation formula is Align512(Align32(H)+Align8(H)/8*sizeof(float)), where AlignN(x)=((x+N-1)/N*N).
- Shared experts are currently not supported. sharedExpertNum and sharedExpertRankNum currently only support 0.
- A: the maximum number of tokens that the current card needs to distribute. The value range is as follows:
HCCL_BUFFSIZE: Before calling this API, check whether the value of the HCCL_BUFFSIZE environment variable is reasonable. This environment variable indicates the memory size occupied by a single communication domain, in MB. The default value is 200 MB when not configured.
- Ascend 950DT products:
- Requires >= 2 and satisfies >= 2 * (localExpertNum * maxBs * epWorldSize * Align512(Align32(2 * H) + 44) + (K + sharedExpertNum) * maxBs * Align512(2 * H)), localExpertNum must use the local expert count of the MoE expert card, where Align512(x) = ((x + 512 - 1) / 512) * 512, Align32(x) = ((x + 32 - 1) / 32) * 32
- Atlas A3 products:
- Requires >= 2 and satisfies >= 2 * (localExpertNum * maxBs * epWorldSize * Align512(Align32(2 * H) + 44) + (K + sharedExpertNum) * maxBs * Align512(2 * H)), localExpertNum must use the local expert count of the MoE expert card, where Align512(x) = ((x + 512 - 1) / 512) * 512, Align32(x) = ((x + 32 - 1) / 32) * 32
- Ascend 950DT products:
Communication domain usage constraints:
- In a model, the aclnnMoeDistributeDispatchSetup, aclnnMoeDistributeDispatchTeardown, aclnnMoeDistributeCombineSetup, and aclnnMoeDistributeCombineTeardown APIs support only the same EP communication domain. No other operators are allowed in this communication domain.
Communication mode constraints:
Ascend 950DT products : Only URMA communication is supported.
Example
- Ascend 950DT products: aclnnMoeDistributeCombineTeardown must be called after aclnnMoeDistributeCombineSetup is called. See the example in aclnnMoeDistributeCombineSetup.