§
    +�’jQ!  ã                  ó2  — 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Zd dlZd dlm	Z	 d dl
mZmZmZ d dlmZ d dlZd dlmZ d dlm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#d$d„Z$d%d&d„Z%dS )'é    )ÚannotationsN)Ú	Generator)ÚPackageNotFoundErrorÚmetadataÚversion)ÚAny)ÚSpecifierSet)ÚVersion)Ú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_HINTSÚreturnúGenerator[None, None, None]c               #  óV  ‡K  — 	 dV — dS # t           t          f$ rŒ} t          | ¦  «                             ¦   «         Št          D ]]\  }}t          ˆfd„|D ¦   «         ¦  «        r= t          | ¦  «        t          | ¦  «                             ¦   «         › d|› �¦  «        | ‚Œ^‚ d} ~ ww xY w)zaRe-raise ImportError/AttributeError with an install hint when a multimodal dependency is missing.Nc              3  ó    •K  — | ]}|‰v V — Œ	d S ©N© )Ú.0ÚkwÚmsgs     €úTC:\Projects\DSCons\.venv\Lib\site-packages\sentence_transformers\util\environment.pyú	<genexpr>z-suggest_extra_on_exception.<locals>.<genexpr>(   s'   øè è € Ð0Ð0 �2˜�9Ð0Ð0Ð0Ð0Ð0Ð0ó    z-

To install the required dependencies, run:
)ÚImportErrorÚAttributeErrorÚstrÚlowerr   ÚanyÚtypeÚstrip)ÚeÚkeywordsÚhintr   s      @r   Úsuggest_extra_on_exceptionr+       sÊ   øè è € ðØˆˆˆˆˆøÝ�Ð(ð ð ð Ý�!‰fŒf�lŠl‰nŒnˆÝ5ð 	pð 	p‰NˆH�dÝÐ0Ð0Ð0Ð0 xÐ0Ñ0Ô0Ñ0Ô0ð pØ•d˜1‘g”g¥ Q¡¤§¢¡¤ÐgÐgÐaeÐgÐgÑhÔhÐnoÐoðpàøøøøðøøøs   … ‹B(œBB#Â#B(Úboolc                 óz   — t           j                             ¦   «         ot           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    r   Úis_dist_initializedr2   -   s-   € õ Ô×)Ò)Ñ+Ô+ÐRµÔ0A×0PÒ0PÑ0RÔ0RÐRr    r#   c                 óÒ  — t           j                             ¦   «         r dt          j        v r t          t          j        d         ¦  «        } nmt          ¦   «         r]t           j                             ¦   «         t           j         	                    ¦   «         k    rt           j         	                    ¦   «         } nd} d| › �S t           j
        j                             ¦   «         rdS t          ¦   «         rdS t          t           d¦  «        r t           j                             ¦   «         rdS t          j                             d¦  «        �ddlm c m} |                     ¦   «         rd	S d
S )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.   Úcudar0   ÚosÚenvironÚintr2   Údevice_countr/   Úget_rankÚbackendsr5   r   Úhasattrr7   Ú	importlibÚutilÚ	find_specÚhabana_frameworks.torch.hpur9   )Ú
local_rankÚhthpus     r   Úget_device_namerI   8   sH  € õ „z×ÒÑ Ô ð Ø�2œ:Ð%Ð%Ý�RœZ¨Ô5Ñ6Ô6ˆJˆJÝ Ñ"Ô"ð 	¥u¤z×'>Ò'>Ñ'@Ô'@Å5ÔCT×C]ÒC]ÑC_ÔC_Ò'_Ð'_ÝÔ*×3Ò3Ñ5Ô5ˆJˆJàˆJØ#�zÐ#Ð#Ð#Ý	ŒÔ	×	(Ò	(Ñ	*Ô	*ð 
ØˆuÝ	Ñ	!Ô	!ð ØˆuÝ	•˜Ñ	Ô	ð ¥5¤9×#9Ò#9Ñ#;Ô#;ð ØˆuÝ	Œ×	!Ò	!Ð"5Ñ	6Ô	6Ð	BØ3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3à×ÒÑÔð 	Ø�5Øˆ5r    Úpackage_nameÚownerc                ó|   — 	 t          | ¦  «        }|d         }|d         | k    o|duo||v S # t          $ r Y dS w xY w)zB
    Checks if a package is available from the correct owner.
    z	Home-pageÚNameNF)r   r   )rJ   rK   ÚmetaÚ	home_pages       r   Úcheck_package_availabilityrP   X   sd   € ðÝ˜Ñ%Ô%ˆØ˜Ô%ˆ	Ø�FŒ|˜|Ò+Ð\°	ÀÐ0EÐ\È%ÐS\ÐJ\Ð\øÝð ð ð Øˆuˆuðøøøs   ‚*- ­
