GRU - 1 vs 22

Next section compares an older to a newer version of the same operator after both definition are converted into markdown text. Green means an addition to the newer version, red means a deletion. Anything else is unchanged.

Files changed (1) hide show
  1. GRU1 → GRU22 +48 -67
GRU1 → GRU22 RENAMED
@@ -1 +1 @@
1
1
  Computes an one-layer GRU. This operator is usually supported via some custom
2
2
  implementation such as CuDNN.
3
3
  Notations:
4
- X - input tensor
4
+ * X - input tensor
5
-
6
- z - update gate
5
+ * z - update gate
7
-
8
- r - reset gate
6
+ * r - reset gate
9
-
10
- h - hidden gate
7
+ * h - hidden gate
11
-
12
- t - time step (t-1 means previous time step)
8
+ * t - time step (t-1 means previous time step)
13
-
14
- W[zrh] - W parameter weight matrix for update, reset, and hidden gates
9
+ * W[zrh] - W parameter weight matrix for update, reset, and hidden gates
15
-
16
- R[zrh] - R recurrence weight matrix for update, reset, and hidden gates
10
+ * R[zrh] - R recurrence weight matrix for update, reset, and hidden gates
17
-
18
- Wb[zrh] - W bias vectors for update, reset, and hidden gates
11
+ * Wb[zrh] - W bias vectors for update, reset, and hidden gates
19
-
20
- Rb[zrh] - R bias vectors for update, reset, and hidden gates
12
+ * Rb[zrh] - R bias vectors for update, reset, and hidden gates
21
-
22
- WB[zrh] - W parameter weight matrix for backward update, reset, and hidden gates
13
+ * WB[zrh] - W parameter weight matrix for backward update, reset, and hidden gates
23
-
24
- RB[zrh] - R recurrence weight matrix for backward update, reset, and hidden gates
14
+ * RB[zrh] - R recurrence weight matrix for backward update, reset, and hidden gates
25
-
26
- WBb[zrh] - W bias vectors for backward update, reset, and hidden gates
15
+ * WBb[zrh] - W bias vectors for backward update, reset, and hidden gates
27
-
28
- RBb[zrh] - R bias vectors for backward update, reset, and hidden gates
16
+ * RBb[zrh] - R bias vectors for backward update, reset, and hidden gates
29
-
30
- H - Hidden state
17
+ * H - Hidden state
31
-
32
- num_directions - 2 if direction == bidirectional else 1
18
+ * num_directions - 2 if direction == bidirectional else 1
33
19
  Activation functions:
34
- Relu(x) - max(0, x)
20
+ * Relu(x) - max(0, x)
21
+ * Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
22
+ * Sigmoid(x) - 1/(1 + e^{-x})
23
+ NOTE:
35
- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
24
+ Below are optional
36
- Sigmoid(x) - 1/(1 + e^{-x})
37
-
38
- (NOTE: Below are optional)
39
-
40
- Affine(x) - alpha*x + beta
25
+ * Affine(x) - alpha * x + beta
41
-
42
- LeakyRelu(x) - x if x >= 0 else alpha * x
26
+ * LeakyRelu(x) - x if x >= 0 else alpha * x
43
-
44
- ThresholdedRelu(x) - x if x >= alpha else 0
27
+ * ThresholdedRelu(x) - x if x >= alpha else 0
45
-
46
- ScaledTanh(x) - alpha*Tanh(beta*x)
28
+ * ScaledTanh(x) - alpha * Tanh(beta * x)
47
-
48
- HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)
29
+ * HardSigmoid(x) - min(max(alpha * x + beta, 0), 1)
49
-
50
- Elu(x) - x if x >= 0 else alpha*(e^x - 1)
30
+ * Elu(x) - x if x >= 0 else alpha * (e^x - 1)
51
-
52
- Softsign(x) - x/(1 + |x|)
31
+ * Softsign(x) - x/(1 + |x|)
53
-
54
- Softplus(x) - log(1 + e^x)
32
+ * Softplus(x) - log(1 + e^x)
55
33
  Equations (Default: f=Sigmoid, g=Tanh):
