
    Pi                     B    d dl Z d dl mZ dej        de j        ddfdZdS )    N)nnmodelscalerreturnc                     d}|                                  D ]7}|s|j        }|                    |          }|j        |xj        |z  c_        8dS )a  
    Utility to scale the gradients of a model.
    This is useful for gradient accumulation where we want to normalize
    the gradients by the total number of tokens seen.

    Inputs:
        model (nn.Module): model whose gradients should be scaled
        scaler (torch.Tensor): scaling factor to apply to the gradients

    Outputs:
        None (grad fields are modified in place)
    N)
parametersdevicetograd)r   r   r	   ps       s/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/training/_grad_scaler.pyscale_gradsr      sg     F   	'XFYYv&&F6FFfFF     )torchr   ModuleTensorr    r   r   <module>r      sY          ry %, 4      r   