
    Pim                         U d dl Z d dlZd dlZd dlmZmZ d dlZd dlZd dl	m
Z
 d dlmZmZ  e            Ze j        ed<   	 d
dee         deeeef                  defd	ZdS )    N)OptionalUnion)_broadcast_tensor)
get_loggerget_world_size_and_rank_logseed
debug_modereturnc           	      8   t                      \  }}t          j        t          j                  j        |z
  dz   }t          j        t          j                  j        }| 8t          j        ||d          }t          |d          	                                } | |k     s| |k    rt          d|  d| d| d          | |z   }|dk    r#t                              d	| d
|  d|            t          j        |           t          j                            |           t          j        |           |t                              d|            t          j        |           t          j                    }|dk    rGt                              d           dt          j        j        _        dt          j        j        _        nUt                              d           dt          j        j        _        dt          j        j        _        dt,          j        d<   | S )a	  Function that sets seed for pseudo-random number generators across commonly used libraries.

    This seeds PyTorch, NumPy, and the python.random module. For distributed jobs, each local process
    sets its own seed, computed seed + rank.
    For more details, see https://pytorch.org/docs/stable/notes/randomness.html.

    Args:
        seed (Optional[int]): the integer value seed. If `None`, a random seed will be generated and set.
        debug_mode (Optional[Union[str, int]]): Controls debug_mode settings for deterministic operations within PyTorch.

            * If `None`, don't set any PyTorch global values.
            * If "default" or 0, don't error or warn on nondeterministic operations and additionally enable PyTorch CuDNN benchmark.
            * If "warn" or 1, warn on nondeterministic operations and disable PyTorch CuDNN benchmark.
            * If "error" or 2, error on nondeterministic operations and disable PyTorch CuDNN benchmark.
            * For more details, see :func:`torch.set_deterministic_debug_mode` and
              https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms.

    Returns:
        int: the current seed

    Raises:
        ValueError: If the input seed value is outside the required range.
       N)r   r   zInvalid seed value provided: z. Value must be in the range [z, ]z"Setting manual seed to local seed z. Local seed is seed + rank = z + z$Setting deterministic debug mode to z"Disabling cuDNN deterministic modeFTz!Enabling cuDNN deterministic modez:4096:8CUBLAS_WORKSPACE_CONFIG)r   npiinfouint32maxmintorchrandintr   item
ValueErrorr   debugmanual_seedrandomr	   set_deterministic_debug_modeget_deterministic_debug_modebackendscudnndeterministic	benchmarkosenviron)	r	   r
   
world_sizerankmax_valmin_val	rand_seed
local_seeddeterministic_debug_modes	            k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/training/seed.pyset_seedr,      s   4 /00Jhry!!%
2Q6Ghry!!%G|M'7D99	 A..3355g~~eDeePWee[beee
 
 	
 Jqyy

jjj[_jjdhjj	
 	
 	
 
j!!!INN:
K


F*FFGGG*:666#(#E#G#G #q((JJ;<<<16EN .-1EN **JJ:;;;15EN .-2EN *4=BJ01K    )NN)loggingr"   r   typingr   r   numpyr   r   torchtune.training._distributedr   torchtune.utilsr   r   r   Logger__annotations__intstrr,    r-   r+   <module>r8      s     				  " " " " " " " "      = = = = = = ? ? ? ? ? ? ? ?!z||gn # # # IM= =
3-=,4U38_,E== = = = = =r-   