
    Pi                     h    d dl Z d dlZd dlmZ dedej        dedededefdZdeeef         fd	Z	dS )
    Nseedgenerator_rankrank
world_sizeepochreturnc                     |                     | |z  |z              t          t          j        dd|dz   f|          d                                                   S )Nr   l       )size	generator)manual_seedinttorchrandintitem)r   r   r   r   r   s        r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchdata/nodes/samplers/utils.py_get_rank_seedr      sY    tj047888u}Q519,.YYYZ\]bbddeee    c                     t          j                    r:t          j                    r't          j                    t          j                    }} ntt
          j                            dd          }t
          j                            dd          }	 t          |          } t          |          }n# t          $ r d} d}Y nw xY w| |k    s| dk     rt          d|  d|dz
   d	          | |fS )
av  
    Returns the rank and world size of the current process.
    If distributed is initialized, returns the rank and world size from the distributed environment.
    If distributed is not initialized, returns the rank and world size from the environment variables.
    If neither distributed nor environment variables are set, returns a rank of 0 and a world size of 1.
    RANK0
WORLD_SIZE1r   r
   zInvalid rank z%, rank should be in the interval [0, ])
distis_availableis_initializedget_rankget_world_sizeosenvirongetr   
ValueError)r   r   _rank_world_sizes       r   get_rank_and_world_sizer'      s      
t244 
=??D,?,A,Aj
vs++jnn\377	u::D[))JJ 	 	 	DJJJ	 zTAXXeeeT^abTbeeefffs   B. .B?>B?)
r!   r   torch.distributeddistributedr   r   	Generatorr   tupler'    r   r   <module>r-      s    
			             f feo fS fVY fbe fjm f f f f
sCx      r   