;º;c                 ó"   — t          dd¦  «        S )zJ
    Returns True if the Huggingface accelerate library is available.
    Ú
accelerateÚhuggingface©rP   r   r    r   Úis_accelerate_availablerU   d   s   € õ & l°MÑBÔBÐBr    c                 ó"   — t          dd¦  «        S )zH
    Returns True if the Huggingface datasets library is available.
    ÚdatasetsrS   rT   r   r    r   Úis_datasets_availablerX   k   s   € õ & j°-Ñ@Ô@Ð@r    c                 ó:   — t          ¦   «         ot          ¦   «         S )z 
    Returns True if we have the required dependencies for training Sentence
    Transformers models, i.e. Huggingface datasets and Huggingface accelerate.
    )rU   rX   r   r    r   Úis_training_availablerZ   r   s   € õ
 #Ñ$Ô$Ð@Õ)>Ñ)@Ô)@Ð@r    ú
str | Nonec                ó,  — | dk    rt          j        ¦   «         S t          j                             |                      dd¦  «        ¦  «        }t          t          |dd¦  «        x}t          ¦  «        r|S 	 t          | ¦  «        S # t          $ r Y dS w xY w)a  
    Returns the version of an installed package, or None if the package can't be found.

    The ``__version__`` of an already imported module takes precedence over the distribution
    metadata, as the metadata of editable installs lags behind the code that actually runs.
    Úpythonú-Ú_Ú__version__N)ÚplatformÚpython_versionÚsysÚmodulesÚgetÚreplaceÚ
isinstanceÚgetattrr#   r   r   )rJ   ÚmoduleÚmodule_versions      r   Úget_installed_versionrk   z   sŸ   € ð �xÒÐÝÔ&Ñ(Ô(Ð(åŒ[�_Š_˜\×1Ò1°#°sÑ;Ô;Ñ<Ô<€FÝ¥G¨F°MÀ4Ñ$HÔ$HÐH�.Í#ÑNÔNð ØÐðÝ�|Ñ$Ô$Ð$øÝð ð ð Øˆtˆtðøøøs   Á6B Â
BÂBÚrequirementsúdict[str, Any] | NoneÚsourceÚNonec           
     ój  — | sdS t          | t          ¦  «        s t                               d|›d�¦  «         dS ddi}g }g }|                      ¦   «         D �]}\  }}|                     ||¦  «        }t          |t          ¦  «        }|r|                     dd¦  «        n|}|r|                     dd¦  «        nd}	t          |t          ¦  «        s"t                               d	|›d
|›d�¦  «         Œœt          |¦  «        }
	 t          |d¬¦  «        }|
�#| 	                    t          |
¦  «        ¦  «        rŒân;# t          $ r.}t                               d	|›d
|›d|› �¦  «         Y d}~�Œd}~ww xY w|
r|› d|
› d�nd}|                     d|› |› d|› d|	› �                     ¦   «         ¦  «         |dk    r|                     d|› |› d�¦  «         �Œ|r\|rd|›d�ndg|¢}|r+|                     dd                     |¦  «        › �¦  «         t          d                     |¦  «        ¦  «        ‚dS )a  
    Verifies that the installed packages satisfy the version requirements declared by a model.

    Requirements that can't be interpreted (e.g. an invalid specifier) are logged as a warning
    and skipped, so that a typo in a model configuration doesn't make the model unloadable.

    Args:
        requirements (dict[str, Any], optional): Mapping of package name to a `PEP 440
            <https://peps.python.org/pep-0440/#version-specifiers>`_ version specifier, e.g.
            ``{"transformers": ">=5.15", "peft": ">=0.18,<0.20"}``. Instead of a specifier, a value
            may also be a dictionary with a ``"specifier"`` and a ``"reason"`` describing what goes
            wrong if the requirement isn't met. The special ``"python"`` package name is matched
            against the running Python version.
        source (str, optional): The model name or path that declared the requirements, used in the
            error message. Defaults to None.

    Raises:
        ImportError: If one or more requirements aren't satisfied.
    NzIgnoring the `requirements` of z.: expected a dictionary of version specifiers.Úpytorchr.   Ú	specifierÚ ÚreasonzCould not verify the z requirement of z&: expected a version specifier string.T)Úprereleasesz: z==z is installedzit is not installedz- z, but z. r]   ú"z
