开发者
下载
[object Object][object Object]
  • [object Object]Ascend 950PR/Ascend 950DT[object Object]:支持
  • [object Object]Atlas A3 训练系列产品/Atlas A3 推理系列产品[object Object]:支持
  • [object Object]Atlas A2 训练系列产品/Atlas A2 推理系列产品[object Object]:支持
  • [object Object]Atlas 200I/500 A2 推理产品[object Object]:不支持
  • [object Object]Atlas 推理系列产品[object Object]:不支持
  • [object Object]Atlas 训练系列产品[object Object]:不支持
[object Object]
  • 接口功能:

    基于一系列计算得到MHC架构中hidden层的Hres\mathbf{H}'_{\text{res}}Hpost\mathbf{H}_{\text{post}}投影矩阵以及Attention或MLP层的输入矩阵hin\mathbf{h}_{\text{in}}。对Hres\mathbf{H}'_{\text{res}}矩阵执行Sinkhorn迭代归一化变换,最终得到双随机矩阵Hres\mathbf{H}_{\text{res}};支持输出中间计算结果,用于反向梯度计算。

  • 计算公式:

    xl=11ddim=2,keepdim=Truexi2+ϵnormHlpre=αlpre(xlφlpre)+blpreHlpost=αlpost(xlφlpost)+blpostHlres=αlres(xlφlres)+blresHlpre=σ(Hlpre)Hlpost=2σ(Hlpost)hin=xlHlpre\begin{aligned} \vec{x^{'}_{l}} &= \frac{1}{\sqrt{\frac{1}{d} \sum_{\dim=-2,\text{keepdim}=\text{True}} x_i^2 + \epsilon_{norm}}}\\ H^{pre}_l &= \alpha^{pre}_{l} \cdot(\vec{x^{'}_{l}}\varphi^{pre}_{l}) + b^{pre}_{l}\\ H^{post}_l &= \alpha^{post}_{l} \cdot(\vec{x^{'}_{l}}\varphi^{post}_{l}) + b^{post}_{l}\\ H^{res}_l &= \alpha^{res}_{l} \cdot(\vec{x^{'}_{l}}\varphi^{res}_{l}) + b^{res}_{l}\\ H^{pre}_l &= \sigma (H^{pre}_{l})\\ H^{post}_l &= 2\sigma (H^{post}_{l})\\ h_{in} &=\vec{x_{l}}H^{pre}_l \end{aligned}

    Hlres\mathbf{H^{res}_l}作为输入,Sinkhorn变换共执行numIters\mathbf{numIters}次迭代,迭代过程中生成中间归一化结果normOut[k]\mathbf{normOut}[k]和求和结果sumOut[k]\mathbf{sumOut}[k],最终输出最后一次迭代的normOut\mathbf{normOut}作为变换结果。

    第一次迭代(初始化):

    normOut[0]=softmax(Hlres,dim=1)+ϵhc,sumOut[1]=dim=2,keepdim=TruenormOut[0]+ϵhc,normOut[1]=normOut[0]sum_out[1],\begin{aligned} \mathbf{normOut}[0] &= \text{softmax}(\mathbf{H^{res}_l}, \dim=-1) + \epsilon_{hc}, \\ \mathbf{sumOut}[1] &= \sum_{\dim=-2,\text{keepdim}=\text{True}} \mathbf{normOut}[0] + \epsilon_{hc}, \\ \mathbf{normOut}[1] &= \frac{\mathbf{normOut}[0]}{\mathbf{sum\_out}[1]}, \\ \end{aligned}

    ii次迭代(i=1,2,,num_iters1i = 1, 2, \dots, \mathbf{num\_iters}-1):

    sumOut[2i]=dim=1,keepdim=TruenormOut[2i1]+ϵhc,normOut[2i]=normOut[2i1]sum_out[2i],sumOut[2i+1]=dim=2,keepdim=TruenormOut[2i]+ϵhc,normOut[2i+1]=normOut[2i]sum_out[2i+1],\begin{aligned} \mathbf{sumOut}[2i] &= \sum_{\dim=-1,\text{keepdim}=\text{True}} \mathbf{normOut}[2i-1] + \epsilon_{hc}, \\ \mathbf{normOut}[2i] &= \frac{\mathbf{normOut}[2i-1]}{\mathbf{sum\_out}[2i]}, \\ \mathbf{sumOut}[2i+1] &= \sum_{\dim=-2,\text{keepdim}=\text{True}} \mathbf{normOut}[2i] + \epsilon_{hc}, \\ \mathbf{normOut}[2i+1] &= \frac{\mathbf{normOut}[2i]}{\mathbf{sum\_out}[2i+1]}, \\ \end{aligned}

    最终输出:

    normOut[2×num_iters1]\mathbf{normOut}[2 \times \mathbf{num\_iters} - 1] sumOut[2×num_iters1]\mathbf{sumOut}[2 \times \mathbf{num\_iters} - 1]
[object Object]
[object Object]
[object Object][object Object][object Object][object Object][object Object]
  • 该接口支持训练、推理场景下使用

  • 该接口支持单算子模式调用

  • 规格约束:

    [object Object]undefined
  • 参数约束:

    • x不支持空Tensor。
    • phi不支持空Tensor。
    • alpha不支持空Tensor。
    • bias不支持空Tensor。
[object Object]

默认支持确定性计算。

[object Object]
  • 单算子模式调用:

    [object Object]