Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apex/normalization/fused_layer_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,19 @@ class FusedRMSNorm(torch.nn.Module):
Currently only runs on cuda() tensors.

.. math::
y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
y = \frac{x}{\mathrm{RMS}[x]} * \gamma

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing epsilon and I checked it's in the code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was left out as the syntax looked kind of involved... feel free to suggest a fix!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


The mean and standard-deviation are calculated separately over the last
The root-mean-square is calculated separately over the last
certain number dimensions which have to be of the shape specified by
:attr:`normalized_shape`.
:math:`\gamma` and :math:`\beta` are learnable affine transform parameters of
:math:`\gamma` is a learnable affine transform parameter of
:attr:`normalized_shape` if :attr:`elementwise_affine` is ``True``.

.. note::
Unlike Batch Normalization and Instance Normalization, which applies
scalar scale and bias for each entire channel/plane with the
:attr:`affine` option, Layer Normalization applies per-element scale and
bias with :attr:`elementwise_affine`.
:attr:`affine` option, RMS Normalization applies per-element scale
with :attr:`elementwise_affine`.

This layer uses statistics computed from input data in both training and
evaluation modes.
Expand Down Expand Up @@ -353,7 +353,7 @@ class FusedRMSNorm(torch.nn.Module):
>>> # Activating the module
>>> output = m(input)

.. _`Layer Normalization`: https://arxiv.org/abs/1607.06450
.. _`Root Mean Square Layer Normalization`: https://arxiv.org/pdf/1910.07467.pdf
"""

def __init__(self, normalized_shape, eps=1e-5, elementwise_affine=True):
Expand Down
3 changes: 3 additions & 0 deletions docs/source/layernorm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ apex.normalization.fused_layer_norm

.. autoclass:: FusedLayerNorm
:members:

.. autoclass:: FusedRMSNorm
:members: