aclnnMoeDistributeDispatchTeardown
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 sent by the AllToAllV communication in the EP (Expert Parallelism) domain of the MOE layer. Data sending is completed by aclnnMoeDistributeDispatchSetup. This API confirms the communication status and organizes the data.
Note that this API must be used together with aclnnMoeDistributeDispatchSetup, aclnnMoeDistributeCombineSetup, and aclnnMoeDistributeCombineTeardown.
Function Prototype
Each operator uses a two-phase API. Call "aclnnMoeDistributeDispatchTeardownGetWorkspaceSize" first to obtain the workspace size required for computation and the executor containing the operator computation process. Then call "aclnnMoeDistributeDispatchTeardown" to execute the computation.
aclnnStatus aclnnMoeDistributeDispatchTeardownGetWorkspaceSize(
const aclTensor* x,
const aclTensor* y,
const aclTensor* expertIds,
const aclTensor* commCmdInfo,
const char* groupEp,
int64_t epWorldSize,
int64_t epRankId,
int64_t moeExpertNum,
int64_t expertShardType,
int64_t sharedExpertNum,
int64_t sharedExpertRankNum,
int64_t quantMode,
int64_t globalBs,
int64_t expertTokenNumsType,
int64_t commType,
char* commAlg,
aclTensor* expandXOut,
aclTensor* dynamicScalesOut,
aclTensor* assistInfoForCombineOut,
aclTensor* expertTokenNumsOut,
uint64_t* workspaceSize,
aclOpExecutor** executor)aclnnStatus aclnnMoeDistributeDispatchTeardown(
void *workspace,
uint64_t workspaceSize,
aclOpExecutor *executor,
aclrtStream stream)aclnnMoeDistributeDispatchTeardownGetWorkspaceSize
Parameters
Parameter Input/Output Description Instruction Data Type Data Format Dimension (shape) Non-contiguous Tensor x Input Indicates the token data sent by the local device. The requirement is a 2D Tensor. FLOAT16, BFLOAT16 ND (Bs, H) √ y Input Output of aclnnMoeDistributeDispatchSetup. Indicates the communication data to be sent by the local device. The communication data is the input token data rearranged by the algorithm; if quantization is required, the input token data is quantized first and then rearranged. The requirement is a 2D Tensor. FLOAT16, BFLOAT16, INT8, HIFP8, FP8E5M2, FP8E4M3 ND (BS * (K + sharedExpertNum), tokenMsgSize) √ expertIds Input Indexes of the topK experts for each token. The requirement is a 2D Tensor. INT32 ND (Bs, K) √ commCmdInfo Input Output of aclnnMoeDistributeDispatchSetup, indicating the cmd information of the communication. Requirement is a 1D tensor. INT32 ND (BS * (K + sharedExpertNum) + epWorldSize * localExpertNum) * 16 √ groupEp Input Name of the EP communication domain (expert parallel communication domain). The string length range is [1, 128). STRING - - - epWorldSize Input Size of the EP communication domain. The value range is [2, 384]. INT64 - - - epRankId Input Local device ID in the EP domain. The value range is [0, epWorldSize). Devices in the same EP communication domain must have a unique epRankId. INT64 - - - moeExpertNum Input Number of MoE experts. The value range is (0, 512]. The requirement is moeExpertNum % (epWorldSize - sharedExpertRankNum) = 0. INT64 - - - expertShardType Input Indicates the distribution type of shared expert cards. Currently, only 0 is supported, indicating that shared expert cards are placed before MoE expert cards. INT64 - - - sharedExpertNum Input Indicates the number of shared experts. The value range is [0, 4] in the current version. INT64 - - - sharedExpertRankNum Input Indicates the number of shared expert cards. The value range is [0, epWorldSize / 2] INT64 - - - quantMode Input Indicates the quantization mode. The value range is [0, 4]. 0 indicates non-quantization, 1 indicates static quantization, 2 indicates Pertoken dynamic quantization, 3 indicates Pergroup dynamic quantization, and 4 indicates MX quantization. Currently, only 0 and 4 are supported. INT64 - - - globalBs Input Global batch size across the EP domain. - When all ranks have the same Bs, globalBs = Bs * epWorldSize or 0.
- When the Bs values of ranks are different, globalBs = maxBs * epWorldSize (maxBs is the maximum Bs value per device).
INT64 - - - expertTokenNumsType Input Indicates the semantic type of values in output expertTokenNums. - If the value is 0, the output in expertTokenNums indicates the prefix sum of the tokens processed by each expert. If the value is 1, the output in expertTokenNums indicates the number of tokens processed by each expert.
INT64 - - - commType Input Indicates the communication solution selection. The value range is [0, 2]. 0 indicates the AICPU-SDMA solution, 1 indicates the CCU solution, and 2 indicates the URMA solution. The current version supports only 2. INT64 - - - commAlg Input Indicates the communication affinity memory layout algorithm. Reserved field. Not supported in the current version. Pass NULL or an empty string. STRING - - - expandXOut Output Token features expanded based on expertIds. The requirement is a 2D Tensor. FLOAT16, BFLOAT16, INT8, FP8E5M2, FP8E4M3, HIFP8 ND (A, H) √ dynamicScalesOut Output Dynamic quantization parameters of each token. The requirement is a 1D Tensor. Actual valid values are output only when quantMode is 2, 3, or 4. FLOAT32, FP8E8M0 ND (A, ) √ assistInfoForCombineOut Output Indicates the number of tokens sent to the same expert, corresponding to assistInfoForCombine in the Combine series operators. Requirement is a 1D tensor. INT32 ND (A * 128, ) √ expertTokenNumsOut Output Indicates the number of tokens received by each expert. The requirement is a 1D Tensor. INT64 ND (localExpertNum, ) √ workspaceSize Output Returns the workspace size required for Device side application. - - - - - executor Output Returns the op executor, which includes calculation flow of the operator. - - - - - Ascend 950DT products :- groupEp: string length range [1, 128).
- The value range of epWorldSize is [2, 384]. Currently, only 2 and 8 are supported.
- The value range of epRankId is [0, epWorldSize). epRankId must be unique for each device in the same EP communication domain.
- The value range of moeExpertNum is (0, 512].
- expertShardType: only 0 is supported currently, indicating that shared expert devices are placed before MoE expert devices.
- sharedExpertNum: current value range [0, 4].
- The value range of sharedExpertRankNum is [0, epWorldSize / 2].
- globalBs: if the Bs value is the same on each rank, globalBs = Bs * epWorldSize or globalBs = 0; if the Bs value differs across ranks, globalBs = maxBs * epWorldSize, where maxBs indicates the maximum Bs value on a single device.
- expertTokenNumsType supports only 1 currently.
- commType supports only 2 currently.
- commAlg is a reserved field and is not supported in the current version. Pass NULL.
Atlas A3 products :- groupEp: string length range [1, 128).
- epWorldSize: value range [2, 384].
- The value range of epRankId is [0, epWorldSize). epRankId must be unique for each device in the same EP communication domain.
- The value range of moeExpertNum is (0, 512].
- expertShardType: only 0 is supported currently, indicating that shared expert devices are placed before MoE expert devices.
- sharedExpertNum: current value range [0, 4].
- The value range of sharedExpertRankNum is [0, epWorldSize / 2].
- globalBs: if the Bs value is the same on each rank, globalBs = Bs * epWorldSize or globalBs = 0; if the Bs value differs across ranks, globalBs = maxBs * epWorldSize, where maxBs indicates the maximum Bs value on a single device.
- commType currently supports only 0.
- commAlg is not supported in the current version. Pass a null pointer.
Return value
aclnnStatus: return 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 and output is out of the supported range. ACLNN_ERR_INNER_TILING_ERROR 561002 The shape of the input and output is out of the supported range. The parameter value is not within the supported range.
aclnnMoeDistributeDispatchTeardown
Parameters
Parameter Input/Output Description workspace Input Pointer to the workspace memory allocated on the Device. workspaceSize Input Size of the workspace allocated on the Device, obtained by the first-phase API aclnnMoeDistributeCombineV2GetWorkspaceSize. executor Input Op executor, includes calculation of the operator. stream Input Specifies the Stream for task execution. Return Value
aclnnStatus: return status code. For details, see aclnn Return Codes.
Constraints
Deterministic computation:
- aclnnMoeDistributeDispatchTeardown defaults to a deterministic implementation.
The aclnnMoeDistributeDispatchTeardown API must be used together with the aclnnMoeDistributeDispatchSetup, aclnnMoeDistributeCombineSetup, and aclnnMoeDistributeCombineTeardown APIs.
The values of the
groupEp,epWorldSize,moeExpertNum,expertShardType,sharedExpertNum,sharedExpertRankNum,globalBs,commQuantMode,commType, andcommAlgparameters used during the API call must be consistent across all devices; the values of thegroupEp,epWorldSize,expertShardType,sharedExpertNum,sharedExpertRankNum,globalBs,commQuantMode,commType, andcommAlgparameters must also be consistent across different layers in the network and consistent with the corresponding parameters ofaclnnMoeDistributeDispatchTeardown,aclnnMoeDistributeCombineSetup, andaclnnMoeDistributeCombineTeardown.Atlas A3 products : In this use case, each device contains dual DIEs (referred to as "die" or "bare die"). Therefore, "local device" in Parameters indicates a single DIE.Description of the shape format in Parameters:
A: Indicates the maximum token quantity that the current device can receive. The value range is as follows:
- For MoE experts, when globalBs is 0, A >=
BS*epWorldSize* min(localExpertNum,K) must be met; whenglobalBsis not 0, A >=globalBs* min(localExpertNum,K) must be met. - For shared experts, when
globalBsis 0, A =BS*epWorldSize*sharedExpertNum/sharedExpertRankNummust be met; when globalBs is not 0, A =globalBs*sharedExpertNum/sharedExpertRankNummust be met.
- For MoE experts, when globalBs is 0, A >=
H: Indicates the hidden size. The value range is [1024, 8192]. Currently, only 4096 and 7168 are supported.
BS: Indicates the batch sequence size, that is, the quantity of tokens finally output by the current device. The value range is 0 <
BS≤ 512. Currently, only 8, 16, and 256 are supported.K: Indicates that topK experts are selected. The value range is 0 <
K≤ 16, and 0 <K≤moeExpertNummust also be met. 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 devices, localExpertNum =
moeExpertNum/ (epWorldSize-sharedExpertRankNum). Currently, only 32 is supported for moeExpertNum.
tokenMsgSize: Indicates the dimension information of each token during data communication.
- In non-quantization use cases, tokenMsgSize = Align256(H).
- In quantization use cases, tokenMsgSize = Align512(Align32(H) + 4 ), where AlignN(x) = ((x + N - 1) / N) * N.
Shared experts are not supported in the current version. sharedExpertNum and sharedExpertRankNum currently support only 0.
HCCL_BUFFSIZE:
Ascend 950DT products : Before calling this API, check whether the value of theHCCL_BUFFSIZEenvironment variable is appropriate. This environment variable specifies the memory size occupied by a single communication domain, in MB. The default value is 200 MB if it is not configured. The value must be >= 2 and satisfy >= 2 * (localExpertNum*maxBs*epWorldSize* Align512(Align32(2 * H) + 44) + (K+sharedExpertNum) *maxBs* Align512(2 *H)), wherelocalExpertNumindicates the number of local experts on devices that use MoE experts, Align512(x) = ((x + 512 - 1) / 512) * 512, and Align32(x) = ((x + 32 - 1) / 32) * 32.
Atlas A3 products : Before calling this API, check whether the value of theHCCL_BUFFSIZEenvironment variable is appropriate. This environment variable specifies the memory size occupied by a single communication domain, in MB. The default value is 200 MB if it is not configured. The value must be >= 2 and satisfy >= 2 * (localExpertNum*maxBs*epWorldSize* Align512(Align32(2 * H) + 44) + (K+sharedExpertNum) *maxBs* Align512(2 *H)), wherelocalExpertNumindicates the number of local experts on devices that use MoE experts, Align512(x) = ((x + 512 - 1) / 512) * 512, and Align32(x) = ((x + 32 - 1) / 32) * 32.
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 : aclnnMoeDistributeDispatchTeardown must be called after aclnnMoeDistributeDispatchSetup. For details, see the example in aclnnMoeDistributeDispatchSetup.