- Description: When there is TP domain communication, ReduceScatterV communication is performed first, followed by AllToAllV communication, and finally the received data is combined (multiplied by the weight and then summed). When there is no TP domain communication, AllToAllV communication is performed, and then the received data is combined (multiplied by the weight and then summed).
- Formula:
- When there is no TP domain communication:
- When there is TP domain communication:
[object Object]
Compared with the [object Object] API, this API has the following changes:
- Inputs more detailed token information to assist aclnnMoeDistributeCombineV2 in performing efficient all-rank synchronization. Therefore, the expandIdx input parameter (shape (BS K,)) in the original API is replaced by the assistInfoForCombine parameter (shape (A 128,)).
- Adds the
[object Object]input parameter. When[object Object]is set to 0, users can provide tokens computed by shared experts. - Adds the
[object Object]parameter to replace the[object Object]and[object Object]environment variables.
For details, see the following parameter description.
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.
Parameters
[object Object][object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
- The value of
[object Object]can be[object Object],[object Object],[object Object], or[object Object]. It is recommended to use[object Object]with driver version 25.0.RC1.1 or later. When set to[object Object]or[object Object], the communication algorithm is selected based on HCCL environment variables (not recommended).[object Object]indicates that tokens are directly transmitted through RDMA.[object Object]indicates a two-stage communication process: intra-server communication followed by inter-server communication, which reduces cross-server data transmission. - Shared experts are not supported.
- The shape of
[object Object]is (moeExpertNum + 2 globalBS K serverNum, ), where K indicates the number of top K experts, moeExpertNum indicates the number of tokens received from each rank in the EP communication domain, and 2 globalBS K serverNum indicates the number of tokens and communication area offset that can be combined for the reduce operation before communication across storage servers or within a storage server. If[object Object]is 0, the shape is calculated as follows: BS * epWorldSize. - Currently, TP domain communication is not supported.
[object Object]depends on the[object Object]value: For[object Object], it requires a 1D tensor with shape (BS, ), where[object Object]must precede[object Object](for example, {true, false, true} is invalid); for[object Object], it is currently not supported and a null pointer should be passed.- The value of expandScalesOptional must be a 1D tensor with the shape of (A,).
[object Object]is a reserved parameter, which is not supported in the current version. Pass a null pointer.- The value of epWorldSize depends on the value of commAlg. For "fullmesh", the value can be 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 192, 256, or 384. For "hierarchy", the value can be 16, 32, or 64.
- The value of moeExpertNum ranges from (0, 512].
[object Object]is not supported in the current version. Pass an empty string.[object Object]is not supported in the current version. Pass 0.[object Object]is not supported in the current version. Pass 0.[object Object]is not supported in the current version. Pass 0.[object Object]is not supported in the current version. Pass 0.[object Object]is not supported in the current version. Pass 0.- The value of
[object Object]is 0 or 2 (0 indicates no quantization and 2 indicates int8 quantization). The value 2 is supported only when commAlg is[object Object], or when HCCL_INTRA_PCIE_ENABLE=1, HCCL_INTRA_ROCE_ENABLE=0, and the driver version is 25.0.RC1.1 or later.
- The value of
[object Object]Atlas A3 training products/Atlas A3 inference products[object Object]:
[object Object]is not supported in the current version. Pass a null pointer.- The shape of epSendCounts is (epWorldSize max(tpWorldSize, 1) localExpertNum, ).
- When there is communication in the TP domain, tpSendCountsOptional is a 1D shape tensor, and the shape is (tpWorldSize, ).
[object Object]must be a 1D tensor with shape (BS, ) or a 2D tensor with shape (BS, K). If it is a 1D tensor,[object Object]must be placed before[object Object]. If it is a 2D tensor and the K values corresponding to tokens are all[object Object], the tokens do not participate in communication.- expandScalesOptional is a reserved parameter and is not supported in the current version. You can pass a null pointer.
- sharedExpertXOptional must be a 2D or 3D tensor. (If it is a 2D tensor, the shape is (BS, H). If it is a 3D tensor, the product of the first two dimensions is equal to BS, and the third dimension is equal to H.) This parameter can be passed or not. If it is passed, sharedExpertRankNum must be 0.
- The value of
[object Object]must be in the range [2, 768]. - The value of
[object Object]must be in the range (0, 1024]. [object Object]must be a string of length [0, 128) and cannot be the same as[object Object]. This parameter can be left empty only when there is no TP domain communication.- The value of
[object Object]must be in the range [0, 2]. 0 and 1 indicate no TP domain communication. 2 is required when TP domain communication is used. - The value of
[object Object]must be in the range [0, 1].[object Object]of each rank in the same TP domain must be unique. If TP domain communication is not used, pass 0. - The value of
[object Object]must be 0, indicating that shared expert ranks are placed in front of MoE expert ranks. - The value of
[object Object]must be in the range [0, 4]. - The value of
[object Object]must be in the range [0, epWorldSize). If the value is 0,[object Object]is 0 or 1. If the value is not 0,[object Object]is 0. - The value of
[object Object]is 0 or 2 (0 indicates no quantization and 2 indicates int8 quantization). The value 2 is supported only when tpWorldSize < 2.
Ascend 950PR/Ascend 950DT:
[object Object]is not supported in the current version. Pass a null pointer.- The shape of epSendCounts is (epWorldSize max(tpWorldSize, 1) localExpertNum,).
- tpSendCountsOptional is not supported in the current version. You can pass a null pointer.
- xActiveMaskOptional must be a 1D or 2D tensor. If it is a 1D tensor, the shape is (BS,). If it is a 2D tensor, the shape is (BS, K). In 1D mode, true must be placed before false. For example, {true, false, true} is invalid. In 2D mode, if all the K values corresponding to a token are false, the token is not involved in communication.
[object Object]is a reserved parameter, which is not supported in the current version. Pass a null pointer.- sharedExpertXOptional must be a 2D or 3D tensor. If it is a 2D tensor, the shape is (BS, H). If it is a 3D tensor, the product of the first two dimensions is equal to BS, and the third dimension is equal to H. This parameter can be passed or not. If it is passed, sharedExpertRankNum must be 0.
- The value of
[object Object]must be in the range [2, 768]. - The value of
[object Object]must be in the range (0, 1024]. [object Object]is not supported in the current version. Pass an empty string.[object Object]is not supported in the current version. Pass 0.[object Object]is not supported in the current version. Pass 0.- The value of
[object Object]must be 0, indicating that shared expert ranks are placed in front of MoE expert ranks. - The value of
[object Object]must be in the range [0, 4]. - The value of
[object Object]must be in the range [0, epWorldSize). If the value is 0,[object Object]is 0 or 1. If the value is not 0,[object Object]is 0. - The value of commQuantMode is 0 or 2 (0 indicates no quantization, and 2 indicates int8 quantization).
Returns
[object Object]: status code. For details, see .The first-phase API implements input parameter verification. The following errors may be thrown.
[object Object]
Deterministic computing:
[object Object]defaults to a deterministic implementation.
Driver constraints:
- The driver versions of all nodes in the operator communicator must be the same.
[object Object]and[object Object]must be used together. For details, see .The element values in the
[object Object],[object Object],[object Object], and[object Object]tensor output of[object Object]may vary depending on the product model, communication algorithm, or version. Pass the tensors directly to the corresponding parameters of[object Object]. Other service logics of the model should not depend on the element values.The values of
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object], and[object Object]used during API calling must be the same for all ranks, at all network layers, and the same as those of[object Object].[object Object]Atlas A3 training products/Atlas A3 inference products[object Object]: In this scenario, a single rank contains dual dies. Therefore, "this rank" in the parameter description indicates a single die.
The shape format is described as follows:
- A: Maximum number of tokens to be distributed by the current rank. The value range is as follows:
- For shared experts, the following condition must be met: A = BS epWorldSize sharedExpertNum / sharedExpertRankNum.
- For MoE experts, when globalBS is 0, the following condition must be met: A >= BS epWorldSize min(localExpertNum, K). When globalBS is not 0, the following condition must be met: A >= globalBS * min(localExpertNum, K).
- H: Hidden layer size.
- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: The value depends on
[object Object].[object Object]must be in the range (0, 7168] and be an integer multiple of 32. If[object Object]is used and the driver version is 25.0.RC1.1 or later, the value must be in the range (0, 10*1024] and be an integer multiple of 32. - [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]: The value range is [1024, 8192].
- Ascend 950PR/Ascend 950DT: The value is within the range of [1024, 8192].
- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: The value depends on
- Bs: Batch sequence size, that is, the number of tokens output by the current rank.
- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: The value is determined by the value of commAlg. If commAlg is set to "fullmesh", the value is within the range of (0, 256]. If commAlg is set to "hierarchy" and the driver version is 25.0.RC1.1 or later, the value is within the range of (0, 512].
- [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]: The value range is (0 < BS ≤ 512).
- Ascend 950PR/Ascend 950DT: The value is within the range of (0 < BS ≤ 512).
- K: Number of top K experts, which must be in the ranges 0 < K ≤ 16 and 0 < K ≤ moeExpertNum.
- serverNum: Number of server nodes. The value can only be 2, 4, or 8.
- localExpertNum: Number of experts on the current rank.
- For shared expert ranks, localExpertNum = 1.
- For MoE expert ranks, localExpertNum = moeExpertNum/(epWorldSize - sharedExpertRankNum). If localExpertNum > 1, TP domain communication is not supported.
- A: Maximum number of tokens to be distributed by the current rank. The value range is as follows:
HCCL_BUFFSIZE:
Before calling this API, check whether the value of the
[object Object]environment variable is proper. This environment variable indicates the buffer size occupied by a single communication domain, in MB. If this environment variable is not set, the default value 200 MB is used.- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
- If
[object Object]is set to[object Object]or[object Object], select[object Object]or[object Object]formula based on the HCCL environment variable. - If commAlg is "fullmesh", the size must be greater than or equal to 2 x (BS x epWorldSize x min(localExpertNum, K) x H x sizeof(uint16) + 2 MB).
- If commAlg is "hierarchy", the size must be greater than or equal to (≥ (moeExpertNum + epWorldSize / 4) * Align512(maxBS * (H * 2 + 16 * Align8(K))) * 1B + 8MB, where Align8(x) = ((x + 8 - 1) / 8) x 8 and Align512(x) = ((x + 512 - 1) / 512) x 512.
- If
- [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]:
- Within an EP communication domain: The value must be greater than or equal to 2 and satisfy (≥ 2 (localExpertNum maxBS epWorldSize Align512(Align32(2 H) + 44) + (K + sharedExpertNum) maxBS Align512(2 H))) (localExpertNum indicates the number of experts assigned to the current rank when using MoE; Align512(x) = ((x + 512 - 1) / 512) 512; Align32(x) = ((x + 32 - 1) / 32) 32).
- Within the TP communication domain: The value must be grater than or equal to
[object Object].
- Ascend 950PR/Ascend 950DT: The value must be greater than or equal to aivNum x 512 + 2 x epWorldSize x BS x H x 2 x localExpertNum, where aivNum indicates the number of cores, and localExpertNum indicates the number of experts on the MoE expert card.
- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
HCCL_INTRA_PCIE_ENABLE and HCCL_INTRA_ROCE_ENABLE: [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: This environment variable is not recommended. You are advised to set
[object Object]to[object Object].In the formulas in this document,
[object Object]denotes integer division.Constraints on the use of communication domains:
[object Object]and[object Object]in a model support only the same EP communication domain, and no other operators are allowed in the communication domain.[object Object]and[object Object]in a model support only the same TP communication domain or both do not support a TP communication domain. If a TP communication domain is supported, no other operators are allowed in the communication domain.- [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]: Nodes in a communication domain must be in the same SuperPoD. Cross-SuperPoD nodes are not supported.
Networking constraints:
- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]: In multi-server scenarios, only switch-based networking is supported, and direct point-to-point networking between two servers is not supported.
Preparing files:
About rankTable:
You can configure the NPU resource information involved in collective communication through the ranktable file. For details, see "Communication Function Development > Cluster Information Configuration > Configuring Resource Information Through the ranktable File" in .
Run the
[object Object]or[object Object]command to query the device IP address. Then, set the JSON file following instructions in the collective communication guide.
[object Object]
Environment variable settings:
[object Object]Set the number of servers:
In 2-server 16-rank scenarios, set MACHINE_NUM to 2.
[object Object]You do not need to set this variable in single-server 16-rank scenarios.
[object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
You do not need to configure the ranktable file or the environment variables RANK_TABLE_FILE and FIRST_RANK_ID.
In this example, the A2 operator can run in a single-node environment with two to eight ranks. Before running the example, set IS_TEST_A2 in the sample code to true to ensure that the A2 branch is executed. In addition, you can set EP_WORLD_SIZE_A2 to the number of ranks in the sample code and change the value of moeExpertNum in the launchOneThreadDispatchV2AndCombineV2_A2 function so that moeExpertNum can be exactly divided by EP_WORLD_SIZE_A2.
The operator compilation commands are as follows. Both the moe_distribute_dispatch_v2 and moe_distribute_combine_v2 operators need to be compiled. The two operators must be executed in pairs.
[object Object]The command for executing the sample operator is as follows:
[object Object][object Object]Atlas A3 training products/Atlas A3 inference products[object Object]:
You do not need to configure the ranktable file or the environment variables RANK_TABLE_FILE and FIRST_RANK_ID.
The following example is for reference only. For details, see .
[object Object]Atlas A2 training products/Atlas A2 inference products[object Object], [object Object]Atlas A3 training products/Atlas A3 inference products[object Object], and Ascend 950PR/Ascend 950DT:
[object Object]