[object Object]

[object Object][object Object]undefined
[object Object]
  • The interface function: The LayerNorm operator is a common normalization operation used in large models. The AddLayerNormQuant operator is used to fuse the Add operator before LayerNorm and the LayerNorm normalization output into one or two downstream quantization operators, reducing the data transfer operations. The downstream quantization operators of LayerNorm can be Quantize, AscendQuantV2, or DynamicQuant. The specific quantization operator type is determined by the attr input parameters divMode and quantMode. When there are two downstream quantization operators, the operator types, input and output dtype combinations, and optional input combinations of the two operators must be the same.
  • Formulas:x=x1+x2+biasOptionalx = x1 + x2 + biasOptional y=xE(x)Var(x)+epsilongamma+betay = {{x-E(x)}\over\sqrt {Var(x)+epsilon}} * gamma + beta
    • When quantMode is set to "static", the outputs outScales1Out and outScales2Out are meaningless. Depending on the input of divMode, the fused quantization operator may be Quantize or AscendQuantV2.

      • When divMode is set to true, the fused quantization operator is Quantize. The calculation formula is as follows:

        y1Out=round(y/scales1Optional+zeroPoints1Optional)y1Out = round(y / scales1Optional + zeroPoints1Optional) y2Out=round(y/scales2Optional+zeroPoints2Optional),if scales2Optional is presenty2Out = round(y / scales2Optional + zeroPoints2Optional), \quad \text{if scales2Optional is present}
      • When divMode is set to false, the fused quantization operator is AscendQuantV2. The calculation formula is as follows:

        y1Out=round(yscales1Optional+zeroPoints1Optional)y1Out = round(y * scales1Optional + zeroPoints1Optional) y2Out=round(yscales2Optional+zeroPoints2Optional),if scales2Optional is presenty2Out = round(y * scales2Optional + zeroPoints2Optional), \quad \text{if scales2Optional is present}
    • When quantMode is set to "dynamic", the inputs zeroPoints1Optional and zeroPoints2Optional are meaningless. The fused quantization operator is DynamicQuant. In this case, divMode is invalid.

      • If neither scales1Optional nor scales2Optional is input, the outputs y2Out and scale2Out are meaningless and can be ignored. The calculation formula is as follows:

        outScales1Out=row_max(abs(y))/127outScales1Out = row\_max(abs(y))/127 y1Out=round(y/outScales1Out)y1Out = round(y / outScales1Out)
      • If only scales1Optional is input, the outputs y2Out and scale2Out are meaningless and can be ignored. The calculation formula is as follows:

        tmp1=yscales1Optionaltmp1 = y * scales1Optional outScales1Out=row_max(abs(tmp1))/127outScales1Out = row\_max(abs(tmp1))/127 y1Out=round(y/outScales1Out)y1Out = round(y / outScales1Out)
      • If both scales1Optional and scales2Optional are present, the outputs y2Out and scale2Out are valid. The calculation formula is as follows:

        tmp1=yscales1Optional,tmp2=yscales2Optionaltmp1 = y * scales1Optional, \quad tmp2 = y * scales2Optional outScales1Out=row_max(abs(tmp1))/127,outScales2Out=row_max(abs(tmp2))/127outScales1Out = row\_max(abs(tmp1))/127, \quad outScales2Out = row\_max(abs(tmp2))/127 y1Out=round(y/outScales1Out),y2Out=round(y/outScales2Out)y1Out = round(y / outScales1Out),\quad y2Out = round(y / outScales2Out)

        row_max indicates the maximum value of each row.

[object Object]

Each operator is divided into two APIs (../common/two_phase_api.md). You must call the [object Object] API to obtain the input parameters and the workspace size required by the computation process, and then call the [object Object] API to perform computation.

[object Object]
[object Object]
[object Object]
  • Parameters

    [object Object]
  • Returns:

    [object Object]: status code. For details, see .

    The first-phase API implements input parameter validation. The following error codes may be returned.

    [object Object]
[object Object]
  • Parameters

    [object Object]
  • Returns:

    [object Object]: status code. For details, see .

[object Object]
  • Functional dimensions:

    • The following table lists the supported combinations of optional inputs (scales1Optional, scales2Optional, zeroPoints1Optional, and zeroPoints2Optional).

      [object Object]undefined

      The values are as follows:

      • [object Object] indicates that the optional input exists and [object Object] is valid.
      • [object Object] indicates that the optional input does not exist, and [object Object] is invalid.
      • [object Object] indicates that any case is acceptable.
  • Data type support:

    • When [object Object] is "static":

      [object Object]undefined
    • When [object Object] is "dynamic":

      [object Object]undefined
  • Deterministic computation:

    • The aclnnAddLayerNormQuant is implemented in a deterministic manner by default.
[object Object]

The following example is for reference only. For details, see .

[object Object]