
    #i                        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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/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/sentence_transformers/util/environment.py	<genexpr>z-suggest_extra_on_exception.<locals>.<genexpr>#   s     0290s   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5 	pNHd0x00d1gQ 00`ae`fghnoo	p 	s*   B
 BB9B0BBBc                    t         j                  j                         rdt        j                  v rt        t        j                  d         } n|t         j                  j                         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)torchcudais_availableosenvironintdistributedis_initializeddevice_countget_rankbackendsr&   r   hasattrr(   	importlibutil	find_spechabana_frameworks.torch.hpur*   )
local_rankhthpus     r   get_device_namer>   (   s     zz 2::%RZZ56J--/EJJ4K4K4MPUPaPaPjPjPl4l**335JJzl##				(	(	*		!		599#9#9#;		!	!"5	6	B33    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_availabilityrF   H   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rF   r   r?   r   is_accelerate_availablerK   T   s     &lMBBr?   c                     t        dd      S )zH
    Returns True if the Huggingface datasets library is available.
    datasetsrI   rJ   r   r?   r   is_datasets_availablerN   [   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.
    )rK   rN   r   r?   r   is_training_availablerP   b   s    
 #$@)>)@@r?   )returnzGenerator[None, None, None])rQ   r   )rB   r   rC   r   rQ   bool)rQ   rR   )
__future__r   
contextlibr8   loggingr/   collections.abcr   importlib.metadatar   r   r,   transformersr   	getLogger__name__loggerr   __annotations__contextmanagerr#   r>   rF   rK   rN   rP   r   r?   r   <module>r^      sy    "    	 % =  /			8	$> :  	 	@	CAAr?   