RmsNormQuantV2
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR/Ascend 950DT | √ |
| Atlas A3 训练系列产品/Atlas A3 推理系列产品 | × |
| Atlas A2 训练系列产品/Atlas A2 推理系列产品 | × |
| Atlas 200I/500 A2 推理产品 | × |
| Atlas 推理系列产品 | × |
| Atlas 训练系列产品 | × |
功能说明
-
算子功能:RmsNorm算子是大模型常用的标准化操作,相比LayerNorm算子,其去掉了减去均值的部分。RmsNormQuantV2算子将RmsNorm算子以及RmsNorm归一化的输出给到1个或2个Quantize算子融合起来,减少搬入搬出操作。
-
计算公式:
yi=xiRms(x)gi+beta, where Rms(x)=1n∑i=1nxi2+epsy_i=\frac{x_i}{\operatorname{Rms}(\mathbf{x})} g_i + beta, \quad \text { where } \operatorname{Rms}(\mathbf{x})=\sqrt{\frac{1}{n} \sum_{i=1}^n x_i^2+eps}
-
divMode为True时:
y1=round((y/scales1)+zero_points1)y1=round((y/scales1)+zero\_points1)
y2=round((y/scales2)+zero_points2)y2=round((y/scales2)+zero\_points2)
-
divMode为False时:
y1=round((y∗scales1)+zero_points1)y1=round((y*scales1)+zero\_points1)
y2=round((y∗scales2)+zero_points2)y2=round((y*scales2)+zero\_points2)
-
参数说明
| 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 |
|---|---|---|---|---|
| x | 输入 | 表示标准化过程中的源数据张量,对应公式中的`x`。 | FLOAT32、FLOAT16、BFLOAT16 | ND |
| gamma | 输入 | 表示标准化过程中的权重张量,对应公式中的`g`。shape与x1需要norm(层归一化)的维度保持一致。 | FLOAT32、FLOAT16、BFLOAT16 | ND |
| scales1 | 输入 | 表示量化过程中得到y1的scales张量,对应公式中的`scales1`。 | FLOAT32、FLOAT16、BFLOAT16 | ND |
| scales2 | 可选输入 | 表示量化过程中得到y2的scales张量,对应公式中的`scales2`。 | FLOAT32、FLOAT16、BFLOAT16 | ND |
| zero_points1 | 可选输入 | 表示量化过程中得到y1的offset张量,对应公式中的`zero_points1`。 | FLOAT32、FLOAT16、BFLOAT16、INT32、INT8 | ND |
| zero_points2 | 可选输入 | 表示量化过程中得到y2的offset张量,对应公式中的`zero_points2`。 | FLOAT32、FLOAT16、BFLOAT16、INT32、INT8 | ND |
| beta | 可选输入 | 表示标准化过程中的偏置项,公式中的`beta`。 | FLOAT32、FLOAT16、BFLOAT16 | ND |
| epsilon | 可选属性 |
|
FLOAT32 | - |
| div_mode | 可选属性 |
|
BOOL | - |
| y1 | 输出 | 表示量化输出Tensor,对应公式中的`y1`。 | INT8、INT4、FLOAT8、HIF8 | ND |
| y2 | 输出 | 表示量化输出Tensor,对应公式中的`y2`。 | INT8、INT4、FLOAT8、HIF8 | ND |
约束说明
- Ascend 950PR/Ascend 950DT:
- 当
x的数据类型为FLOAT32时,scales1、scales2和zero_points1、zero_points2的数据类型只能为FLOAT32;当x的数据类型为FLOAT16或者BFLOAT16,并且scales1、scales2的数据类型为FLOAT32时,zero_points1、zero_points2的数据类型只能是FLOAT32或者INT32,否则scales1、scales2的数据类型需要与x的数据类型保持一致同为FLOAT16或者BFLOAT16,zero_points1、zero_points2的数据类型也需要与x的数据类型保持一致或者为INT8。 - 当
y的数据类型为INT4时,x、gamma以及beta的最后一维必须为偶数。 zero_points2必须在scales2存在的情况下,才能作为可选输入。
- 当
调用说明
| 调用方式 | 样例代码 | 说明 |
|---|---|---|
| aclnn接口 | test_aclnn_rms_norm_quant | 通过aclnnRmsNormQuant接口方式调用RmsNormQuantV2算子。 |
| 图模式 | - | 通过算子IR构图方式调用RmsNormQuantV2算子。 |