module onnxrt.ops_cpu.op_layer_normalization
#
Short summary#
module mlprodict.onnxrt.ops_cpu.op_layer_normalization
Runtime operator.
Classes#
class |
truncated documentation |
---|---|
LayerNormalization ================== This is layer normalization defined in ONNX as function. The overall computation … |
Functions#
function |
truncated documentation |
---|---|
Properties#
property |
truncated documentation |
---|---|
|
Returns the list of arguments as well as the list of parameters with the default values (close to the signature). … |
|
Returns the list of modified parameters. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns all parameters in a dictionary. |
Methods#
method |
truncated documentation |
---|---|
Documentation#
Runtime operator.
- class mlprodict.onnxrt.ops_cpu.op_layer_normalization.LayerNormalization(onnx_node, desc=None, **options)#
Bases:
OpRun
This is layer normalization defined in ONNX as function. The overall computation can be split into two stages. The first stage is standardization, which makes the normalized elements have zero mean and unit variances. The computation required by standardization can be described by the following equations. `` Mean = ReduceMean<axes=normalized_axes>(X) D = Sub(X, Mean) DD = Mul(D, D) Var = ReduceMean<axes=normalized_axes>(DD) VarEps = Add(Var, epsilon) StdDev = Sqrt(VarEps) InvStdDev = Reciprocal(StdDev) Normalized = Mul(D, InvStdDev) `` where normalized_axes is [axis, …, rank of X - 1]. The variables Var and StdDev stand for variance and standard deviation, respectively. The second output is Mean and the last one is InvStdDev. Depending on stash_type attribute, the actual computation must happen in different floating-point precision. For example, if stash_type is 1, this operator casts all input variables to 32-bit float, perform the computation, and finally cast Normalized back to the original type of X. The second stage then scales and shifts the outcome of the first stage using `` NormalizedScaled = Mul(Normalized, Scale) Y = Add(NormalizedScaled, B) `` The second stage doesn’t depends on stash_type. All equations are in [this syntax](onnx/onnx). The same variable (i.e., input, output, and attribute) uses the same name in the equations above and this operator’s definition. Let d[i] indicate the i-th dimension of X. If X’s shape is [d[0], …, d[axis-1], d[axis], …, d[rank-1]], the shape of Mean and InvStdDev is [d[0], …, d[axis-1], 1, …, 1]. Y and X have the same shape.
Attributes
axis: The first normalization dimension. If rank(X) is r, axis’ allowed range is [-r, r]. Negative value means counting dimensions from the back. Default value is
nameaxisi-1typeINT
(INT)epsilon: The epsilon value to use to avoid division by zero. Default value is
nameepsilonf9.999999747378752e-06typeFLOAT
(FLOAT)stash_type: Type of Mean and InvStdDev. This also specifies stage one’s computation precision. Default value is
namestashtypei1typeINT
(INT)
Inputs
Between 2 and 3 inputs.
X (heterogeneous)T: Tensor to be normalized.
Scale (heterogeneous)T: Scale tensor.
B (optional, heterogeneous)T: Bias tensor.
Outputs
Between 1 and 3 outputs.
Y (heterogeneous)T: Normalized tensor.
Mean (optional, heterogeneous)U: Saved mean used during training to speed up gradient computation
InvStdDev (optional, heterogeneous)U: Saved inverse standard deviation used during training to speed up gradient computation.
Type Constraints
T tensor(float16), tensor(float), tensor(double), tensor(bfloat16): Constrain input types and output Y type to float tensors.
U tensor(float), tensor(bfloat16): Type of Mean and InvStdDev tensors.
Version
Onnx name: LayerNormalization
This version of the operator has been available since version 17.
Runtime implementation:
LayerNormalization
- __init__(onnx_node, desc=None, **options)#
- _run(X, Scale, B=None, attributes=None, verbose=0, fLOG=None)#
Should be overwritten.
- mlprodict.onnxrt.ops_cpu.op_layer_normalization._layer_normalization(X, W, B, axis=-1, epsilon=1e-05)#