- The interface function: The LayerNorm operator is a common normalization operation used in large models. The AddLayerNormQuant operator is used to fuse the Add operator before LayerNorm and the LayerNorm normalization output into one or two downstream quantization operators, reducing the data transfer operations. The downstream quantization operators of LayerNorm can be Quantize, AscendQuantV2, or DynamicQuant. The specific quantization operator type is determined by the attr input parameters divMode and quantMode. When there are two downstream quantization operators, the operator types, input and output dtype combinations, and optional input combinations of the two operators must be the same.
- Formulas:
When quantMode is set to "static", the outputs outScales1Out and outScales2Out are meaningless. Depending on the input of divMode, the fused quantization operator may be Quantize or AscendQuantV2.
When divMode is set to true, the fused quantization operator is Quantize. The calculation formula is as follows:
When divMode is set to false, the fused quantization operator is AscendQuantV2. The calculation formula is as follows:
When quantMode is set to "dynamic", the inputs zeroPoints1Optional and zeroPoints2Optional are meaningless. The fused quantization operator is DynamicQuant. In this case, divMode is invalid.
If neither scales1Optional nor scales2Optional is input, the outputs y2Out and scale2Out are meaningless and can be ignored. The calculation formula is as follows:
If only scales1Optional is input, the outputs y2Out and scale2Out are meaningless and can be ignored. The calculation formula is as follows:
If both scales1Optional and scales2Optional are present, the outputs y2Out and scale2Out are valid. The calculation formula is as follows:
row_max indicates the maximum value of each row.
Each operator is divided into two APIs (../common/two_phase_api.md). You must call the [object Object] API to obtain the input parameters and the workspace size required by the computation process, and then call the [object Object] API to perform computation.
Parameters
[object Object]Returns:
[object Object]: status code. For details, see .The first-phase API implements input parameter validation. The following error codes may be returned.
[object Object]
Functional dimensions:
The following table lists the supported combinations of optional inputs (scales1Optional, scales2Optional, zeroPoints1Optional, and zeroPoints2Optional).
[object Object]undefined
The values are as follows:
[object Object]indicates that the optional input exists and[object Object]is valid.[object Object]indicates that the optional input does not exist, and[object Object]is invalid.[object Object]indicates that any case is acceptable.
Data type support:
When
[object Object]is "static":[object Object]undefined
When
[object Object]is "dynamic":[object Object]undefined
Deterministic computation:
- The aclnnAddLayerNormQuant is implemented in a deterministic manner by default.
The following example is for reference only. For details, see .