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

aclnnInplaceWeightQuantMatmulAllReduceAddRmsNorm

产品支持情况

[object Object]undefined

说明: 使用该接口时,请确保驱动固件包和CANN包都为配套的8.0.RC2版本或者配套的更高版本,否则将会引发报错,比如BUS ERROR等。

功能说明

  • 接口功能:完成mm + all_reduce + add + rms_norm计算。
  • 计算公式mm_out=AllReduce(x1@(x2antiquantScale+antiquantOffset)+bias)mm\_out = AllReduce(x1 @ (x2*antiquantScale + antiquantOffset) + bias) y=mm_out+residualy = mm\_out + residual normOut=yRMS(y)gamma,RMS(y)=1di=1dyi2+epsilonnormOut = \frac{y}{RMS(y)} * gamma, RMS(y) = \sqrt{\frac{1}{d} \sum_{i=1}^{d} y_{i}^{2} + epsilon}

函数原型

  • aclnnWeightQuantMatmulAllReduceAddRmsNorm和aclnnInplaceWeightQuantMatmulAllReduceAddRmsNorm实现相同的功能,使用区别如下,请根据自身实际场景选择合适的算子。

    • aclnnWeightQuantMatmulAllReduceAddRmsNorm:需新建两个输出张量normOut和张量y对象存储计算结果。
    • aclnnInplaceWeightQuantMatmulAllReduceAddRmsNorm:需新建一个输出张量normOut,原非Inplace场景中新建的输出张量y存储的结果直接存储到输入张量residual的内存中。
  • 每个算子分为,必须先调用“aclnnInplaceWeightQuantMatmulAllReduceAddRmsNormGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnInplaceWeightQuantMatmulAllReduceAddRmsNorm”接口执行计算。

[object Object]
[object Object]

aclnnInplaceWeightQuantMatmulAllReduceAddRmsNormGetWorkspaceSize

  • 参数说明:

    [object Object]
  • 返回值:

    返回aclnnStatus状态码,具体参见

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

    [object Object]

aclnnInplaceWeightQuantMatmulAllReduceAddRmsNorm

  • 参数说明:

    [object Object]
  • 返回值:

    返回aclnnStatus状态码,具体参见

约束说明

  • 确定性计算:

    • aclnnInplaceWeightQuantMatmulAllReduceAddRmsNorm默认非确定性实现,支持通过aclrtCtxSetSysParamOpt开启确定性。
  • 使用场景同融合算子aclnnWeightQuantMatmulAllReduce一致:增量场景不使能MC2,全量场景使能MC2

  • 输入x1可为二维或者三维,其shape为(b, s, k)或者(s, k)。x2必须是二维,其shape为(k, n),轴满足mm算子入参要求,k轴相等,b*s、s的范围为[1, 2147483647],k、n的范围为[1, 65535]。bias若非空,bias为一维,其shape为(n)。

  • 输入residual必须是三维,其shape为(b, s, n),当x1为二维时,residual的(b*s)等于x1的s。输入gamma必须是一维,其shape为(n)。

  • antiquantScale满足pertensor场景shape为(1),perchannel场景shape为(1,n)/(n),pergroup场景shape为(ceil(k,antiquantGroupSize),n)。antiquantOffset若非空,shape与antiquantScale一致。

  • 输出y和normOut的维度和数据类型同residual。bias若非空,shape大小与normOut最后一维相等。

  • x2的数据类型需为int8或者int4,x1、bias、residual、gamma、y、normOut计算输入的数据类型要一致。

  • 只支持x2矩阵转置/不转置,x1矩阵支持不转置场景。

  • antiquantGroupSize取值满足取值范围[32, min(k-1, INT_MAX)]且为32倍数。

  • 支持1、2、4、8卡,并且仅支持hccs链路all mesh组网。

  • 支持(b*s)、n为0的空tensor,不支持k为0的空tensor。

  • [object Object]Atlas A2 训练系列产品/Atlas A2 推理系列产品[object Object]:一个模型中的通算融合MC2算子,仅支持相同通信域。

调用示例

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

[object Object]