
    Pi                     R    d dl Z d dlmc mZ d dl mZ  G d dej                  ZdS )    N)nnc                   V     e Zd ZdZd
dededdf fdZdej        dej        fd	Z	 xZ
S )RMSNormz
    Root Mean Square Normalization in fp32.

    See: https://pytorch.org/docs/stable/generated/torch.nn.RMSNorm.html

    Args:
        dim (int): embedding size
        eps (float): small value to avoid division by zero. Default: 1e-6
    ư>dimepsreturnNc                     t                                                       |f| _        || _        t	          j        t          j        |                    | _        d S )N)	super__init__normalized_shaper   r   	Parametertorchonesscale)selfr   r   	__class__s      n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/modules/rms_norm.pyr   zRMSNorm.__init__   sG    !$\%*S//22


    xc                     t          j        |                                | j        | j        | j                                      |j                  S )z
        Args:
            x (torch.Tensor): input tensor to normalize

        Returns:
            torch.Tensor: The normalized and scaled tensor having the same shape as ``x``.
        )r   weightr   )Frms_normfloatr   r   r   todtype)r   r   s     r   forwardzRMSNorm.forward   sG     zGGII!2:	
 
 

 "QW++	r   )r   )__name__
__module____qualname____doc__intr   r   r   Tensorr   __classcell__)r   s   @r   r   r      s         3 3C 3e 3t 3 3 3 3 3 3 %,        r   r   )r   torch.nn.functionalr   
functionalr   Moduler    r   r   <module>r*      ss                       bi     r   