module onnxrt.ops_cpu.op_rnn#

Inheritance diagram of mlprodict.onnxrt.ops_cpu.op_rnn

Short summary#

module mlprodict.onnxrt.ops_cpu.op_rnn

Runtime operator.

source on GitHub

Classes#

class

truncated documentation

CommonRNN

RNN_14

RNN === Computes an one-layer simple RNN. This operator is usually supported via some custom implementation such as CuDNN. …

RNN_14

RNN === Computes an one-layer simple RNN. This operator is usually supported via some custom implementation such as CuDNN. …

RNN_7

Properties#

property

truncated documentation

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

Methods#

method

truncated documentation

__init__

__init__

__init__

__init__

_f_tanh

_f_tanh

_f_tanh

_f_tanh

_infer_shapes

_infer_shapes

_infer_shapes

_infer_shapes

_infer_types

_infer_types

_infer_types

_infer_types

_run

_run

_run

_run

_step

_step

_step

_step

choose_act

choose_act

choose_act

choose_act

Documentation#

Runtime operator.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_rnn.CommonRNN(onnx_node, expected_attributes=None, desc=None, **options)#

Bases: OpRun

__init__(onnx_node, expected_attributes=None, desc=None, **options)#
_f_tanh(x)#
_infer_shapes(X, W, R, B=None, sequence_lens=None, initial_h=None)#

Should be overwritten.

source on GitHub

_infer_types(X, W, R, B=None, sequence_lens=None, initial_h=None)#

Should be overwritten.

source on GitHub

_run(X, W, R, B=None, sequence_lens=None, initial_h=None, attributes=None, verbose=0, fLOG=None)#

Should be overwritten.

source on GitHub

_step(X, R, B, W, H_0)#
mlprodict.onnxrt.ops_cpu.op_rnn.RNN#

alias of RNN_14

class mlprodict.onnxrt.ops_cpu.op_rnn.RNN_14(onnx_node, desc=None, **options)#

Bases: CommonRNN

Computes an one-layer simple RNN. This operator is usually supported via some custom implementation such as CuDNN.

Notations:

X - input tensor

i - input gate

t - time step (t-1 means previous time step)

Wi - W parameter weight matrix for input gate

Ri - R recurrence weight matrix for input gate

Wbi - W parameter bias vector for input gate

Rbi - R parameter bias vector for input gate

WBi - W parameter weight matrix for backward input gate

RBi - R recurrence weight matrix for backward input gate

WBbi - WR bias vectors for backward input gate

RBbi - RR bias vectors for backward input gate

H - Hidden state

num_directions - 2 if direction == bidirectional else 1

Activation functions:

Relu(x) - max(0, x)

Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})

Sigmoid(x) - 1/(1 + e^{-x})

(NOTE: Below are optional)

Affine(x) - alpha*x + beta

LeakyRelu(x) - x if x >= 0 else alpha * x

ThresholdedRelu(x) - x if x >= alpha else 0

ScaledTanh(x) - alpha*Tanh(beta*x)

HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)

Elu(x) - x if x >= 0 else alpha*(e^x - 1)

Softsign(x) - x/(1 + |x|)

Softplus(x) - log(1 + e^x)

Equations (Default: f=Tanh):

  • Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)

This operator has optional inputs/outputs. See ONNX 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.

Attributes

  • activation_alpha: 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. default value cannot be automatically retrieved (FLOATS)

  • activation_beta: 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. default value cannot be automatically retrieved (FLOATS)

  • activations: One (or two if bidirectional) activation function for input gate. The activation function must be one of the activation functions specified above. Optional: Default Tanh if not specified. Default value is nameactivationsstringsTanhstringsTanhtypeSTRINGS (STRINGS)

  • clip: 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. default value cannot be automatically retrieved (FLOAT)

  • direction: Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional. Default value is namedirectionsforwardtypeSTRING (STRING)

  • hidden_size: Number of neurons in the hidden layer default value cannot be automatically retrieved (INT)

  • layout: 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]. Default value is namelayouti0typeINT (INT)

Inputs

Between 3 and 6 inputs.

  • X (heterogeneous)T: The input sequences packed (and potentially padded) into one 3-D tensor with the shape of [seq_length, batch_size, input_size].

  • W (heterogeneous)T: The weight tensor for input gate. Concatenation of Wi and WBi (if bidirectional). The tensor has shape [num_directions, hidden_size, input_size].

  • R (heterogeneous)T: The recurrence weight tensor. Concatenation of Ri and RBi (if bidirectional). The tensor has shape [num_directions, hidden_size, hidden_size].

  • B (optional, heterogeneous)T: The bias tensor for input gate. Concatenation of [Wbi, Rbi] and [WBbi, RBbi] (if bidirectional). The tensor has shape [num_directions, 2*hidden_size]. Optional: If not specified - assumed to be 0.

  • sequence_lens (optional, heterogeneous)T1: 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].

  • initial_h (optional, heterogeneous)T: Optional initial value of the hidden. If not specified - assumed to be 0. It has shape [num_directions, batch_size, hidden_size].

Outputs

Between 0 and 2 outputs.

  • Y (optional, heterogeneous)T: A tensor that concats all the intermediate output values of the hidden. It has shape [seq_length, num_directions, batch_size, hidden_size].

  • Y_h (optional, heterogeneous)T: The last output value of the hidden. It has shape [num_directions, batch_size, hidden_size].

Type Constraints

  • T tensor(float16), tensor(float), tensor(double): Constrain input and output types to float tensors.

  • T1 tensor(int32): Constrain seq_lens to integer tensor.

Version

Onnx name: RNN

This version of the operator has been available since version 14.

Runtime implementation: RNN

__init__(onnx_node, desc=None, **options)#
class mlprodict.onnxrt.ops_cpu.op_rnn.RNN_7(onnx_node, desc=None, **options)#

Bases: CommonRNN

__init__(onnx_node, desc=None, **options)#