Ë
    Têñiü	  ã                  óf   — d dl mZ d dlZd dlmZ d dlmZ  ej                  e	«      Z
ddd„Zdd„Zy)	é    )ÚannotationsN)Úloggingc                óð  — t        j                  «       rÅt        j                  «       r±|r*t        j                  j
                  j                  | «      }nnt        j                  «       }t        |«      D �cg c]  }t        j                  | «      ‘Œ }}t        j                  || «       t        j                  «       }| ||<   t        j                  |d¬«      S d}t        j                  |«       | S c c}w )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.
    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.)ÚdistÚis_availableÚis_initializedÚtorchÚdistributedÚnnÚ
all_gatherÚget_world_sizeÚrangeÚ
zeros_likeÚget_rankÚcatÚloggerÚwarning_once)ÚtensorÚ	with_gradÚgathered_tensorsÚ
world_sizeÚ_Ú
local_rankÚwarnings          úh/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/sentence_transformers/util/distributed.pyr   r      sÎ   € ô ×ÑÔœt×2Ñ2Ô4ÙÜ$×0Ñ0×3Ñ3×>Ñ>¸vÓFÑä×,Ñ,Ó.ˆJÜBGÈ
ÓBSÖT¸Q¤× 0Ñ 0°Õ 8ÐTÐÐTô �O‰OÐ,¨fÔ5ô Ÿ™›ˆJØ+1Ð˜ZÑ(Ü�y‰yÐ)¨qÔ1Ð1ð	Sð ô
 ×Ñ˜Ô Ø€Mùò#  Us   Á6C3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   2   s   € ô �f¨Ô-Ð-ó    )F)r   útorch.Tensorr   ÚboolÚreturnr    )r   r    r"   r    )Ú
__future__r   r
   Útorch.distributedr   r   Útransformers.utilsr   Ú
get_loggerÚ__name__r   r   r   © r   r   ú<module>r)      s0   ðÝ "ã Ý  Ý &ð 
ˆ×	Ñ	˜HÓ	%€ô$ôN.r   