
    <Цiw                     N   S SK JrJrJrJrJrJr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\R2                  S\\	\\R6                  4      S\S	\\R2                  S4   4S jj5       r\ SS\S\\	\\R6                  4      S\S	\\   4S jj5       rSS jr SS\\S4   S\\\\4      S\\	\\R6                  4      S\S	\\\S4   \\\\4   S4   4   4
S jjrSS\S\	\\R6                  4   S\S	\4S jjrg)    )	AnyDictListOptionaloverloadSequenceTupleTypeVarUnion)
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    _/var/www/html/ai-image-ml/venv/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            r   c                     g r   r'   r(   s      r   r   r   )   r)   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      (       a/  [        [        TU 5      6  Vs/ s H  n[        U 5      " U6 PM     sn$ [        U [        5      (       a*  [        U 5      S:  a  [        [        [        TU 5      6 5      $ [        U [        5      (       a;  [        U 5      S:  a,  [        [        TU 5      6  Vs/ s H  n[        U5      PM     sn$ [        U [        5      (       aO  [        U 5      S:  a@  [        [        TU R                  5       5      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 )Nr   )r   torchTensorr   applyr   zipmaptyper    lenlistdictitems)r   argsi_r%   scatter_mapr$   s       r   r:   scatter.<locals>.scatter_map8   s;   c5<<((==dC==#14c+s6K1LM1LDIt$1LMMc5!!c#hlSc2344c4  SX\%(#k3*?%@A%@DG%@AAc4  SX\*-s;		/L*MN*MQDIaL*MNN()[[)) N BN)s   E>0FF0FNr'   )r#   r$   r%   resr:   s    `` @r   r   r   2   s*    *$&!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'   .0r9   s     r   	<genexpr>!scatter_kwargs.<locals>.<genexpr>[          
L1BL   c              3   &   #    U  H  n0 v   M	     g 7fr   r'   rA   s     r   rC   rD   _   rE   rF   )r   r3   extendranger    )r#   r>   r$   r%   scattered_inputsscattered_kwargss         r   r   r   Q   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 6 5      5      $ [        T5      " [        T[        T 6 5      5      $ )Nr   c              3   R   >#    U  H  n[        T5      [        U5      :H  v   M     g 7fr   )r3   )rB   douts     r   rC   -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'   )rB   krQ   
gather_maprL   s      r   rC   rS      s-     Ss!7,C7aqT7,C!DEs,Cs   1,1)r   r-   r.   r   r/   r5   all
ValueErrorr2   r   _maker1   r0   )rL   rR   r%   rV   rM   s   `@r   rV   gather.<locals>.gather_mapv   s    ajc5<<((<<s=W==;c4  ;7;;; !NOO9SsSSS#9??3z3=#ABBCyZg788r   Nr'   )rL   rM   r%   r<   rV   s    `` @r   r   r   e   s*    "9 !
J 
r=   ).)r   ) typingr   r   r   r   r   r   r	   r
   r   typing_extensionsr   r-   torch.nn.parallel._functionsr   r   __all__FutureWarningboolr   r   r5   r4   r    r"   r.   intdevicer   strr   r   r'   r   r   <module>rd      s   W W W (  8 2 Is t 	
   CtU# 
 LL%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   