开发者
资源
[object Object][object Object][object Object]undefined
[object Object]
  • 算子功能:实现长短期记忆网络单元(LSTM Cell)的单步前向计算中,矩阵乘法后的后续计算。输出当前时刻的隐状态和细胞状态,同时输出当前遗忘门、输入门、输出门和候选状态用于反向计算。

  • 计算公式:

    计算门控激活值:

    b=bih+bhhgates=inputGates+hiddenGates+biout=σ(gatesi)gout=tanh(gatesg)fout=σ(gatesf)oout=σ(gateso)\begin{aligned} b &= b_{ih} + b_{hh} \\ gates &= inputGates + hiddenGates + b \\ i_{out} &= \sigma(gates_{i}) \\ g_{out} &= \tanh(gates_{g}) \\ f_{out} &= \sigma(gates_{f}) \\ o_{out} &= \sigma(gates_{o}) \end{aligned}

    更新细胞状态:

    cyout=foutcx+ioutgoutcy_{out} = f_{out} \odot cx + i_{out} \odot g_{out}

    更新隐状态:

    tanhc=tanh(cyout)hyout=oouttanhc\begin{aligned} tanhc &= \tanh(cy_{out}) \\ hy_{out} &= o_{out} \odot tanhc \end{aligned}

    相关符号说明:

    • 偏置 bih=inputBiasOptionalb_{ih} = \text{inputBiasOptional}, bhh=hiddenBiasOptionalb_{hh} = \text{hiddenBiasOptional} ,如未输入偏置则为零
    • gatesgates 沿最后一维平均切分为 4 个分量,即 gatessplit[gatesi,gatesg,gatesf,gateso]gates \xrightarrow{\text{split}} [gates_i, gates_g, gates_f, gates_o]
    • 将得到的4个门控激活值沿最后一维拼接成storageOut\text{storageOut},即 [iout,gout,fout,oout]concatstorageOut[i_{out}, g_{out}, f_{out}, o_{out}] \xrightarrow{\text{concat}} \text{storageOut}
    • σ\sigma 为 Sigmoid 激活函数,\odot 为逐元素乘积
[object Object]

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

[object Object]
[object Object]
[object Object]
  • 参数说明:
[object Object]
  • 返回值:

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

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

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

    [object Object]
  • 返回值:

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

[object Object]
  • 确定性说明:aclnnThnnFusedLstmCell默认确定性实现。
  • 所有输入、输出参数的数据类型需保持一致。
[object Object]

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

[object Object]