QuantBatchMatmulV4

产品支持情况

产品 是否支持
Ascend 950PR/Ascend 950DT
Atlas A3 训练系列产品/Atlas A3 推理系列产品
Atlas A2 训练系列产品/Atlas A2 推理系列产品
Kirin X90 处理器系列产品
Kirin 9030 处理器系列产品

参数说明

  • 算子功能:完成量化的矩阵乘计算。

  • 计算公式:

    • Atlas A2 训练系列产品/Atlas A2 推理系列产品、Atlas A3 训练系列产品/Atlas A3 推理系列产品:

      • x1为INT8,x2为INT32,x1Scale为FLOAT32,x2Scale为UINT64,yOffset为FLOAT32,out为FLOAT16/BFLOAT16:

        out=((x1@(x2∗x2Scale))+yoffset)∗x1Scaleout = ((x1 @ (x2*x2Scale)) + yoffset) * x1Scale

      • 无x1Scale无bias:

        out=x1@x2∗x2Scale+x2Offsetout = x1@x2 * x2Scale + x2Offset

      • bias INT32:

        out=(x1@x2+bias)∗x2Scale+x2Offsetout = (x1@x2 + bias) * x2Scale + x2Offset

      • bias BFLOAT16/FLOAT32(此场景无offset):

        out=x1@x2∗x2Scale+biasout = x1@x2 * x2Scale + bias

      • x1Scale无bias:

        out=x1@x2∗x2Scale∗x1Scaleout = x1@x2 * x2Scale * x1Scale

      • x1Scale, bias INT32(此场景无offset):

        out=(x1@x2+bias)∗x2Scale∗x1Scaleout = (x1@x2 + bias) * x2Scale * x1Scale

      • x1Scale, bias BFLOAT16/FLOAT16/FLOAT32(此场景无offset):

        out=x1@x2∗scale∗x1Scale+biasout = x1@x2 * scale * x1Scale + bias

      • x1,x2为INT8,x1Scale, x2Scale为FLOAT32,bias为FLOAT32,out为FLOAT16/BFLOAT16 (pertoken-pergroup量化):

        out=(x1@x2)∗x1Scale∗x2Scale+biasout = (x1 @ x2) * x1Scale * x2Scale + bias

      • x1,x2为INT4,x1Scale, x2Scale为FLOAT32,x2Offset为FLOAT16, out为FLOAT16/BFLOAT16 (pertoken-pergroup非对称量化):

        out=x1Scale∗x2Scale@(x1@x2−x1@x2Offset)out = x1Scale * x2Scale @ (x1 @ x2 - x1 @ x2Offset)

    • Ascend 950PR/Ascend 950DT:

      • x1,x2为FLOAT8_E4M3FN/FLOAT8_E5M2/HIFLOAT8,无x1Scale,x2Scale为INT64/UINT64,无x2Offset,可选参数bias的dtype为FLOAT32,out为FLOAT8_E4M3FN/HIFLOAT8/FLOAT16/BFLOAT16/FLOAT32:

        out=(x1@x2+bias)∗x2Scaleout = (x1@x2 + bias) * x2Scale

      • mx量化模式中, x1,x2为FLOAT4_E2M1/FLOAT4_E1M2/FLOAT8_E4M3FN/FLOAT8_E5M2,x1Scale为FLOAT8_E8M0,x2Scale为FLOAT8_E8M0,无x2Offset,可选参数bias的dtype为FLOAT32:

        out=(x1∗x1Scale)@(x2∗x2Scale)+biasout = (x1* x1Scale)@(x2* x2Scale) + bias

      • x1,x2为FLOAT8_E4M3FN/FLOAT8_E5M2/HIFLOAT8,x1Scale为FLOAT32,x2Scale为FLOAT32,无x2Offset,可选参数bias的dtype为FLOAT32:

        out=(x1@x2+bias)∗x2Scale∗x1Scaleout = (x1@x2 + bias) * x2Scale * x1Scale

      • 在G-B && B-B量化模式中, x1,x2为FLOAT8_E4M3FN/FLOAT8_E5M2/HIFLOAT8,x1Scale为FLOAT32,x2Scale为FLOAT32,无x2Offset,无bias,当x1为(a0, a1),x2为(b0, b1)时,x1Scale为(ceil(a0 / 128), ceil(a1 / 128))或(a0, ceil(a1 / 128)),x2Scale为(ceil(b0 / 128), ceil(b1 / 128)):

        outpq=∑0⌊kblockSize⌋(x1pr@x2rq∗(x1Scalepr∗x2Scalerq))out_{pq} = \sum_{0}^{\left \lfloor \frac{k}{blockSize} \right \rfloor} (x1_{pr}@x2_{rq}*(x1Scale_{pr}*x2Scale_{rq}))

      • x1为FLOAT8_E4M3FN,x2为FLOAT4_E2M1,x1Scale为FLOAT8_E8M0,x2Scale为FLOAT8_E8M0,无x1Offset,无x2Offset,可选参数bias的dtype为BFLOAT16,out为BFLOAT16:

        out=(x1∗x1Scale)@(x2∗x2Scale)+biasout = (x1 * x1Scale)@(x2 * x2Scale) + bias

      • x1为FLOAT8_E4M3FN,x2为FLOAT4_E2M1,无x1Scale,x2Scale为BFLOAT16,无x1Offset,无x2Offset,无bias, yScale为UINT64,out为BFLOAT16:

        out=(x1@(x2∗x2Scale))∗yScaleout = (x1@(x2 * x2Scale)) * yScale

