文件最后提交记录最后更新时间
7 天前
19 小时前
19 小时前
8 小时前
19 小时前
8 小时前
19 小时前
7 天前
8 小时前
README.md

GroupedQuantMax

产品支持情况

产品 是否支持
Ascend 950PR/Ascend 950DT
Atlas A3 训练系列产品/Atlas A3 推理系列产品 ×
Atlas A2 训练系列产品/Atlas A2 推理系列产品 ×
Atlas 200I/500 A2 推理产品 ×
Atlas 推理系列产品 ×
Atlas 训练系列产品 ×

功能说明

  • 算子功能:根据输入的scale对输入x进行分组量化,并分组计算输入x的绝对值的最大值amax。

  • 计算公式:

    group_listgroup\_list 沿 dim-0 将 xx 切分为 num_groups 组,group_list[g]group\_list[g] 为前 g+1g+1 组在 dim-0 上的累计大小(单调递增,group_list[−1]=x.shape[0]group\_list[-1]=x.shape[0])。对每个group(g = 0, 1, ..., num_groups - 1):

    x_g=x[group_list[g−1]:group_list[g],...]x\_g = x[group\_list[g-1] : group\_list[g], ...]

    y=Cast(x_g×scale[g],dst_type,round_mode)y = \text{Cast}(x\_g \times scale[g], \text{dst\_type}, \text{round\_mode})

    amax[g]=max⁡(∣x_g∣)amax[g] = \max(|x\_g|)

    其中,xx 表示输入张量,x_gx\_g 表示输入张量的第g组数据,g=0 时下界为0;scalescale 表示量化缩放因子,amax[g]amax[g] 为输入张量对应group组绝对值的最大值,dst_type\text{dst\_type}指定输出类型,round_mode\text{round\_mode}指定舍入模式。

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
x 输入 待量化的输入张量,对应公式中的x。支持2-8维任意shape。 FLOAT、FLOAT16、BFLOAT16 ND
scale 输入 量化缩放因子,对应公式中的scale。shape固定为[num_groups]。 FLOAT ND
group_list 输入 表示输入x在0轴上每个group的偏移(cumsum模式),对应公式中group_list。shape固定为[num_groups]。 INT64 ND
y 输出 量化后的输出张量,对应公式中的y。shape与x相同,数据类型由dst_type决定。 HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3 ND
amax 输出 x绝对值的最大值,对应公式中的amax。shape固定为[num_groups],数据类型与x一致。 FLOAT、FLOAT16、BFLOAT16 ND
round_mode 属性 取值需为Cast API支持的有效舍入模式。 string -
dst_type 属性 指定输出量化数据类型。34=HIFLOAT8,35=FLOAT8_E5M2,36=FLOAT8_E4M3。 int -

约束说明

  • round_modedst_type的匹配关系:
    • dst_type3536时,round_mode必须为"rint"
    • dst_type34时,round_mode必须为"round""hybrid"
  • num_groups的范围目前仅支持1-384。

调用说明

调用方式 调用样例 说明
aclnn调用 test_aclnn_grouped_quant_max 通过aclnnGroupedQuantMax接口方式调用GroupedQuantMax算子。
图模式调用 - 通过算子IR构图方式调用GroupedQuantMax算子。