文件最后提交记录最后更新时间
13 天前
2 天前
13 天前
13 天前
13 天前
13 天前
7 个月前
1 个月前
README

DynamicRnnV2

产品支持情况

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

功能说明

  • 算子功能:基础循环神经网络(Recurrent Neural Network)算子,用于处理序列数据。它通过隐藏状态传递时序信息,适合处理具有时间/顺序依赖性的数据,仅支持单层RNN。

  • 算子公式:以LSTM格式为例给定输入 xtx_t、前一时刻隐藏状态 ht−1h_{t-1} 和细胞状态 ct−1c_{t-1},DynamicRNN的计算过程如下:

    1. 遗忘门 (Forget Gate):

      ft=σ(Wf⋅[ht−1,xt]+bf)f_t = \sigma(W_f \cdot [h_{t-1}, x_t] + b_f)

    2. 输入门 (Input Gate):

      it=σ(Wi⋅[ht−1,xt]+bi)i_t = \sigma(W_i \cdot [h_{t-1}, x_t] + b_i)

      c~t=tanh⁡(Wc⋅[ht−1,xt]+bc)\tilde{c}_t = \tanh(W_c \cdot [h_{t-1}, x_t] + b_c)

    3. 细胞状态更新:

      ct=ft⊙ct−1+it⊙c~tc_t = f_t \odot c_{t-1} + i_t \odot \tilde{c}_t

    4. 输出门 (Output Gate):

      ot=σ(Wo⋅[ht−1,xt]+bo)o_t = \sigma(W_o \cdot [h_{t-1}, x_t] + b_o)

      ht=ot⊙tanh⁡(ct)h_t = o_t \odot \tanh(c_t)

    其中:

    • σ\sigma 是sigmoid函数
    • ⊙\odot 表示逐元素乘法(Hadamard product)
    • W∗W_* 是可学习的权重矩阵
    • b∗b_* 是可学习的偏置项

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
x 输入 输入数据(T, Batch, input_size)。 FLOAT、FLOAT16 ND
w 输入 输入权重(input_size + hidden_size, 4 * hidden_size)。 FLOAT、FLOAT16 ND
b 输入 输入偏置(4 * hidden_size)。 FLOAT、FLOAT16 ND
seq_length 输入 每个batch真实的长度,维度为(T, Batch, input_size)。 FLOAT、FLOAT16 ND
init_h 输入 初始时刻的hidden state,维度为(1, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
init_c 输入 初始时刻的cell state,维度为(1, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
mask 输入 输入的掩码矩阵。 FLOAT、FLOAT16 ND
y 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
output_h 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
output_c 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
i 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
j 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
f 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
o 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
tanhc 输出 输出结果,维度为(T, batch_size, hidden_size)。 FLOAT、FLOAT16 ND
cell_type 属性 默认为"LSTM",当前实现"LSTM"、"GRU"。 STRING -
direction 属性 默认为"UNIDIRECTIONAL"。 STRING -
cell_depth 属性 multi_rnn的级数,默认为1,且当前只支持1。 INT -
use_peephole 属性 是否使用peephole,默认false。 BOOL -
keep_prob 属性 默认1.0。 FLOAT -
cell_clip 属性 默认值为-1.0(没有剪切)。 FLOAT -
num_proj 属性 用projection的降维后的维度,默认为0表示不降维。 INT -
time_major 属性 输入数据的排列方式,默认True。 BOOL -
activation 属性 激活函数"tanh"。 STRING -
forget_bias 属性 默认1.0。 FLOAT -
gate_order 属性 默认"ijfo"。 STRING -
is_training 属性 默认true。 BOOL -
  • Atlas 推理系列产品:不支持BFLOAT16。

约束说明

调用说明

调用方式 样例代码 说明
图模式 test_geir_dynamic_rnnv2 通过算子IR构图方式调用DynamicRnn算子。