算子规格

参数名 输入/输出/属性 描述 数据类型 数据格式
x1 输入 矩阵乘运算中的左矩阵。 FLOAT8_E5M2, FLOAT8_E4M3FN, INT4, INT8 ND
x2 输入 矩阵乘运算中的右矩阵。 FLOAT4_E1M2, FLOAT4_E2M1, INT4, INT8 ND, FRACTAL_NZ
bias 输入 矩阵乘运算后累加的偏置,对应公式中的bias。 BFLOAT16, FLOAT16, FLOAT32 ND
x1_scale 输入 矩阵乘计算时,量化参数的缩放因子,对应公式的x1Scale。 BFLOAT16, FLOAT16, FLOAT32, FLOAT8_E8M0 ND
x2_scale 输入 矩阵乘计算时,量化参数的缩放因子,对应公式的x2Scale。 BFLOAT16, FLOAT16, FLOAT32, UINT64, FLOAT8_E8M0 ND
y_scale 输入 矩阵乘运算后,量化参数的缩放因子,对应公式的yScale。 UINT64 ND
x1_offset 输入 矩阵乘计算时,量化参数的偏置因子,对应公式的x1Offset。 BFLOAT16, FLOAT16 ND
x2_offset 输入 矩阵乘计算时,量化参数的偏置因子,对应公式的x2Offset。 BFLOAT16, FLOAT16 ND
y_offset 输入 矩阵乘运算后,量化参数的偏置因子,对应公式的yOffset。 BFLOAT16, FLOAT16, FLOAT32 ND
y 输出 矩阵乘运算的计算结果。 BFLOAT16, FLOAT16 ND
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品、Atlas A3 训练系列产品/Atlas A3 推理系列产品:

    x1 x2 x1Scale x2Scale x2Offset yScale bias yOffset out
    INT8 INT32 FLOAT32 UINT64 nullptr nullptr nullptr FLOAT32 FLOAT16/BFLOAT16
    INT8 INT8 nullptr UINT64/INT64 nullptr nullptr nullptr/INT32 nullptr FLOAT16
    INT8 INT8 nullptr UINT64/INT64 nullptr/FLOAT32 nullptr nullptr/INT32 nullptr INT8
    INT8 INT8 nullptr/FLOAT32 BFLOAT16 nullptr nullptr nullptr/INT32/BFLOAT16/FLOAT32 nullptr BFLOAT16
    INT8 INT8 FLOAT32 FLOAT32 nullptr nullptr nullptr/INT32/FLOAT16/FLOAT32 nullptr FLOAT16
    INT4/INT32 INT4/INT32 nullptr UINT64/INT64 nullptr nullptr nullptr/INT32 nullptr INT32
    INT8 INT8 nullptr FLOAT32/BFLOAT16 nullptr nullptr nullptr/INT32 nullptr FLOAT16
    INT8 INT8 FLOAT32 FLOAT32 nullptr nullptr FLOAT32 nullptr BFLOAT16
    INT4/INT32 INT4/INT32 FLOAT32 FLOAT32/BFLOAT16 nullptr nullptr nullptr/INT32/BFLOAT16/FLOAT32 nullptr BFLOAT16
    INT4/INT32 INT4/INT32 FLOAT32 FLOAT32 nullptr nullptr nullptr/INT32/FLOAT16/FLOAT32 nullptr FLOAT16
    INT4 INT4 FLOAT32 FLOAT32 FLOAT16 nullptr nullptr nullptr BFLOAT16
  • Ascend 950PR/Ascend 950DT:

    x1 x2 x1Scale x2Scale x2Offset yScale bias out
    INT8 INT8 nullptr UINT64/INT64 nullptr nullptr nullptr/INT32 FLOAT16/BFLOAT16
    INT8 INT8 nullptr UINT64/INT64 nullptr/FLOAT32 nullptr nullptr/INT32 INT8
    INT8 INT8 nullptr/FLOAT32 FLOAT32/BFLOAT16 nullptr nullptr nullptr/INT32/FLOAT32/BFLOAT16 BFLOAT16
    INT8 INT8 FLOAT32 FLOAT32 nullptr nullptr nullptr/INT32/FLOAT32/FLOAT16 FLOAT16
    FLOAT8_E4M3FN/FLOAT8_E5M2 FLOAT8_E4M3FN/FLOAT8_E5M2 nullptr UINT64/INT64 nullptr nullptr nullptr/FLOAT32 FLOAT8_E4M3FN/FLOAT16/BFLOAT16/FLOAT32
    HIFLOAT8 HIFLOAT8 nullptr UINT64/INT64 nullptr nullptr nullptr/FLOAT32 HIFLOAT8/FLOAT16/BFLOAT16/FLOAT32
    FLOAT8_E4M3FN/FLOAT8_E5M2 FLOAT8_E4M3FN/FLOAT8_E5M2 FLOAT32 FLOAT32 nullptr nullptr nullptr/FLOAT32 FLOAT16/BFLOAT16/FLOAT32
    HIFLOAT8 HIFLOAT8 FLOAT32 FLOAT32 nullptr nullptr nullptr/FLOAT32 FLOAT16/BFLOAT16/FLOAT32
    FLOAT4_E2M1/FLOAT4_E1M2 FLOAT4_E2M1/FLOAT4_E1M2 FLOAT8_E8M0 FLOAT8_E8M0 nullptr nullptr nullptr/FLOAT32 FLOAT16/BFLOAT16/FLOAT32
    FLOAT8_E4M3FN/FLOAT8_E5M2 FLOAT8_E4M3FN/FLOAT8_E5M2 FLOAT8_E8M0 FLOAT8_E8M0 nullptr nullptr nullptr/FLOAT32 FLOAT16/BFLOAT16/FLOAT32
    FLOAT8_E4M3FN FLOAT4_E2M1 FLOAT8_E8M0 FLOAT8_E8M0 nullptr nullptr nullptr/BFLOAT16 BFLOAT16
    FLOAT8_E4M3FN FLOAT4_E2M1 nullptr BFLOAT16 nullptr INT64/UINT64 nullptr BFLOAT16

约束说明

  • 不支持空tensor。
  • 支持连续tensor,非连续tensor只支持转置场景。

调用说明

调用方式 样例代码 说明
aclnn接口 test_aclnn_quant_matmul_v5 通过
aclnnQuantMatmulV5
等方式调用QuantBatchMatmulV4算子。