
    ΅ih                     2   S SK Jr  S SKJrJrJr  S SKJr  S SKrS SK	J
r
Jr  / SQr\" S\S9S	\S
\4S j5       rS	\S
\4S jr\" S\\\5      r\ SS\R*                  S\\\R.                  -     S\S
\\R*                  S4   4S jj5       r\ SS\S\\\R.                  -     S\S
\\   4S jj5       rSS jr SS\\S4   S\\\4   S-  S\\\R.                  -     S\S
\\\S4   \\\\4   S4   4   4
S jjrSS\S\\R.                  -  S\S
\4S jjrg)    )Sequence)AnyoverloadTypeVar)
deprecatedN)GatherScatter)scatterscatter_kwargsgatherzC`is_namedtuple` is deprecated, please use the python checks instead)categoryobjreturnc                     [        U 5      $ N)_is_namedtupler   s    Z/home/james-whalen/.local/lib/python3.13/site-packages/torch/nn/parallel/scatter_gather.pyis_namedtupler      s     #    c                 n    [        U [        5      =(       a    [        U S5      =(       a    [        U S5      $ )N_asdict_fields)
isinstancetuplehasattrr   s    r   r   r      s+     	3V73	#:VwsI?Vr   T.inputstarget_gpusdimc                     g r    r   r   r    s      r   r
   r
   !   s    
  #r   c                     g r   r"   r#   s      r   r
   r
   )   s    
 r   c                 @   ^^^ UUU4S jm T" U 5      nSmU$ ! Smf = f)zSlice tensors into approximately equal chunks and distributes them across given GPUs.

Duplicates references to objects that are not tensors.
c                 <  > [        U [        R                  5      (       a  [        R                  " TS TU 5      $ [        U 5      (       a2  [        [        TU 5      SS06 Vs/ s H  n[        U 5      " U6 PM     sn$ [        U [        5      (       a-  [        U 5      S:  a  [        [        [        TU 5      SS065      $ [        U [        5      (       a>  [        U 5      S:  a/  [        [        TU 5      SS06 Vs/ s H  n[        U5      PM     sn$ [        U [        5      (       aR  [        U 5      S:  aC  [        [        TU R                  5       5      SS06 Vs/ s H  n[        U 5      " U5      PM     sn$ T Vs/ s H  o0PM     sn$ s  snf s  snf s  snf s  snf )NstrictFr   )r   torchTensorr	   applyr   zipmaptyper   lenlistdictitems)r   argsi_r    scatter_mapr   s       r   r5   scatter.<locals>.scatter_map7   sr   c5<<((==dC==#  [#!6EuE FD S	4 E 
 c5!!c#hlSc2A5ABBc4  SX\%(#k3*?%N%NO%NDG%NOOc4  SX\ c+syy{;JEJ KA S	!J 
 ))[[))# P
 *s   !F
9FF<FNr"   )r   r   r    resr5   s    `` @r   r
   r
   1   s*    *8&!J     kwargsc           	         U (       a  [        XU5      O/ nU(       a  [        XU5      O/ n[        U5      [        U5      :  a7  UR                  S [        [        U5      [        U5      -
  5       5       5        ON[        U5      [        U 5      :  a6  UR                  S [        [        U5      [        U5      -
  5       5       5        [	        U5      [	        U5      4$ )z+Scatter with support for kwargs dictionary.c              3   &   #    U  H  nS v   M	     g7f)r"   Nr"   .0r4   s     r   	<genexpr>!scatter_kwargs.<locals>.<genexpr>d          
L1BL   c              3   &   #    U  H  n0 v   M	     g 7fr   r"   r<   s     r   r>   r?   h   r@   rA   )r
   r.   extendranger   )r   r9   r   r    scattered_inputsscattered_kwargss         r   r   r   Z   s     =CwvC8<BwvC8
s#344  
c"23c:J6KKL 
 	
 
	V	,  
c"23c:J6KKL 
 	
 !"E*:$;;;r   outputstarget_devicec                 @   ^^^ UUU4S jm T" U 5      nSmU$ ! Smf = f)am  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           
        >^ ^ T S   m[        T[        R                  5      (       a  [        R                  " TT/T Q76 $ Tc  g [        T[
        5      (       aA  [        U4S jT  5       5      (       d  [        S5      e[        T5      " UU 4S jT 5       5      $ [        T5      (       a-  [        T5      R                  [        T[        T SS065      5      $ [        T5      " [        T[        T SS065      5      $ )Nr   c              3   R   >#    U  H  n[        T5      [        U5      :H  v   M     g 7fr   )r.   )r=   douts     r   r>   -gather.<locals>.gather_map.<locals>.<genexpr>   s     ;7as3x3q6)7s   $'z+All dicts must have the same number of keysc           	   3   f   >#    U  H!  oT" T Vs/ s H  o"U   PM	     sn5      4v   M#     g s  snf 7fr   r"   )r=   krL   
gather_maprG   s      r   r>   rN      s-     Ss!7,C7aqT7,C!DEs,Cs   1,1r'   T)r   r(   r)   r   r*   r0   all
ValueErrorr-   r   _maker,   r+   )rG   rM   r    rQ   rH   s   `@r   rQ   gather.<locals>.gather_map   s    ajc5<<((<<s=W==;c4  ;7;;; !NOO9SsSSS#9??3z33M3M#NOOCyZg)Cd)CDEEr   Nr"   )rG   rH   r    r7   rQ   s    `` @r   r   r   n   s+    "F&!
J 
r8   ).)r   )collections.abcr   typingr   r   r   typing_extensionsr   r(   torch.nn.parallel._functionsr   r	   __all__FutureWarningboolr   r   r0   r/   r   r   r)   intdevicer
   strr   r   r"   r   r   <module>r`      s   $ ) ) (  8 2 Is t 	
   CtU# 
 #LL##,-# 
# 5<<	# 
# 
 #,- 
 
!W	 
&Z 	<#s(O<cNT!< #,-< 
	<
 5c?E$sCx.#"5667<((C (ell(: ( (S (r   