GRU

Description

Computes a single-layer GRU. This operator is usually supported through some custom implementation.

Input

  • x: input tensor. The input sequence is packed into a 3D tensor. The shape is [seq_length, batch_size, input_size]. The data type is float16.
  • w: input tensor. The gate weight is concatenated along dimension 0 (if bidirectional). The shape is W[zrh] WB[zrh] [num_directions, 3*hidden_size, input_size]. The data type is float16.
  • r: input tensor. The recursive weight tensor is concatenated along dimension 0 (if bidirectional). The shape is R[zrh] RB[zrh] [num_directions, 3*hidden_size, hidden_size]. The data type is float16.
  • b (optional): input tensor. The gate offset tensor is concatenated along dimension 0 (if bidirectional). The shape is [Wb[zrh], Rb[zrh]] [WBb[zrh], RBb[zrh]] [num_directions, 6*hidden_size]. If this parameter is not selected, the default value 0 is used. The data type can be float16.
  • sequence_lens (optional): input tensor. It is used to specify the length of a sequence in a batch. The shape is seq_length[batch_size]. If this parameter is not selected, it is assumed that all sequences have length. The data type is int32.
  • initial_h (optional): input tensor. It is used to specify the initial value of hidden. The shape is [num_directions, batch_size, hidden_size]. If this parameter is not selected, it is assumed that the value is 0. The data type is float16.

Attribute

  • activation_alpha: optional scaling value used by the activation function. The data type can be floats. These values are used in the order of the activation function, such as (f, g, h) in LSTM. The default value is the same as that of ONNX. For LeakyRelu, the default alpha is 0.01.
  • activation_beta: optional scaling value used by the activation function. The data type can be floats. These values are used in the order of the activation function, such as (f, g, h) in LSTM. The default value is the same as that of ONNX.
  • activations: activation function list used to update, reset, and hide the gates (if bidirectional). The data type can be strings. The activation function must be one of the activation functions specified above.
  • clip: clip threshold of a unit. The data type can be float. The tensor element is limited to a specific unit.
  • direction: The data type can be string. The default value is forward, indicating whether the RNN is forward, reverse, or bidirectional. The value must be forward (by default), reverse, or bidirectional.
  • hidden_size: number of neurons at the hidden layer. The data type can be int.
  • linear_before_reset: The data type can be int. The default value is 0. Linear transformation is applied before multiplying the output of the reset gate when computing the output of the hidden gate.

Output

  • y: output tensor, which is connected to all intermediate output values of hidden. The shape is [seq_length, num_directions, batch_size, hidden_size]. The data type is float16.
  • y_h: output tensor, which is the last hidden output value. The shape is [num_directions, batch_size, hidden_size]. The data type is float16.

Constraints

None.

ONNX Opset Support

Opset v8/v9/v10/v11/v12/v13/v14/v15/v16/v17/v18