o
    ©Ì³i  ã                   @   s6   d dl mZ d dlZd dlmZ G dd„ dejƒZdS )é    )ÚAnyN)Únnc                       sD   e Zd ZdZdededdf‡ fdd„Zdejdejfd	d
„Z‡  Z	S )ÚFp32LayerNormzZ
    Wrapper around :class:`~torch.nn.LayerNorm` to support mixed-precision training.
    ÚargsÚkwargsÚreturnNc                    s   t ƒ j|i |¤Ž d S )N)ÚsuperÚ__init__)Úselfr   r   ©Ú	__class__© úP/home/ubuntu/.local/lib/python3.10/site-packages/torchtune/modules/layer_norm.pyr	      s   zFp32LayerNorm.__init__Úxc                 C   sN   t j | ¡ | j| jdur| j ¡ nd| jdur| j ¡ nd| j¡}| |¡S )z¬
        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            torch.Tensor: The normalized output tensor having the same shape as ``x``.
        N)	r   Ú
functionalÚ
layer_normÚfloatÚnormalized_shapeÚweightÚbiasÚepsÚtype_as)r
   r   Úoutputr   r   r   Úforward   s   û
zFp32LayerNorm.forward)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   ÚtorchÚTensorr   Ú__classcell__r   r   r   r   r      s    r   )Útypingr   r   r   Ú	LayerNormr   r   r   r   r   Ú<module>   s   