ó
    >:jü	  ã                  ól   • S SK Jr  S SKrS SKJr  S SKJr  \R                  " \	5      r
SSS jjrSS jrg)	é    )ÚannotationsN)Úloggingc                ó  • [         R                  " 5       (       aÓ  [         R                  " 5       (       a¹  U(       a*  [        R                  R
                  R                  U 5      nOs[         R                  " 5       n[        U5       Vs/ s H  n[        R                  " U 5      PM     nn[         R                  " X 5        [         R                  " 5       nXU'   [        R                  " USS9$ Sn[        R                  U5        U $ s  snf )aL  
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          Úc/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sentence_transformers/util/distributed.pyr   r      sÒ   € ô ×Ò×Ñœt×2Ò2×4Ñ4ÞÜ$×0Ñ0×3Ñ3×>Ñ>¸vÓFÑä×,Ò,Ó.ˆJÜBGÈ
ÔBSÓTÒBS¸Q¤× 0Ò 0°Ö 8ÑBSÐÐTô �OŠOÐ,Ô5ô Ÿš›ˆJØ+1˜ZÑ(Ü�yŠyÐ)¨qÑ1Ð1ð	Sð ô
 ×Ñ˜Ô Ø€Mùò#  Us   Â Dc                ó   • [        U SS9$ )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)      s.   ðÝ "ã Ý  Ý &ð 
×	Ò	˜HÓ	%€ö$õN.r   