The model z
 requires:zThis model requires:z5Install compatible versions with:
    pip install -U ú ú
)rg   ÚdictÚloggerÚwarningÚitemsre   r#   rk   r	   Úcontainsr
   Ú	ExceptionÚappendÚrstripÚjoinr!   )rl   rn   ÚaliasesÚunmetÚinstall_specsrJ   ÚrequirementÚis_dictrr   rt   Úinstalled_versionÚspecifier_setr(   ÚfoundÚliness                  r   Úcheck_version_requirementsr‹   Ž   s×  € ð( ð ØˆÝ�l¥DÑ)Ô)ð Ý�ŠÐq¸ÐqÐqÐqÑrÔrÐrØˆð ˜'Ð"€Gà€EØ!€MØ%1×%7Ò%7Ñ%9Ô%9ð Añ AÑ!ˆ�kØ—{’{ <°Ñ>Ô>ˆÝ˜[­$Ñ/Ô/ˆØ8?ÐP�K—O’O K°Ñ4Ô4Ð4À[ˆ	Ø29ÐA�—’ ¨2Ñ.Ô.Ð.¸rˆå˜)¥SÑ)Ô)ð 	Ý�NŠNØu¨	ÐuÐuÀVÐuÐuÐuñô ð ð å1°,Ñ?Ô?Ðð	Ý(¨ÀÐEÑEÔEˆMØ Ð,°×1GÒ1GÍÐPaÑHbÔHbÑ1cÔ1cÐ,ØøøÝð 	ð 	ð 	Ý�NŠNÐ_°9Ð_Ð_ÐPVÐ_Ð_Ð\]Ð_Ð_Ñ`Ô`Ð`ØˆHˆHˆH‰Høøøøð	øøøð HYÐs�<ÐCÐCÐ#4ÐCÐCÐCÐCÐ^sˆØ�ŠÐJ˜,ÐJ¨	ÐJÐJ¸ÐJÐJÀ&ÐJÐJ×QÒQÑSÔSÑTÔTÐTØ˜8Ò#Ð#Ø× Ò Ð!? \Ð!?°9Ð!?Ð!?Ð!?Ñ@Ô@Ð@ùàð ,Ø6<ÐXÐ2˜fÐ2Ð2Ð2Ð2ÐBXÐaÐ[`ÐaˆØð 	mØ�LŠLÐkÐRU×RZÒRZÐ[hÑRiÔRiÐkÐkÑlÔlÐlÝ˜$Ÿ)š) EÑ*Ô*Ñ+Ô+Ð+ð	,ð ,s   Ä5D9Ä9
E1Å#E,Å,E1)r   r   )r   r,   )r   r#   )rJ   r#   rK   r#   r   r,   )rJ   r#   r   r[   r   )rl   rm   rn   r[   r   ro   )&Ú
__future__r   Ú
contextlibrC   Úloggingr<   ra   rc   Úcollections.abcr   Úimportlib.metadatar   r   r   Útypingr   r.   Úpackaging.specifiersr	   Úpackaging.versionr
   Útransformersr   Ú	getLoggerÚ__name__rz   r   Ú__annotations__Úcontextmanagerr+   r2   rI   rP   rU   rX   rZ   rk   r‹   r   r    r   ú<module>r™      só  ðØ "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð Ø €€€Ø 	€	€	€	Ø €€€Ø 
€
€
€
Ø %Ð %Ð %Ð %Ð %Ð %Ø FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ Ð Ð Ð Ð Ð à €€€Ø -Ð -Ð -Ð -Ð -Ð -Ø %Ð %Ð %Ð %Ð %Ð %Ø /Ð /Ð /Ð /Ð /Ð /à	ˆÔ	˜8Ñ	$Ô	$€ð>ð >ð >Ð ð ð ð ñ ð Ôð	ð 	ð 	ñ Ôð	ðSð Sð Sð Sðð ð ð ð@	ð 	ð 	ð 	ðCð Cð Cð CðAð Að Að AðAð Að Að Aðð ð ð ð(?,ð ?,ð ?,ð ?,ð ?,ð ?,ð ?,r    