o
    pia                  	   @   sj   d Z ddlZddlZddlZddlmZm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_rankrank_prefixed_message)
get_loggerl    TFseedverbosedeterministicreturnc                 C   s   t  du rdnt  }t|   krtks%n t|  dt dt  |} n| |7 } |r7tjtd|  dd t| tjd< t	
|  zddl}|j	
|  W n	 tyX   Y nw t|  tj|  |rktd	 | S )
a  Function that sets the seed for pseudo-random number generators in: torch, numpy, and Python's random module.

    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.
    Nr   z& is not in bounds, numpy accepts from z to zSetting seed to F)main_process_onlySB_GLOBAL_SEEDT)r   min_seed_valuemax_seed_valueloggerinfor   strosenvironrandomr   numpyImportErrortorchmanual_seedcudamanual_seed_alluse_deterministic_algorithms)r   r   r   seed_offsetnp r   T/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/speechbrain/utils/seed.pyseed_everything   s2   


r   )r   TF)__doc__r   r   r   speechbrain.utils.distributedr   r   speechbrain.utils.loggerr   __name__r   r   r   intboolr   r   r   r   r   <module>   s&    