| Files | Last commit | Last update |
|---|---|---|
| 9 days ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 19 days ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 4 months ago | ||
| 4 days ago | ||
| 4 days ago |
QuantAllReduce
English | 简体中文
Product Support Status
| Product | Supported |
|---|---|
| Ascend 950DT products | √ |
| Atlas A3 products | × |
| Atlas A2 products | × |
| Atlas 200I/500 A2 inference products | × |
| Atlas inference products | × |
| Atlas training products | × |
NOTE: When using this interface, ensure that both the driver firmware package and the CANN package are of the matched 9.2.0 version or a later matched version. Otherwise, errors such as BUS ERROR will occur.
Function Description
-
Operator function: The QuantAllReduce operator fuses the AllReduce communication of low-bit quantized data with the dequantization computation. After the quantized data and scale factors of all ranks are distributed within the communication domain through a one-step AllGather, the data are dequantized element-wise and reduced (summed) across ranks during the communication read, and every rank obtains the full communication result with the same shape as the input, achieving overlapping of communication and computation.
-
Computation formulas:
-
Inputs:
- Xr∈RBS×H\mathbf{X}_r \in \mathbb{R}^{\text{BS} \times \text{H}}: the quantized input data of rank rr, corresponding to the input
x. BS\text{BS} is the number of tokens (whenxis 3-dimensional, the axes are merged as BS=b×s\text{BS}=\text{b}\times\text{s}), and H\text{H} is the hidden dimension. - Sr\mathbf{S}_r: the quantization scale factors of rank rr, corresponding to the input
scales. The shape depends on the quantization mode; see the parameter description for details.
- Xr∈RBS×H\mathbf{X}_r \in \mathbb{R}^{\text{BS} \times \text{H}}: the quantized input data of rank rr, corresponding to the input
-
Outputs:
- Y∈RBS×H\mathbf{Y} \in \mathbb{R}^{\text{BS} \times \text{H}}: the final output of every rank, corresponding to the output
output, with the same shape as the inputx.
- Y∈RBS×H\mathbf{Y} \in \mathbb{R}^{\text{BS} \times \text{H}}: the final output of every rank, corresponding to the output
-
Conventions:
- RR denotes the total number of ranks in the communication domain, corresponding to the input
world_size, and r∈{0,1,…,R−1}r \in \{0, 1, \dots, R-1\}. - ⊙⊙ denotes element-wise multiplication; the scale factors are broadcast along the H\text{H} axis per quantization group.
- ⌊z⌋\lfloor z \rfloor denotes the floor of zz.
- DQ(⋅)\mathrm{DQ}(\cdot) denotes the element-wise dequantization operation performed according to the quantization mode.
- RR denotes the total number of ranks in the communication domain, corresponding to the input
-
Overall computation:
Y=∑q=0R−1DQ(Xq⊙Sq)\mathbf{Y} = \sum_{q=0}^{R-1} \mathrm{DQ}\left(\mathbf{X}_q \odot \mathbf{S}_q\right)
That is, the quantized data and scale factors of all ranks are first distributed by AllGather (AllGatherData=AllGather(x)\text{AllGatherData}=\text{AllGather}(\mathbf{x}) and AllGatherScales=AllGather(scales)\text{AllGatherScales}=\text{AllGather}(\text{scales})), then dequantized element-wise and summed across ranks, and every rank obtains the complete result Y\mathbf{Y}.
reduce_oponly supports "sum" currently.
-
-
Computation process
The current version adopts the MTE one-step AllGather (one-shot) implementation: each rank writes its complete data into its local communication window at a time, and the other ranks read directly from each peer window, with communication and dequantization-reduction computation pipelined per data block. The input types and dequantization group granularity of each quantization scenario are as follows:
Quantization mode x scales Group granularity Output pertoken-pergroup (KG) quantization INT8, HIFLOAT8, FLOAT8_E4M3FN, FLOAT8_E5M2 FLOAT32 One scale shared by every 128 consecutive elements of each token BFLOAT16, FLOAT16, FLOAT32 MX quantization FLOAT8_E4M3FN, FLOAT8_E5M2 FLOAT8_E8M0 One scale shared by every 32 consecutive elements BFLOAT16, FLOAT16, FLOAT32 pertoken-pergroup (KG) quantization scenario
-
Data distribution (one-step AllGather communication)
Each rank rr writes its complete Xr\mathbf{X}_r and Sr\mathbf{S}_r into the data region of its local communication window (Win region) at a time, and writes the synchronization flag into the status region; the other ranks in the communication domain read the window data directly through UB-Memory without intermediate aggregation, so the AllGather is completed in one step.
-
Dequantization and reduce summation
This rank reads data blocks from the Win region of each rank qq. Type conversion is performed first: INT8 is converted to FLOAT32 via FLOAT16, and HIFLOAT8, FLOAT8_E4M3FN and FLOAT8_E5M2 are converted to FLOAT32 directly; the scale factors are FLOAT32 and are broadcast once per 128 consecutive elements to obtain the element-wise scale view. Then the data are dequantized element-wise and accumulated across ranks:
Dq[i,j]=Xq[i,j]⋅Sq[i,⌊j/128⌋]\mathbf{D}_q[i,j] = \mathbf{X}_q[i,j] \cdot \mathbf{S}_q\left[i, \left\lfloor j / 128 \right\rfloor\right]
Y[i,j]=∑q=0R−1Dq[i,j]\mathbf{Y}[i,j] = \sum_{q=0}^{R-1} \mathbf{D}_q[i,j]
The accumulation is performed in FLOAT32, and finally the result is rounded according to
output_dtype; every rank obtains the complete result with the same shape asx.
MX quantization scenario
-
Data distribution (one-step AllGather communication)
Same as the KG scenario: each rank writes its Xr\mathbf{X}_r (FLOAT8_E4M3FN or FLOAT8_E5M2) and Sr\mathbf{S}_r (FLOAT8_E8M0) into its local Win region at a time and synchronizes the status flags, and the other ranks read the data directly.
-
Dequantization and reduce summation
This rank reads data blocks from the Win region of each rank qq. The shape of Sr\mathbf{S}_r is (BS,H/64,2)(\text{BS}, \text{H}/64, 2) (or (b,s,H/64,2)(\text{b}, \text{s}, \text{H}/64, 2) when
xis 3-dimensional), containing BS×H/32\text{BS} \times \text{H}/32 scale factors in total, that is, one FLOAT8_E8M0 scale is shared by every 32 consecutive elements. The scale factors are first converted to FLOAT32 via BFLOAT16, and then broadcast per 32 elements to obtain the element-wise scale view:Dq[i,j]=Xq[i,j]⋅S~q[i,⌊j/32⌋]\mathbf{D}_q[i,j] = \mathbf{X}_q[i,j] \cdot \widetilde{\mathbf{S}}_q\left[i, \left\lfloor j / 32 \right\rfloor\right]
where S~q\widetilde{\mathbf{S}}_q denotes the per-group scale factors obtained by expanding the packed layout above row by row. Then, same as the KG scenario, the results are accumulated across ranks in FLOAT32, rounded according to
output_dtype, and the full result is written out.
-
Parameter Description
| Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format |
|---|---|---|---|---|
| context | Input | MTE communication context data of this rank, containing the address table of the communication domain and the communication window information. The aclnn interface passes this tensor directly; the PyTorch interface builds it automatically from the hcom communication domain name, and users do not need to prepare it explicitly. |
INT32 | ND |
| x | Input | The quantized data of this rank to be communicated. The shape supports 2 dimensions (bs, h) and 3 dimensions (b, s, h); h is 128-aligned and within the range [1024, 8192]. This parameter does not support empty tensors. For the data types supported in each quantization scenario, see the constraints. | INT8, HIFLOAT8, FLOAT8_E4M3FN, FLOAT8_E5M2 | ND |
| scales | Input | The quantization scale factors of the communicated data. In the pertoken-pergroup (KG) quantization mode, the data type is FLOAT32 and the number of dimensions is the same as x: when x is 2-dimensional, the shape is (bs, h/128); when x is 3-dimensional, the shape is (b, s, h/128). In the MX quantization mode, the data type is FLOAT8_E8M0: when x is 2-dimensional, the shape is (bs, h/64, 2); when x is 3-dimensional, the shape is (b, s, h/64, 2). This parameter does not support empty tensors. | FLOAT32, FLOAT8_E8M0 | ND |
| world_size | Attribute | The total number of ranks in the communication domain. 2, 4 and 8 are supported. | INT64 | |
| hccl_buffer_size | Attribute | The size of the communication buffer occupied by a single communication domain, in MB. The PyTorch interface obtains and passes it automatically according to the communication domain configuration; when calling the aclnn interface directly, it must satisfy the HCCL_BUFFSIZE requirement in the constraints. | INT64 | |
| reduce_op | Optional attribute | The type of the reduce operation. Default value: "sum". Only "sum" is supported in the current version. | STRING | |
| output_dtype | Optional attribute | Specifies the data type of the output parameter. Current values: bfloat16, float16, float32. Default value: bfloat16. | INT64 | |
| output | Output | The final communication result, with the same shape as the input x: when x is 2-dimensional (bs, h), output is (bs, h); when x is 3-dimensional (b, s, h), output is (b, s, h). The data type is specified by output_dtype, defaulting to bfloat16. | BFLOAT16, FLOAT16, FLOAT32 | ND |
NOTE: The PyTorch interface also provides the optional parameters x_dtype and scales_dtype, which are used to annotate the real data types carried by uint8 tensors for custom data types (such as HIFLOAT8 and FLOAT8_E8M0); the hcom parameter is the communication domain handle name, obtained through the get_hccl_comm_name interface.
Constraints
-
Usage scenario constraints:
- This interface supports training scenarios, currently only Ascend 950DT products are supported.
-
Communication engine constraints:
- Ascend 950DT products: only UB-Memory communication is supported.
-
Communication domain constraints:
- The communication domain size supports 2, 4 and 8.
- Within the same communication domain, only the
aclnnQuantAllReduceandaclnnQuantReduceScatteroperators are allowed to be executed consecutively, and no other communication operators are allowed in this communication domain. HCCL_BUFFSIZE: Before calling this operator, check whether the value of theHCCL_BUFFSIZEenvironment variable is reasonable. This environment variable indicates the memory size occupied by a single communication domain, in MB, defaulting to 200 MB when not configured. It is required thatHCCL_BUFFSIZE>= 2 * CeilDiv(xDataSize+scalesDataSize+reserveSize, 1024 * 1024), where CeilDiv is the ceiling division and the right-hand side is expressed in MB. All terms are calculated in bytes:xDataSizeis the data size of the inputx,xDataSize = BS * H * 1 (Byte);scalesDataSizeis the data size ofscales,BS * H / 128 * 4 (Byte)for pertoken-pergroup quantization andBS * H / 32 * 1 (Byte)for MX quantization;reserveSize = 1 * 1024 * 1024 (Byte)is reserved for the status region.
-
Parameter constraints:
- The BS axis of
x(the merged B*S axes for 3-dimensional input) must be divisible byworld_size. - The h axis of
xonly supports the range [1024, 8192] and must be 128-aligned. - Neither
xnorscalessupports empty tensors. - The shape of
outputis exactly the same as that ofx(2-dimensional or 3-dimensional). - The data format of
x,scalesandoutputonly supports ND.
- The BS axis of
-
Data type constraints:
Scenario x scales output pertoken-pergroup quantization hifloat8, int8, float8_e4m3fn, float8_e5m2 float32 float16, bfloat16, float32 MX quantization float8_e4m3fn, float8_e5m2 float8_e8m0 float16, bfloat16, float32 -
Shape constraints:
Scenario x scales pertoken-pergroup quantization 2-dimensional tensor, shape (bs, h) 2-dimensional tensor, shape (bs, h/128) pertoken-pergroup quantization 3-dimensional tensor, shape (b, s, h) 3-dimensional tensor, shape (b, s, h/128) MX quantization 2-dimensional tensor, shape (bs, h) 3-dimensional tensor, shape (bs, h/64, 2) MX quantization 3-dimensional tensor, shape (b, s, h) 4-dimensional tensor, shape (b, s, h/64, 2) -
Deterministic computation:
- Deterministic computation is supported by default.
-
Reserved and non-public parameters:
- Some parameters and data types in the parameter table are not yet publicly available and are reserved or used for internal implementation. The introduction to the interface parameters and their constraints are described in detail in the interface document quant_all_reduce Operator Interface Document.
Invocation Description
| Invocation Method | Sample Code | Description |
|---|---|---|
| PyTorch interface invocation | - | Invoke the quant_all_reduce operator through the quant_all_reduce PyTorch interface. Both single-operator mode and torchair graph mode are supported. |