
    rh7	                        d dl mZ d dlZd dlZd dlZd dlmZmZ d dlZd dl	m
Z
  ej                  e      Zd
dZddZddZddZdd	Zy)    )annotationsN)PackageNotFoundErrormetadata)is_torch_npu_availablec                 z   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        j                  j                  d      ddlm c m} |j                         ryy	)
aO  
    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', 'hpu', or 'cpu'
    
LOCAL_RANKr   zcuda:mpsnpuhabana_frameworksNhpucpu)torchcudais_availableosenvironintdistributedis_initializeddevice_countget_rankbackendsr	   r   	importlibutil	find_spechabana_frameworks.torch.hpur   )
local_rankhthpus     y/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/sentence_transformers/util/environment.pyget_device_namer       s     zz 2::%RZZ56J--/EJJ4K4K4MPUPaPaPjPjPl4l**335JJzl##				(	(	*		!		!	!"5	6	B33    c                Z    	 t        |       }|d   | k(  xr ||d   v S # t        $ r Y yw xY w)zB
    Checks if a package is available from the correct owner.
    Namez	Home-pageF)r   r   )package_nameownermetas      r   check_package_availabilityr'   ,   sA    %F||+Jk9J0JJ s    	**c                     t        dd      S )zJ
    Returns True if the Huggingface accelerate library is available.
    
acceleratehuggingfacer'    r!   r   is_accelerate_availabler-   7   s     &lMBBr!   c                     t        dd      S )zH
    Returns True if the Huggingface datasets library is available.
    datasetsr*   r+   r,   r!   r   is_datasets_availabler0   >   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.
    )r-   r0   r,   r!   r   is_training_availabler2   E   s    
 #$@)>)@@r!   )returnstr)r$   r4   r%   r4   r3   bool)r3   r5   )
__future__r   r   loggingr   importlib.metadatar   r   r   transformersr   	getLogger__name__loggerr    r'   r-   r0   r2   r,   r!   r   <module>r=      sH    "   	 =  /			8	$<CAAr!   