
    BNj                        U d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlZd dlmZ  ej                  e      Zg dZded<   ej&                  dd	       Zdd
ZddZddZddZddZddZy)    )annotationsN)	Generator)PackageNotFoundErrormetadata)is_torch_npu_available)))pillowpil-pip install -U "sentence-transformers[image]"))
read_videozQpip install -U "sentence-transformers[video]"  # or [audio] for audio-only models))torchvisionr
   ))
torchcodeczpip install -U torchcodec))	soundfilelibrosaz-pip install -U "sentence-transformers[audio]"z!list[tuple[tuple[str, ...], str]]_DEPENDENCY_EXTRA_HINTSc               #    K   	 d y# t         t        f$ ro} t        |       j                         t        D ]G  \  }}t        fd|D              s t        |       t        |       j                          d|       |   d} ~ ww xY ww)zaRe-raise ImportError/AttributeError with an install hint when a multimodal dependency is missing.Nc              3  &   K   | ]  }|v  
 y w)N ).0kwmsgs     w/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/sentence_transformers/util/environment.py	<genexpr>z-suggest_extra_on_exception.<locals>.<genexpr>#   s     0x29xs   z-

To install the required dependencies, run:
)ImportErrorAttributeErrorstrlowerr   anytypestrip)ekeywordshintr   s      @r   suggest_extra_on_exceptionr#      s     ( !flln5NHd0x00d1gQ 00`ae`fghnoo 6 	s*   B
 BB9B0BBBc                 ~    t         j                  j                         xr t         j                  j                         S )aP  
    Returns whether ``torch.distributed`` is available and has been initialized.

    The availability check must come first: some PyTorch builds (e.g. ROCm or CPU-only) report
    ``torch.distributed.is_available() == False`` and do not expose APIs like ``is_initialized``, so calling
    them directly raises ``AttributeError``.
    )torchdistributedis_availableis_initializedr       r   is_dist_initializedr*   (   s-     ))+R0A0A0P0P0RRr)   c                    t         j                  j                         rdt        j                  v rt        t        j                  d         } nht               r\t         j                  j                         t         j                  j                         kD  rt         j                  j                         } nd} d|  S t         j                  j                  j                         ryt               ryt        t         d      rt         j                  j                         ryt        j                   j#                  d      ddlm c m} |j                         ry	y
)aV  
    Returns the name of the device where this module is running on.

    This function only supports single device or basic distributed training setups.
    In distributed mode for cuda device, it uses the rank to assign a specific CUDA device.

    Returns:
        str: Device name, like 'cuda:2', 'mps', 'npu', 'xpu', 'hpu', or 'cpu'
    
LOCAL_RANKr   zcuda:mpsnpuxpuhabana_frameworksNhpucpu)r%   cudar'   osenvironintr*   device_countr&   get_rankbackendsr-   r   hasattrr/   	importlibutil	find_spechabana_frameworks.torch.hpur1   )
local_rankhthpus     r   get_device_namerA   3   s     zz 2::%RZZ56J "uzz'>'>'@5CTCTC]C]C_'_**335JJzl##				(	(	*		!		599#9#9#;		!	!"5	6	B33r)   c                j    	 t        |       }|d   }|d   | k(  xr
 |duxr ||v S # t        $ r Y yw xY w)zB
    Checks if a package is available from the correct owner.
    z	Home-pageNameNF)r   r   )package_nameownermeta	home_pages       r   check_package_availabilityrH   S   sQ    %%	F||+\	0E\%S\J\\ s   #& 	22c                     t        dd      S )zJ
    Returns True if the Huggingface accelerate library is available.
    
acceleratehuggingfacerH   r   r)   r   is_accelerate_availablerM   _   s     &lMBBr)   c                     t        dd      S )zH
    Returns True if the Huggingface datasets library is available.
    datasetsrK   rL   r   r)   r   is_datasets_availablerP   f   s     &j-@@r)   c                 .    t               xr
 t               S )z
    Returns True if we have the required dependencies for training Sentence
    Transformers models, i.e. Huggingface datasets and Huggingface accelerate.
    )rM   rP   r   r)   r   is_training_availablerR   m   s    
 #$@)>)@@r)   )returnzGenerator[None, None, None])rS   bool)rS   r   )rD   r   rE   r   rS   rT   )
__future__r   
contextlibr;   loggingr4   collections.abcr   importlib.metadatar   r   r%   transformersr   	getLogger__name__loggerr   __annotations__contextmanagerr#   r*   rA   rH   rM   rP   rR   r   r)   r   <module>r`      s    "    	 % =  /			8	$> :  	 	S@	CAAr)   