§
    ™Štj
  ã                  óp   — d dl mZ d dlZd dlmZ d dlmZ ddlm	Z	  ej
        e¦  «        Zddd„Zdd„ZdS )é    )ÚannotationsN)Úloggingé   )Úis_dist_initializedFÚtensorútorch.TensorÚ	with_gradÚboolÚreturnc                óŒ  ‡ — t          ¦   «         r˜|r%t          j        j                             ‰ ¦  «        }n[t          j        ¦   «         }ˆ fd„t          |¦  «        D ¦   «         }t          j        |‰ ¦  «         t          j        ¦   «         }‰ ||<   t          j	        |d¬¦  «        S d}t                               |¦  «         ‰ S )ap  
    Gathers a tensor from each distributed rank into a list. Always retains gradients for the local rank's tensor,
    and optionally retains gradients for the gathered tensors if `with_grad` is True.

    Args:
        tensor (torch.Tensor): The tensor to gather from each rank.
        with_grad (bool, optional): If True, the local rank's tensor retains its gradients. Defaults to False.

    Returns:
        torch.Tensor: A tensor containing the gathered tensors from all ranks, concatenated along the first dimension.
        If torch.distributed is not available or not initialized, returns the original tensor.
    c                ó8   •— g | ]}t          j        ‰¦  «        ‘ŒS © )ÚtorchÚ
zeros_like)Ú.0Ú_r   s     €úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sentence_transformers/util/distributed.pyú
<listcomp>zall_gather.<locals>.<listcomp>    s$   ø€ ÐTÐTÐT¸Q¥Ô 0°Ñ 8Ô 8ÐTÐTÐTó    r   )ÚdimzâTrying to gather while torch.distributed is not available or has not been initialized, returning the original (local) tensor. This is expected if you are only using one GPU; consider not using gathering to remove this warning.)r   r   ÚdistributedÚnnÚ
all_gatherÚdistÚget_world_sizeÚrangeÚget_rankÚcatÚloggerÚwarning_once)r   r	   Úgathered_tensorsÚ
world_sizeÚ
local_rankÚwarnings   `     r   r   r      sÑ   ø€ õ ÑÔð 2Øð 	2Ý$Ô0Ô3×>Ò>¸vÑFÔFÐÐåÔ,Ñ.Ô.ˆJØTÐTÐTÐTÅ%È
ÑBSÔBSÐTÑTÔTÐõ ŒOÐ,¨fÑ5Ô5Ð5õ œ™œˆJØ+1Ð˜ZÑ(ÝŒyÐ)¨qÐ1Ñ1Ô1Ð1ð	Sð õ
 ×Ò˜Ñ Ô Ð Ø€Mr   c                ó$   — t          | d¬¦  «        S )a¦  
    Gathers a tensor from each distributed rank into a list, retaining gradients for the local rank's tensor.

    Args:
        tensor (torch.Tensor): The tensor to gather from each rank.

    Returns:
        torch.Tensor: A tensor containing the gathered tensors from all ranks, concatenated along the first dimension.
        If torch.distributed is not available or not initialized, returns the original tensor.
    T)r	   )r   )r   s    r   Úall_gather_with_gradr&   4   s   € õ �f¨Ð-Ñ-Ô-Ð-r   )F)r   r   r	   r
   r   r   )r   r   r   r   )Ú
__future__r   r   Útorch.distributedr   r   Útransformers.utilsr   Úenvironmentr   Ú
get_loggerÚ__name__r   r   r&   r   r   r   ú<module>r-      s¢   ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ø &Ð &Ð &Ð &Ð &Ð &à ,Ð ,Ð ,Ð ,Ð ,Ð ,ð 
ˆÔ	˜HÑ	%Ô	%€ð$ð $ð $ð $ð $ðN.ð .ð .ð .ð .ð .r   