开发者
资源
[object Object][object Object][object Object]undefined
[object Object]
  • 接口功能:将两次FlashAttention的输出根据其不同的softmax的max和sum更新。接口的区别是:在输入排布为TND的场景下,原RingAttentionUpdate接口中的softmax相关输入的数据排布为BNS8,RingAttentionUpdateV2 接口支持传入字符串参数 inputSoftmaxLayout,用于控制 softmax 相关输入的数据排布是否与attention保持一致(即采用 TND 排布)。
  • 计算公式:
softmax_max=max(prev_softmax_max,cur_softmax_max)softmax\_max = max(prev\_softmax\_max, cur\_softmax\_max) softmax_sum=prev_softmax_sumexp(prev_softmax_maxsoftmax_max)+cur_softmax_sumexp(cur_softmax_maxsoftmax_max)softmax\_sum = prev\_softmax\_sum * exp(prev\_softmax\_max - softmax\_max) + cur\_softmax\_sum * exp(cur\_softmax\_max - softmax\_max) attn_out=prev_attn_outexp(prev_softmax_maxsoftmax_max)prev_softmax_sum/softmax_sum+cur_attn_outexp(cur_softmax_maxsoftmax_max)cur_softmax_sum/softmax_sumattn\_out = prev\_attn\_out * exp(prev\_softmax\_max - softmax\_max) * prev\_softmax\_sum / softmax\_sum + cur\_attn\_out * exp(cur\_softmax\_max - softmax\_max) * cur\_softmax\_sum / softmax\_sum [object Object]

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

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

    [object Object]
    • [object Object]Atlas A2 训练系列产品/Atlas A2 推理系列产品[object Object]、[object Object]Atlas A3 训练系列产品/Atlas A3 推理系列产品[object Object]:当输入数据排布inputLayoutOptional为TND时,D限制为64的倍数。
  • 返回值

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

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

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

    [object Object]
  • 返回值

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

[object Object]
  • 确定性计算:
    • aclnnRingAttentionUpdateV2默认确定性实现。
  • 当inputLayoutOptional为“TND”时,actualSeqQlenOptional为必填。
  • 当inputLayoutOptional为“TND”时,其中:
    • N:
      • [object Object]Atlas A2 训练系列产品/Atlas A2 推理系列产品[object Object]、[object Object]Atlas A3 训练系列产品/Atlas A3 推理系列产品[object Object]:N<=256。
    • D:
      • [object Object]Atlas A2 训练系列产品/Atlas A2 推理系列产品[object Object]、[object Object]Atlas A3 训练系列产品/Atlas A3 推理系列产品[object Object]:D<=768且D为64的倍数。
  • 当inputLayoutOptional为“TND”时,inputSoftmaxLayoutOptional才生效。inputSoftmaxLayoutOptional只支持三种输入:空字符串、“SBH”、“TND”
[object Object]

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

[object Object]