o
    ¡¿¯iÛ  ã                   @   s6   d dl Z 			dde jjdededed	ef
d
d„ZdS )é    Néd   ç      ð?çš™™™™™á?ÚmodelÚ	iterationÚdurationÚetaÚscale_factorc           
      C   sb   || d }|||  }|   ¡ D ]}|jdur.|j ¡ }|t |¡ |j¡ }	| j|	7  _qdS )a  Adds noise from a standard normal distribution to the gradients.

    The standard deviation (`sigma`) is controlled
    by the three hyper-parameters below.
    `sigma` goes to zero (no noise) with more iterations.

    Args:
        model: Model.
        iteration: Number of iterations.
        duration: {100, 1000}: Number of durations to control
            the interval of the `sigma` change.
        eta: {0.01, 0.3, 1.0}: The magnitude of `sigma`.
        scale_factor: {0.55}: The scale of `sigma`.
    é   N)Ú
parametersÚgradÚsizeÚtorchÚrandnÚtoÚdevice)
r   r   r   r   r	   ÚintervalÚsigmaÚparamÚ_shapeÚnoise© r   úZ/home/ubuntu/.local/lib/python3.10/site-packages/espnet2/torch_utils/add_gradient_noise.pyÚadd_gradient_noise   s   

€ür   )r   r   r   )r   ÚnnÚModuleÚintÚfloatr   r   r   r   r   Ú<module>   s    ûÿþýüû