文件最后提交记录最后更新时间
18 小时前
18 天前
18 天前
18 天前
18 天前
18 天前
4 个月前
1 个月前
README

ThnnFusedLstmCell

产品支持情况

产品 是否支持
Ascend 950PR/Ascend 950DT ×
Atlas A3 训练系列产品/Atlas A3 推理系列产品
Atlas A2 训练系列产品/Atlas A2 推理系列产品
Atlas 200I/500 A2 推理产品 ×
Atlas 推理系列产品 ×
Atlas 训练系列产品 ×

功能说明

  • 算子功能:实现长短期记忆网络单元(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}

    更新细胞状态:

    cy=fout⊙cx+iout⊙goutcy = f_{out} \odot cx + i_{out} \odot g_{out}

    更新隐状态:

    tanhc=tanh⁡(cy)hy=oout⊙tanhc\begin{aligned} tanhc &= \tanh(cy) \\ hy &= o_{out} \odot tanhc \end{aligned}

    相关符号说明:

    • 偏置 bih=inputBiasb_{ih} = \text{inputBias}, bhh=hiddenBiasb_{hh} = \text{hiddenBias}
    • gatesgates 沿最后一维平均切分为4个分量,即 gates→split[gatesi,gatesg,gatesf,gateso]gates \xrightarrow{\text{split}} [gates_i, gates_g, gates_f, gates_o]
    • 将得到的4个门控激活值沿最后一维拼接成storage\text{storage},即 [iout,gout,fout,oout]→concatstorage[i_{out}, g_{out}, f_{out}, o_{out}] \xrightarrow{\text{concat}} \text{storage}
    • σ\sigma 为Sigmoid激活函数,⊙\odot 为逐元素乘积

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
inputGates 输入 输入层的4个门,即输入门(Input Gate)、候选细胞状态(Cell Candidate)、遗忘门(Forget Gate)、输出门(Output Gate)的值。 FLOAT、FLOAT16 ND
hiddenGates 输入 隐藏层的4个门的值。 FLOAT、FLOAT16 ND
cx 输入 上一时的刻细胞状态。 FLOAT、FLOAT16 ND
inputBias 输入 输入偏置。 FLOAT、FLOAT16 ND
hiddenBias 输入 隐藏层偏置。 FLOAT、FLOAT16 ND
hy 输出 当前时刻的隐状态,即当前时刻的输出。 FLOAT、FLOAT16 ND
cy 输出 当前时刻的细胞状态。 FLOAT、FLOAT16 ND
storage 输出 4个门的激活值,提供给反向计算。 FLOAT、FLOAT16 ND

约束说明

调用说明

调用方式 样例代码 说明
aclnn接口 test_aclnn_thnn_fused_lstm_cell.cpp 通过aclnnThnnFusedLstmCell接口方式调用ThnnFusedLstmCell算子。