开发者
资源
[object Object][object Object][object Object]undefined
[object Object]
  • 接口功能:将GeluV2与DynamicQuant/AscendQuantV2进行融合,对输入的数据self进行Gelu激活后,对激活的结果进行量化,输出量化后的结果。

  • 计算公式:

  1. 先计算gelu计算得到geluOut
  • approximate = tanh
geluOut=Gelu(self)=self×Φ(self)=0.5self(1+Tanh(2/π(self+0.044715self3)))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.5self[1+erf(self/2)]geluOut=Gelu(self)=self × Φ(self)=0.5 * self *[1 + erf(self/\sqrt{2})]
  1. 再对geluOut进行量化操作
  • quant_mode = static
y=round_to_dst_type(geluOutinputScaleOptional+inputOffsetOptional,round_mode)y = round\_to\_dst\_type(geluOut * inputScaleOptional + inputOffsetOptional, round\_mode)
  • quant_mode = dynamic

    geluOut=geluOutinputScaleOptionalgeluOut = 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: 对应数据类型的最大值。

    [object Object]undefined
[object Object]

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

[object Object]
[object Object]
[object Object]
  • 参数说明:

    [object Object]
  • 返回值:

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

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

[object Object][object Object]
  • 参数说明:

    [object Object]
  • 返回值:

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

[object Object]
  • 确定性计算:

    • aclnnGeluQuant默认确定性实现。
  • inputScaleOptional的数据类型与self的类型一致,或者在类型不一致时采用精度更高的类型。

[object Object]

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

[object Object]