
    ȅi                     h   S SK r S SKrS SKJr  S SKr/ SQrS rS rS r	S r
S rS\R                  \\R                     -  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                     -  S-  S\S\S\\R                   R"                     S-  S\\R                     S-  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)
all_reducereduce	broadcast
all_gatherreduce_scatterc                 ^   [        [        R                  S5      (       d  [        R                  " SSS9  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 support   
stacklevelFT)hasattrtorch_Cwarningswarnset	is_sparseis_contiguousis_cuda
get_deviceadd)tensorsdevicestensordevices       I/home/james-whalen/.local/lib/python3.13/site-packages/torch/cuda/nccl.pyis_availabler      s    588/00AaP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_idr1   8   s    88##%%r   c                 B    [         R                  R                  XU5      $ r.   )r   r   _nccl_init_rank)	num_ranksuidranks      r   	init_rankr7   <   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)r8   s    r   _check_sequence_typerA   @   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.   )rA   r   r   r
   r8   outputsopstreamscommss        r   r   r   G   s2     !	HHfrEBr   )rD   outputrootrE   rF   rD   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.r   r   z\nccl.reduce with an output tensor list is deprecated. Please specify a single output tensor.)rA   
ValueErrorr   r   FutureWarningr;   r   r?   r<   r=   r   r   _nccl_reduce)r8   rH   rI   rE   rF   rG   rD   _outputs           r   r   r   Q   s      Y  MM`	 mG--*((3 3 	5		
 ,"(.&,f	HH&4WDr   c                 Z    [        U 5        [        R                  R                  XX#5        g r.   )rA   r   r   _nccl_broadcast)r8   rI   rF   rG   s       r   r   r   |   s       	HHV7:r   c                 p    [        U 5        [        U5        [        R                  R                  XX#5        g r.   )rA   r   r   _nccl_all_gather)r8   rD   rF   rG   s       r   r   r      s(      !	HHfw>r   c                 r    [        U 5        [        U5        [        R                  R                  XX#U5        g r.   )rA   r   r   _nccl_reduce_scatterrC   s        r   r   r      s*      !	HH!!&2Fr   )r   NN)NN)r<   r   collections.abcr   
torch.cudar   __all__SUMr   r,   r1   r7   r?   rA   r   intcudaStreamr   r   r   r   r0   r   r   <module>r\      s     $  P*-*&:D0F!F D4 D  $T C <@26
(E .2(EU\\"(ELL8ELL11D8(E (E 		(E
 ejj''(4/(E ell#d*(E 
(EX HL;U\\";*-;	; 
	?U\\"?ell#?
 
? 
	GU\\"	Gell#	G 		G 
	Gr   