
    [Th                        S SK r S SKrS SKJr  S SKJrJr  S SKr/ SQr	S r
S rS rS rS rS	\\R                  \\R                     4   S
S4S jrS\
SS4S jrSS \
SS4SS.S	\\R                     S\\\R                  \\R                     4      S\S\S\\\R&                  R(                        S\\\R                        S
S4S jjjr SS	\\R                     S\S
S4S jjr  SS	\\R                     S\\R                     S
S4S jjr\
SS4S	\\R                     S\\R                     S\S
S4S jjrg)    N)Sequence)OptionalUnion)
all_reducereduce	broadcast
all_gatherreduce_scatterc                 `   [        [        R                  S5      (       d  [        R                  " S5        g[        5       nU  Hh  nUR                  (       a    gUR                  5       (       d    gUR                  (       d    gUR                  5       nX1;   a    gUR                  U5        Mj     g)N_nccl_all_reducez)PyTorch is not compiled with NCCL supportFT)hasattrtorch_Cwarningswarnset	is_sparseis_contiguousis_cuda
get_deviceadd)tensorsdevicestensordevices       G/var/www/auris/envauris/lib/python3.13/site-packages/torch/cuda/nccl.pyis_availabler      s    588/00ABeG##%%~~""$F      c                      [         R                  R                  5       n U S-	  nU S-	  S-  nU S-  n[         R                  R                  5       R	                  S5      nUS:X  a  XU4$ XX44$ )a  
Returns the version of the NCCL.


This function returns a tuple containing the major, minor, and patch version numbers of the NCCL.
The suffix is also included in the tuple if a version suffix exists.
Returns:
    tuple: The version information of the NCCL.
       i  zutf-8 )r   r   _nccl_version_nccl_version_suffixdecode)vermajorminorpatchsuffixs        r   versionr+   $   sp     ((
 
 
"C2IEBY%E%KEXX**,33G<F|e$$e,,r   c                  >    [         R                  R                  5       $ N)r   r   _nccl_unique_id r   r   	unique_idr0   9   s    88##%%r   c                 B    [         R                  R                  XU5      $ r-   )r   r   _nccl_init_rank)	num_ranksuidranks      r   	init_rankr6   =   s    88##ID99r   inputsreturnc                     [        U [        R                  R                  5      (       a  [        U [        R
                  5      (       a  [        S5      eg )Nz(Inputs should be a collection of tensors)
isinstancecollectionsabc	Containerr   Tensor	TypeError)r7   s    r   _check_sequence_typer@   A   sA    fkoo7788J= = BCC=r   c                 |    [        U 5        Uc  U n[        U5        [        R                  R                  XX#U5        g r-   )r@   r   r   r   r7   outputsopstreamscommss        r   r   r   H   s2     !	HHfrEBr   )rC   outputrootrD   rE   rC   c                   [        U 5        Ub-  Ub  [        S5      e[        R                  " S[        SS9  Xb   nOp[        U[        R                  5      (       dH  [        U[        R                  R                  5      (       a  [        R                  " S[        SS9  X   nO	Uc  X   OUn[        R                  R                  XX#XE5        g )Nz'output' and 'outputs' can not be both specified. 'outputs' is deprecated in favor of 'output', taking in a single output tensor. The signature of reduce is: reduce(inputs, output=None, root=0, op=SUM, streams=None, comms=None).z`nccl.reduce` with an output tensor list is deprecated. Please specify a single output tensor with argument 'output' instead instead.   )
stacklevelz\nccl.reduce with an output tensor list is deprecated. Please specify a single output tensor.)r@   
ValueErrorr   r   FutureWarningr:   r   r>   r;   r<   r   r   _nccl_reduce)r7   rG   rH   rD   rE   rF   rC   _outputs           r   r   r   R   s      Y  MM`	 mG--*((3 3 	5		
 ,"(.&,f	HH&4WDr   c                 Z    [        U 5        [        R                  R                  XX#5        g r-   )r@   r   r   _nccl_broadcast)r7   rH   rE   rF   s       r   r   r   }   s       	HHV7:r   c                 p    [        U 5        [        U5        [        R                  R                  XX#5        g r-   )r@   r   r   _nccl_all_gather)r7   rC   rE   rF   s       r   r	   r	      s(      !	HHfw>r   c                 r    [        U 5        [        U5        [        R                  R                  XX#U5        g r-   )r@   r   r   _nccl_reduce_scatterrB   s        r   r
   r
      s*      !	HH!!&2Fr   )r   NN)NN)r;   r   collections.abcr   typingr   r   
torch.cudar   __all__SUMr   r+   r0   r6   r>   r@   r   intcudaStreamr   r   r	   r
   r/   r   r   <module>r^      s     $ "  P*-*&:Du||Xell5K'K!L DQU D  $T C EI59
(E 15(EU\\"(EU5<<%,,)??@A(E (E 		(E
 huzz0012(E hu||,-(E 
(EX HL;U\\";*-;	; 
	?U\\"?ell#?
 
? 
	GU\\"	Gell#	G 		G 
	Gr   