
    QVjiw                     ~   d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
Z
d dlmZmZ g dZ e	de          d	ed
efd            Zd	ed
efdZ edeee          Ze	 dde
j        deeee
j        f                  ded
ee
j        df         fd            Ze	 ddedeeee
j        f                  ded
ee         fd            ZddZ	 ddeedf         deeeef                  deeee
j        f                  ded
eeedf         eeeef         df         f         f
dZddedeee
j        f         ded
efdZdS )    )Sequence)AnyOptionaloverloadTypeVarUnion)
deprecatedN)GatherScatter)scatterscatter_kwargsgatherzC`is_namedtuple` is deprecated, please use the python checks instead)categoryobjreturnc                      t          |           S N)_is_namedtupler   s    Z/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/nn/parallel/scatter_gather.pyis_namedtupler      s     #    c                 l    t          | t                    ot          | d          ot          | d          S )N_asdict_fields)
isinstancetuplehasattrr   s    r   r   r      s4     	3V73	#:#:VwsI?V?Vr   T.inputstarget_gpusdimc                     d S r    r    r!   r"   s      r   r   r   !   s	    
  #sr   c                     d S r   r$   r%   s      r   r   r   )   s	    
 cr   c                 F    fd	  |           }dn# dw xY w|S )zSlice tensors into approximately equal chunks and distributes them across given GPUs.

    Duplicates references to objects that are not tensors.
    c                     t           t          j                  rt          j        d            S t                     r# fdt          t                      D             S t           t                    r7t                     dk    r$t          t          t                                S t           t                    r4t                     dk    r!d t          t                      D             S t           t                    rHt                     dk    r5 fdt          t                                                      D             S  fdD             S )Nc                 4    g | ]} t                    | S r$   type).0argsr   s     r   
<listcomp>z0scatter.<locals>.scatter_map.<locals>.<listcomp>;   s&    MMMIDIIt$MMMr   r   c                 ,    g | ]}t          |          S r$   )list)r,   is     r   r.   z0scatter.<locals>.scatter_map.<locals>.<listcomp>?   s    AAADGGAAAr   c                 @    g | ]} t                    |          S r$   r*   )r,   r1   r   s     r   r.   z0scatter.<locals>.scatter_map.<locals>.<listcomp>A   s'    NNNQIDIIaLLNNNr   c                     g | ]}S r$   r$   )r,   _r   s     r   r.   z0scatter.<locals>.scatter_map.<locals>.<listcomp>B   s    ))))))r   )r   torchTensorr   applyr   zipmapr   lenr0   dictitems)r   r"   scatter_mapr!   s   `r   r=   zscatter.<locals>.scatter_map7   sU   c5<(( 	>=dC===# 	NMMMMc+s6K6K1LMMMMc5!! 	5c#hhllSc223444c4   	BSXX\\AAS#k3*?*?%@AAAAc4   	OSXX\\NNNN#s;		/L/L*MNNNN))))[))))r   Nr$   )r    r!   r"   resr=   s    `` @r   r   r   1   sY    * * * * * * *$k&!!dJ    kwargsc           	      8   | rt          | ||          ng }|rt          |||          ng }t          |          t          |          k     rJ|                    d t          t          |          t          |          z
            D                        nit          |          t          |           k     rI|                    d t          t          |          t          |          z
            D                        t	          |          t	          |          fS )z+Scatter with support for kwargs dictionary.c              3      K   | ]}d V  dS )r$   Nr$   r,   r4   s     r   	<genexpr>z!scatter_kwargs.<locals>.<genexpr>Z   3        
  
B 
  
  
  
  
  
r   c              3      K   | ]}i V  d S r   r$   rC   s     r   rD   z!scatter_kwargs.<locals>.<genexpr>^   rE   r   )r   r:   extendranger   )r    r@   r!   r"   scattered_inputsscattered_kwargss         r   r   r   P   s@    =CJwv{C888<BJwv{C888
s#34444  
  
c"233c:J6K6KKLL 
  
  
 	
 	
 	
 	
 
		V	,	,  
  
c"233c:J6K6KKLL 
  
  
 	
 	
 	
 !""E*:$;$;;;r   outputstarget_devicec                 F    fd	  |           }dn# dw xY w|S )a  Gather tensors from different GPUs on a specified device.

    This function is useful for gathering the results of a distributed computation.
    It takes a sequence of objects, one for each GPU, and returns a single object
    on the specified device.

    Args:
        outputs (Any): A sequence of objects (potentially tensors) to gather.
        target_device (Union[int, torch.device]): The device to gather the tensors to.
            Use 'cpu' for CPU to avoid a deprecation warning.
        dim (int, optional): The dimension along which to gather. Default: 0.

    Returns:
        Any: A gathered object (potentially tensor) on the specified device.
    c                 (     d         t          t          j                  rt          j        g R  S d S t          t
                    rOt          fd D                       st          d           t                     fdD                       S t                    r7t                    
                    t          t                                S  t                    t          t                                S )Nr   c              3   X   K   | ]$}t                    t          |          k    V  %d S r   )r:   )r,   douts     r   rD   z-gather.<locals>.gather_map.<locals>.<genexpr>|   s4      ;;as3xx3q66);;;;;;r   z+All dicts must have the same number of keysc              3   L   K   | ] fd D                       fV  dS )c                      g | ]
}|         S r$   r$   )r,   rP   ks     r   r.   z8gather.<locals>.gather_map.<locals>.<genexpr>.<listcomp>~   s    ,C,C,CaQqT,C,C,Cr   Nr$   )r,   rT   
gather_maprK   s    @r   rD   z-gather.<locals>.gather_map.<locals>.<genexpr>~   sH      SS!a,C,C,C,C7,C,C,C!D!DESSSSSSr   )r   r5   r6   r
   r7   r;   all
ValueErrorr+   r   _maker9   r8   )rK   rQ   r"   rU   rL   s   `@r   rU   zgather.<locals>.gather_mapu   s   ajc5<(( 	><s=W====;4c4   	T;;;;7;;;;; P !NOOO499SSSSSsSSSSSS# 	C99??3z3=#A#ABBBtCyyZg77888r   Nr$   )rK   rL   r"   r>   rU   s    `` @r   r   r   d   sY    "9 9 9 9 9 9 9 j!!

T
Jr?   ).)r   )collections.abcr   typingr   r   r   r   r   typing_extensionsr	   r5   torch.nn.parallel._functionsr
   r   __all__FutureWarningboolr   r   r;   r0   r   r   r6   intdevicer   strr   r   r$   r   r   <module>rc      s   $ $ $ $ $ $ : : : : : : : : : : : : : : ( ( ( ( ( (  8 8 8 8 8 8 8 8 2
1
1 I  s t   	 
      GCtU## 
 # #L#%U\ 123# 
# 5<	# # # 
# 
  %U\ 123 
 
!W	   
   F 	< <#s(O<T#s(^$< %U\ 123< 
	<
 5c?E$sCx.#"5667< < < <(% %C %c5<.?(@ %s %SV % % % % % %r   