昇腾社区首页
中文
注册
开发者
下载

aclnnDynamicQuantV2

产品支持情况

[object Object]undefined

功能说明

  • 接口功能:为输入张量进行per-token对称/非对称动态量化。在MOE场景下,每个专家的smoothScalesOptional是不同的,根据输入的groupIndexOptional进行区分。

  • 计算公式:

    • 对称量化:

      • 若不输入smoothScalesOptional,则

        scaleOut=row_max(abs(x))/127scaleOut=row\_max(abs(x))/127 yOut=round(x/scaleOut)yOut=round(x/scaleOut)
      • 若输入smoothScalesOptional,则

        input=xsmoothScalesOptionalinput = x\cdot smoothScalesOptional scaleOut=row_max(abs(input))/127scaleOut=row\_max(abs(input))/127 yOut=round(input/scaleOut)yOut=round(input/scaleOut)
    • 非对称量化:

      • 若不输入smoothScalesOptional,则

        scaleOut=(row_max(x)row_min(x))/scale_optscaleOut=(row\_max(x) - row\_min(x))/scale\_opt offset=offset_optrow_max(x)/scaleOutoffset=offset\_opt-row\_max(x)/scaleOut yOut=round(x/scaleOut+offset)yOut=round(x/scaleOut+offset)
      • 若输入smoothScalesOptional,则

        input=xsmoothScalesOptionalinput = x\cdot smoothScalesOptional scaleOut=(row_max(input)row_min(input))/scale_optscaleOut=(row\_max(input) - row\_min(input))/scale\_opt offset=offset_optrow_max(input)/scaleOutoffset=offset\_opt-row\_max(input)/scaleOut yOut=round(input/scaleOut+offset)yOut=round(input/scaleOut+offset)

    其中row_max代表每行求最大值,row_min代表每行求最小值。当输出yOut类型为INT8时,scale_opt为255.0,offset_opt为127.0;yOut类型为INT4时,scale_opt为15.0,offset_opt为7.0。

函数原型

每个算子分为,必须先调用“aclnnDynamicQuantV2GetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnDynamicQuantV2”接口执行计算。

[object Object]
[object Object]

aclnnDynamicQuantGetWorkspaceSize

  • 参数说明:

    [object Object]
    • [object Object]Atlas 推理系列产品[object Object]、[object Object]Atlas 训练系列产品[object Object]:
      • 入参[object Object]仅支持FLOAT16。
      • 入参[object Object][object Object]只支持为nullptr。
      • 入参[object Object]只支持配置为2。
      • 出参[object Object]只支持INT8。
  • 返回值:

    aclnnStatus:返回状态码,具体参见

    第一段接口完成入参校验,出现以下场景时报错:

    [object Object]

aclnnDynamicQuantV2

  • 参数说明:

    [object Object]
  • 返回值:

    aclnnStatus:返回状态码,具体参见

约束说明

  • [object Object]的数据类型为INT4时,需满足[object Object][object Object]的最后一维能被2整除。
  • [object Object]的数据类型为INT32时,需满足[object Object]的最后一维能被8整除。
  • [object Object]Atlas 推理系列产品[object Object]:尾轴只支持32位对齐的数据,暂时只支持对称量化,不支持BFLOAT16数据类型。
  • 确定性计算:
    • aclnnDynamicQuantV2默认确定性实现。

调用示例

示例代码如下,仅供参考,具体编译和执行过程请参考

[object Object]