o
    /ôjÆ  ã                   @   sn  d dl Z d dlZd dlmZmZmZ d dlZg d¢Zd Z	dd„ Z
dd„ Zdd	„ Zd
d„ Zdeejeej f ddfdd„Zde	ddfdd„Zdd e	ddfddœdeej deeejeej f  dededeeejj  deeej  ddfdd„Z	d deej deddfdd„Z		d!deej deej ddfdd„Ze	ddfdeej deej deddfdd„ZdS )"é    N)ÚOptionalÚSequenceÚUnion)Ú
all_reduceÚreduceÚ	broadcastÚ
all_gatherÚreduce_scatterc                 C   st   t tjdƒst d¡ dS tƒ }| D ]%}|jr dS | ¡ s! dS |js' dS | 	¡ }||v r2 dS | 
|¡ qdS )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Údevice© r   ú`/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torch/cuda/nccl.pyÚis_available   s    
r   c                  C   sT   t j ¡ } | d? }| d? d@ }| d@ }t j ¡  d¡}|dkr$|||fS ||||fS )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   Z_nccl_versionZ_nccl_version_suffixÚdecode)ÚverÚmajorÚminorZpatchÚsuffixr   r   r   Úversion#   s   


r%   c                   C   s
   t j ¡ S ©N)r   r   Z_nccl_unique_idr   r   r   r   Ú	unique_id8   s   
r'   c                 C   s   t j | ||¡S r&   )r   r   Z_nccl_init_rank)Z	num_ranksÚuidÚrankr   r   r   Ú	init_rank<   s   r*   ÚinputsÚreturnc                 C   s&   t | tjjƒrt | tjƒrtdƒ‚d S )Nz(Inputs should be a collection of tensors)Ú
isinstanceÚcollectionsÚabcÚ	Containerr   ÚTensorÚ	TypeError)r+   r   r   r   Ú_check_sequence_type@   s
   ÿýr3   c                 C   s4   t | ƒ |d u r
| }t |ƒ tj | ||||¡ d S r&   )r3   r   r   r
   ©r+   ÚoutputsÚopÚstreamsÚcommsr   r   r   r   G   s
   r   )r5   ÚoutputÚrootr6   r7   r5   c                C   sœ   t | ƒ |d ur|d urtdƒ‚tjdtdd� || }n$t|tjƒs7t|tj	j
ƒr7tjdtdd� || }n
|d u r?| | n|}tj | |||||¡ d S )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.)r3   Ú
ValueErrorr   r   ÚFutureWarningr-   r   r1   r.   r/   r   r   Z_nccl_reduce)r+   r9   r:   r6   r7   r8   r5   Z_outputr   r   r   r   Q   s.   
ÿü
ÿü
r   c                 C   s   t | ƒ tj | |||¡ d S r&   )r3   r   r   Z_nccl_broadcast)r+   r:   r7   r8   r   r   r   r   |   s   r   c                 C   s&   t | ƒ t |ƒ tj | |||¡ d S r&   )r3   r   r   Z_nccl_all_gather)r+   r5   r7   r8   r   r   r   r   ƒ   s   r   c                 C   s(   t | ƒ t |ƒ tj | ||||¡ d S r&   )r3   r   r   Z_nccl_reduce_scatterr4   r   r   r   r	   Ž   s   r	   )r   NN)NN)r.   r   Útypingr   r   r   Ú
torch.cudar   Ú__all__ÚSUMr   r%   r'   r*   r1   r3   r   ÚintÚcudaÚStreamr   r   r   r	   r   r   r   r   Ú<module>   s~   "úøÿþýüûø	
÷,ÿÿÿ
þ
üÿþ
ûûÿþýú