56
- - zt = f(Xt*(Wz^T) + Ht-1*Rz + Wbz + Rbz)
34
+ * zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz)
57
-
58
- - rt = f(Xt*(Wr^T) + Ht-1*Rr + Wbr + Rbr)
35
+ * rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr)
59
-
60
- - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*Rh + Rbh + Wbh) # default, when linear_before_reset = 0
36
+ * ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0
61
-
62
- - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*Rh + Rbh) + Wbh) # when linear_before_reset != 0
37
+ * ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0
63
-
64
- - Ht = (1 - zt) (.) ht + zt (.) Ht-1
38
+ * Ht = (1 - zt) (.) ht + zt (.) Ht-1
39
+ This operator has **optional** inputs/outputs. See [ONNX IR](https://github.com/onnx/onnx/blob/main/docs/IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
65
40
  ### Attributes
66
41
  * **activation_alpha - FLOATS** :
67
- Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM.
42
+ Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
68
43
  * **activation_beta - FLOATS** :
69
- Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM.
44
+ Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
70
45
  * **activations - STRINGS** :
71
46
  A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
72
47
  * **clip - FLOAT** :
73
48
  Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
74
- * **direction - STRING** (default is 'foward'):
49
+ * **direction - STRING** (default is 'forward'):
75
50
  Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
76
51
  * **hidden_size - INT** :
77
52
  Number of neurons in the hidden layer
78
- * **output_sequence - INT** (default is '0'):
53
+ * **layout - INT** (default is '0'):
79
- The sequence output for the hidden is optional if 0. Default 0.
54
+ The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].
55
+
56
+ * **linear_before_reset - INT** (default is '0'):
57
+
58
+ When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate.
80
59
  ### Inputs
81
60
  Between 3 and 6 inputs.
82
61
  - **X** (heterogeneous) - **T**:
83
62
  The input sequences packed (and potentially padded) into one 3-D tensor with the shape of [seq_length, batch_size, input_size].
84
63
  - **W** (heterogeneous) - **T**:
85
64
  The weight tensor for the gates. Concatenation of W[zrh] and WB[zrh] (if bidirectional) along dimension 0. This tensor has shape [num_directions, 3*hidden_size, input_size].
86
65
  - **R** (heterogeneous) - **T**:
87
66
  The recurrence weight tensor. Concatenation of R[zrh] and RB[zrh] (if bidirectional) along dimension 0. This tensor has shape [num_directions, 3*hidden_size, hidden_size].
88
67
  - **B** (optional, heterogeneous) - **T**:
89
68
  The bias tensor for the gates. Concatenation of [Wb[zrh], Rb[zrh]] and [WBb[zrh], RBb[zrh]] (if bidirectional) along dimension 0. This tensor has shape [num_directions, 6*hidden_size]. Optional: If not specified - assumed to be 0
90
69
  - **sequence_lens** (optional, heterogeneous) - **T1**:
91
70
  Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length seq_length. It has shape [batch_size].
92
71
  - **initial_h** (optional, heterogeneous) - **T**:
93
72
  Optional initial value of the hidden. If not specified - assumed to be 0. It has shape [num_directions, batch_size, hidden_size].
94
73
  ### Outputs
74
+ Between 0 and 2 outputs.
75
+
95
76
  - **Y** (optional, heterogeneous) - **T**:
96
- A tensor that concats all the intermediate output values of the hidden. It has shape [seq_length, num_directions, batch_size, hidden_size]. It is optional if output_sequence is 0.
77
+ A tensor that concats all the intermediate output values of the hidden. It has shape [seq_length, num_directions, batch_size, hidden_size].
97
- - **Y_h** (heterogeneous) - **T**:
78
+ - **Y_h** (optional, heterogeneous) - **T**:
98
79
  The last output value of the hidden. It has shape [num_directions, batch_size, hidden_size].
99
80
  ### Type Constraints
100
- * **T** in ( tensor(double), tensor(float), tensor(float16) ):
81
+ * **T** in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ):
101
82
  Constrain input and output types to float tensors.
102
83
  * **T1** in ( tensor(int32) ):
103
84
  Constrain seq_lens to integer tensor.