Norms#

Collection of Ivy normalization classes.

class ivy.stateful.norms.BatchNorm2D(num_features, /, *, eps=1e-05, momentum=0.1, data_format='NSC', affine=True, track_running_stats=True, device=None, v=None, dtype=None)[source]#

Bases: Module

__init__(num_features, /, *, eps=1e-05, momentum=0.1, data_format='NSC', affine=True, track_running_stats=True, device=None, v=None, dtype=None)[source]#

Class for applying Layer Normalization over a mini-batch of inputs.

Parameters:
  • num_features – Trailing shape to applying the normalization to.

  • epsilon – small constant to add to the denominator, use global ivy._MIN_BASE by default.

  • data_format (str) – The ordering of the dimensions in the input, one of “NSC” or “NCS”, (default: 'NSC') where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

  • affine (bool) – Whether to include learnable affine parameters, default is True. (default: True)

  • track_running_stats (bool) – is a boolean flag that determines whether (default: True) the running statistics should be updated during training in batch normalization.

  • momentum (float) –

    (default: 0.1) The value used for the running_mean and running_var computation.

    Default is 0.1.

  • device – device on which to create the layer’s variables ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None)

  • v – the variables for each submodule in the sequence, constructed internally by default.

  • training – If true, calculate and use the mean and variance of x. Otherwise, use the internal mean and variance when affine is True.

class ivy.stateful.norms.LayerNorm(normalized_shape, /, *, eps=1e-05, elementwise_affine=True, new_std=1.0, device=None, v=None, dtype=None)[source]#

Bases: Module

__init__(normalized_shape, /, *, eps=1e-05, elementwise_affine=True, new_std=1.0, device=None, v=None, dtype=None)[source]#

Class for applying Layer Normalization over a mini-batch of inputs.

Parameters:
  • normalized_shape – Trailing shape to applying the normalization to.

  • epsilon – small constant to add to the denominator, use global ivy._MIN_BASE by default.

  • elementwise_affine (bool) – Whether to include learnable affine parameters, default is True. (default: True)

  • new_std (float) – The standard deviation of the new normalized values. Default is 1. (default: 1.0)

  • device – device on which to create the layer’s variables ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None)

  • v – the variables for each submodule in the sequence, constructed internally by default.

This should have hopefully given you an overview of the norms submodule, if you have any questions, please feel free to reach out on our discord in the norms channel or in the norms forum!