AllToAllVOperation
Description
Sends data (the data volume can be customized) to all communication cards in the communicator and receives data from all communication cards.
Operator Context
Input the quantized tensor X of int8 and send it to each node through AlltoAll. (In this example, int8 is used for communication, which improves the communication speed.)
Then, the sum operation of reduce is used to sum up x, the int8 data is dequantized to the float16 data, and AllGather is used for communication to transmit the calculation result to each node.
Operator Function Implementation
Sends data to all communication cards in the communicator (the data volume can be customized using parameters) and receives data from all communication cards (the data volume can be customized using parameters). Currently, only the
- Example
Figure 2 Operator input and output example
- Python calculation process
golden_result = [] for j in range(rankSize): tensor_list = intensors[j].reshape(-1).tolist() # intensors[j] stands for intesor on the jth card. golden_result += tensor_list[sdispls[rank]:sdispls[rank]+sendCounts[rank]] size = sum(recvCounts) golden_out_tensor = torch.tensor(golden_result).reshape(1,size)
Application Scenarios
Send data to each node in many-to-many mode. It is an extension of AllGather, but different nodes collect different data from a node.
Applies to model parallelism, matrix transposition in model parallelism, and matrix transposition from data parallelism to model parallelism.
Definition
struct AllToAllVParam {
int rank = 0;
int rankSize = 0;
int rankRoot = 0;
std::vector<int64_t> sendCounts;
std::vector<int64_t> sdispls;
std::vector<int64_t> recvCounts;
std::vector<int64_t> rdispls;
std::string backend = "hccl";
HcclComm hcclComm = nullptr;
CommMode commMode = COMM_MULTI_PROCESS;
std::string rankTableFile;
std::string commDomain;
uint8_t rsv[64] = {0};
};
Parameters
|
Member |
Type |
Default Value |
Description |
|---|---|---|---|
|
rank |
int |
0 |
Communication ID of the current card |
|
rankSize |
int |
0 |
Number of communication cards |
|
rankRoot |
int |
0 |
Primary communication rank |
|
sendCounts |
std::vector< int64_t > |
[] |
Array of the sent data volume. For example, if the data type is float32, sendCounts[i] = n indicates that the current rank sends n float32 data segments to rank i. |
|
sdispls |
std::vector< int64_t > |
[] |
Array of sending offsets. sdispls[i] = n indicates that the rank sends data to the rank i from a position whose offset relative to the input start position is n. |
|
recvCounts |
std::vector< int64_t > |
[] |
Array of the received data volume. For example, if the data type is float32, recvCounts[i] = n indicates that the current rank receives n float32 data from rank i. |
|
rdispls |
std::vector< int64_t > |
[] |
Array of receive offsets. rdispls[i] = n indicates that the current rank starts to receive data of the rank i from a position whose offset relative to the output start position is n. |
|
backend |
std::string |
"hccl" |
Communication computing type. Only hccl is supported. |
|
hcclComm |
HcclComm |
nullptr |
Pointer to the HCCL communicator. By default, this parameter is left blank. The ATB is created by users. If the user wants to manage the communicator, the communicator pointer needs to be passed. The ATB uses the passed communicator pointer to execute the communication operator. |
|
commMode |
CommMode |
COMM_MULTI_PROCESS |
Communication mode. For details, see CommMode. In the scenario where hccl multi-thread is applied, a communicator can only be imported externally. |
|
rankTableFile |
std::string |
- |
Path of the configuration file for cluster information, which applies to single-node and multi-node communication scenarios. Currently, only the HCCL backend is supported. If a ranktable is configured for a single-node system, the ranktable is used to initialize the communicator. For details, see . |
|
commDomain |
std::string |
- |
Communicator name used by a communication device group when there are multiple communicators. When backend is set to lccl and commMode is multi-process, commDomain must be set to a number ranging from 0 to 63. When commMode is multi-thread, deterministic computing is not supported. In this case, LCCL_DETERMINISTIC must be set to 0 or false. In the multi-process/multi-thread multi-communicator concurrency scenario, LCCL_PARALLEL must be set to 1 or true. After the multi-communicator parallelism is used, LCCL_PARALLEL must be set to 0 or false. Otherwise, the performance in basic scenarios deteriorates. |
|
rsv[64] |
uint8_t |
{0} |
Reserved |
Input
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
x |
[–1, ..., –1] The value -1 indicates that the size of the current dimension is not restricted. The multi-dimensional input tensor is considered as a 1-dimensional tensor in the operator. |
"hccl": float16/float/int8/int16/int32/int64/bf16 |
ND |
Input tensor |
Output
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
output |
[1,sum(recvCounts)] recvCountsSum is the sum of all elements of the recvCounts parameter. |
"hccl": float16/float/int8/int16/int32/int64/bf16 The data type is the same as the input. |
ND |
Output tensor. The shape of the last dimension is the sum of all elements of the recvCounts parameter. |
Restrictions
- The length of the array parameters sendCounts, recvCounts, sdispls and rdispls is equal to the value of ranksize, and the values of all elements in the array are greater than 0.
- Currently, only the
Atlas A2 inference products is supported. - The input tensor dimensions of each communication card are the same.
- The sum of sendCounts and recvCounts array elements cannot overflow int64, and the sum of recvCounts arrays must be greater than 0. For any element in rdispls, recvCounts[i] + rdispls[i] cannot be greater than recvCountsSum (the last dimension of the output). For any element in sdispls, sendCounts[i] + sdispls[i] cannot be greater than the data volume of the input tensor. For example, if the input tensor has shape [3, 4, 5] and the data amount is 60 (3 x 4 x 5), the input tensor will be considered as a tensor with shape [60] for AllToAllV computation.
- rank, rankSize, and rankRoot must meet the following conditions:
- 0 ≤ rank < rankSize
- 0 ≤ rankRoot < rankSize
- If there are multiple users, ATB_SHARE_MEMORY_NAME_SUFFIX (see ATB Environment Variables) needs to be used to distinguish the shared memory and synchronize initialization information.
- When the communication operator of the ATB exits abnormally, run the following commands to clear the residual data to avoid affecting subsequent operations.
rm -rf /dev/shm/sem.lccl* rm -rf /dev/shm/sem.hccl* ipcrm -a