文件最后提交记录最后更新时间
27 天前
1 个月前
7 个月前
1 个月前
1 天前
26 天前
8 个月前
27 天前
README

GeluQuant

产品支持情况

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

功能说明

  • 接口功能:将GeluV2与DynamicQuant/AscendQuantV2进行融合,对输入的数据self进行GELU激活后,对激活的结果进行量化,输出量化后的结果。

  • 计算公式:

  1. 先计算GELU计算得到geluOut

    • approximate = tanh

    geluOut=Gelu(self)=self×Φ(self)=0.5∗self∗(1+Tanh(2/π∗(self+0.044715∗self3)))geluOut=Gelu(self)=self × Φ(self)=0.5 * self * (1 + Tanh( \sqrt{2 / \pi} * (self + 0.044715 * self^{3})))

    • approximate = none

    geluOut=Gelu(self)=self×Φ(self)=0.5∗self∗[1+erf(self/2)]geluOut=Gelu(self)=self × Φ(self)=0.5 * self *[1 + erf(self/\sqrt{2})]

  2. 再对geluOut进行量化操作

  • quant_mode = static

y=round_to_dst_type(geluOut∗inputScaleOptional+inputOffsetOptional,round_mode)y = round\_to\_dst\_type(geluOut * inputScaleOptional + inputOffsetOptional, round\_mode)

  • quant_mode = dynamic

    geluOut=geluOut∗inputScaleOptionalgeluOut = geluOut * inputScaleOptional

    Max=max(abs(geluOut))Max = max(abs(geluOut))

    outScaleOptional=Max/maxValueoutScaleOptional = Max/maxValue

    y=round_to_dst_type(geluOut/outScaleOptional,round_mode)y = round\_to\_dst\_type(geluOut / outScaleOptional, round\_mode)

  • maxValue: 对应数据类型的最大值。

    DataType maxValue
    INT8 127
    FLOAT8_E4M3FN 448
    FLOAT8_E5M2 57344
    HIFLOAT8 32768

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
self 输入 公式中的输入self。 BFLOAT16、FLOAT16、FLOAT ND
inputScaleOptional 输入 公式中的输入inputScaleOptional。 BFLOAT16、FLOAT16、FLOAT ND
inputOffsetOptional 输入 公式中的输入inputOffsetOptional。 BFLOAT16、FLOAT16、FLOAT ND
approximate 属性
  • GELU激活函数的模式。
  • approximate仅支持{"none", "tanh"}。
STRING -
quantMode 属性
  • 量化的模式。
  • quantMode仅支持{"static", "dynamic"}。
STRING -
roundMode 属性
  • 数据转换的模式。
  • 支持{"rint", "round", "hybrid"}模式。
STRING -
dstType 属性
  • 数据转换后y的类型。
  • 输入范围为{2, 34, 35, 36}。
INT64_T -
y 输出 公式中的输出y。 FLOAT8_E4M3FN、FLOAT8_E5M2、HIFLOAT8、INT8 ND
outScaleOptional 输出 公式中的outScaleOptional。 FLOAT ND
  • Atlas Kirin X90 处理器系列产品、Atlas Kirin 9030 处理器系列产品:self、inputScaleOptional和inputOffsetOptional的数据类型不支持BFLOAT16。y不支持FLOAT8_E4M3FN、FLOAT8_E5M2、HIFLOAT8。

约束说明

inputScaleOptional的数据类型与self的类型一致,或者在类型不一致时采用精度更高的类型。

调用说明

调用方式 调用样例 说明
aclnn调用 test_aclnn_gelu_quant 通过aclnnGeluQuant接口方式调用GeluQuant算子。
图模式调用 test_geir_gelu_quant 通过算子IR构图方式调用GeluQuant算子。