o
    %ݫi`                  	   @   sZ   d Z ddlZddlZddlZddlmZ eeZdZdZ		dde
ded	ed
e
fddZdS )zASeed utilities for reproducibility.

Authors
 * Adel Moumen 2024
    N)
get_loggerl    TFseedverbosedeterministicreturnc                 C   s   t |   kr
tksn t|  dt  dt  t } |r$td|   t| tjd< t|  zddl	}|j|  W n	 t
yE   Y nw t|  tj|  |rXtd | S )a*  Function that sets the seed for pseudo-random number generators in: torch, numpy, and Python's random module. Important note on DDP: all DDP
    process have the same seed. This is important to ensure that parameters
    without a require_grad set to True are the same across processes. This
    must be taken into account if one wants to build a custom data sampler as
    the processes would pick the same samples... SpeechBrain takes care of that
    internally.

    Arguments
    ---------
    seed: int
        the integer value seed for global random state.
    verbose: bool
        Whether to print a message on each rank with the seed being set.
    deterministic: bool
        Whether to set the seed for deterministic operations.

    Returns
    -------
    int
        The seed that was set.
    z& is not in bounds, numpy accepts from z to zSetting seed to SB_GLOBAL_SEEDr   NT)min_seed_valuemax_seed_valueloggerinfostrosenvironrandomr   numpyImportErrortorchmanual_seedcudamanual_seed_alluse_deterministic_algorithms)r   r   r   np r   J/home/ubuntu/.local/lib/python3.10/site-packages/speechbrain/utils/seed.pyseed_everything   s(   


r   )r   TF)__doc__r   r   r   speechbrain.utils.loggerr   __name__r
   r	   r   intboolr   r   r   r   r   <module>   s$    