WeightQuantBatchMatmulV2
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR/Ascend 950DT | √ |
| Atlas A3 训练系列产品/Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品/Atlas A2 推理系列产品 | √ |
| Kirin X90 处理器系列产品 | √ |
| Kirin 9030 处理器系列产品 | √ |
功能说明
-
算子功能:完成一个输入为伪量化场景的矩阵乘计算,并可以实现对于输出的量化计算。
-
计算公式:
y=x@ANTIQUANT(weight)+biasy = x @ ANTIQUANT(weight) + bias
公式中的weightweight为伪量化场景的输入,其反量化公式ANTIQUANT(weight)ANTIQUANT(weight)为
ANTIQUANT(weight)=(weight+antiquantOffset)∗antiquantScaleANTIQUANT(weight) = (weight + antiquantOffset) * antiquantScale
当需要对输出进行量化处理时,其量化公式为
y=QUANT(x@ANTIQUANT(weight)+bias)=(x@ANTIQUANT(weight)+bias)∗quantScale+quantOffset\begin{aligned} y &= QUANT(x @ ANTIQUANT(weight) + bias) \\ &= (x @ ANTIQUANT(weight) + bias) * quantScale + quantOffset \\ \end{aligned}
当不需要对输出再进行量化操作时,其计算公式为
y=x@ANTIQUANT(weight)+biasy = x @ ANTIQUANT(weight) + bias
参数说明
| 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 |
|---|---|---|---|---|
| x | 输入 | 矩阵乘运算中的左矩阵。 | FLOAT16, BF16 | ND |
| weight | 输入 | 矩阵乘运算中的右矩阵。 | INT8, INT4, INT32, FLOAT8_E4M3FN, HIFLOAT8, FLOAT4_E2M1 | ND, FRACTAL_NZ |
| antiquant_scale | 输入 | 反量化参数中的缩放因子,对应公式的antiquantScale。 | FLOAT16, BF16, UINT64, INT64, FLOAT8_E8M0 | ND |
| antiquant_offset | 输入 | 反量化参数的偏置因子,对应公式的antiquantOffset。 | FLOAT16, BF16, INT32 | ND |
| quant_scale | 输入 | 量化参数的缩放因子,对应公式的quantScale。 | FLOAT32, UINT64 | ND |
| quant_offset | 输入 | 量化参数的偏置因子,对应公式的quantOffset。 | FLOAT32 | ND |
| bias | 输入 | 矩阵乘运算后累加的偏置,对应公式中的bias。 | FLOAT16, FLOAT32, BF16 | ND |
| y | 输出 | 矩阵乘运算的计算结果。 | FLOAT16, BF16, INT8 | ND |
- Atlas A2 训练系列产品/Atlas A2 推理系列产品:
- weight只支持INT8、INT4、INT32。
- antiquant_scale只支持FLOAT16、BF16、UINT64、INT64。
- Atlas A3 训练系列产品/Atlas A3 推理系列产品:
- weight只支持INT8、INT4、INT32。
- antiquant_scale只支持FLOAT16、BF16、UINT64、INT64。
- Ascend 950PR/Ascend 950DT:quant_scale和quant_offset暂不支持。
约束说明
- 不支持空tensor。
- 支持连续tensor,非连续tensor只支持转置场景。
调用说明
| 调用方式 | 样例代码 | 说明 |
|---|---|---|
| aclnn接口 | test_aclnn_weight_quant_batch_matmul_v2 | 通过 aclnnWeightQuantBatchMatmulV2 aclnnWeightQuantBatchMatmulV3 等方式调用WeightQuantBatchMatmulV2算子。 |