
    Ng$                    V    d dl mZ d dlmZ d dlmZ ddlmZ d Z	 G d d          Zd	S )
    )annotationswraps)PeftAdapterMixin   )Transformerc                <     t                      fd            }|S )zQWrapper to call the method on the auto_model with a check for PEFT compatibility.c                |    |                                   t          | d         j        j                  } ||i |S Nr   )check_peft_compatible_modelgetattr
auto_model__name__)selfargskwargsmethodfuncs       \/var/www/html/ai-engine/env/lib/python3.11/site-packages/sentence_transformers/peft_mixin.pywrapperzpeft_wrapper.<locals>.wrapper   sB    ((***a+T];;vt&v&&&    r   )r   r   s   ` r   peft_wrapperr   
   s5     4[[' ' ' ' ['
 Nr   c                      e Zd ZdZddZddZedd            Zedd            Zedd	            Z	edd
            Z
edd            Zedd            Zedd            Zedd            ZdS )r   a  
    Wrapper Mixin that adds the functionality to easily load and use adapters on the model. For
    more details about adapters check out the documentation of PEFT
    library: https://huggingface.co/docs/peft/index

    Currently supported PEFT methods follow those supported by transformers library,
    you can find more information on:
    https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin
    returnboolc                x    t          | d         t                    ot          | d         j        t                    S r   )
isinstancer   r   PeftAdapterMixinTransformersr   s    r   has_peft_compatible_modelz*PeftAdapterMixin.has_peft_compatible_model!   s-    $q';//pJtAw?QSo4p4ppr   Nonec                L    |                                  st          d          d S )Nz`PEFT methods are only supported for Sentence Transformer models that use the Transformer module.)r    
ValueErrorr   s    r   r   z,PeftAdapterMixin.check_peft_compatible_model$   s5    --// 	r  	 	r   c                    dS )a  
        Load adapter weights from file or remote Hub folder." If you are not familiar with adapters and PEFT methods, we
        invite you to read more about them on PEFT official documentation: https://huggingface.co/docs/peft

        Requires peft as a backend to load the adapter weights and the underlying model to be compatible with PEFT.

        Args:
            *args:
                Positional arguments to pass to the underlying AutoModel `load_adapter` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.load_adapter
            **kwargs:
                Keyword arguments to pass to the underlying AutoModel `load_adapter` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.load_adapter
        N r   r   r   s      r   load_adapterzPeftAdapterMixin.load_adapter*   s	      	r   c                    dS )a  
        Adds a fresh new adapter to the current model for training purposes. If no adapter name is passed, a default
        name is assigned to the adapter to follow the convention of PEFT library (in PEFT we use "default" as the
        default adapter name).

        Requires peft as a backend to load the adapter weights and the underlying model to be compatible with PEFT.

        Args:
            *args:
                Positional arguments to pass to the underlying AutoModel `add_adapter` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.add_adapter
            **kwargs:
                Keyword arguments to pass to the underlying AutoModel `add_adapter` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.add_adapter

        Nr%   r&   s      r   add_adapterzPeftAdapterMixin.add_adapter<   s	    $ 	r   c                    dS )a  
        Sets a specific adapter by forcing the model to use a that adapter and disable the other adapters.

        Args:
            *args:
                Positional arguments to pass to the underlying AutoModel `set_adapter` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.set_adapter
            **kwargs:
                Keyword arguments to pass to the underlying AutoModel `set_adapter` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.set_adapter
        Nr%   r&   s      r   set_adapterzPeftAdapterMixin.set_adapterP   s	     	r   c                    dS )zx
        Disable all adapters that are attached to the model. This leads to inferring with the base model only.
        Nr%   r   s    r   disable_adaptersz!PeftAdapterMixin.disable_adapters_   	    
 	r   c                    dS )zl
        Enable adapters that are attached to the model. The model will use `self.active_adapter()`
        Nr%   r   s    r   enable_adaptersz PeftAdapterMixin.enable_adaptersf   r.   r   	list[str]c                    dS )a3  
        If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
        official documentation: https://huggingface.co/docs/peft

        Gets the current active adapters of the model. In case of multi-adapter inference (combining multiple adapters
        for inference) returns the list of all active adapters so that users can deal with them accordingly.

        For previous PEFT versions (that does not support multi-adapter inference), `module.active_adapter` will return
        a single string.
        Nr%   r   s    r   active_adaptersz PeftAdapterMixin.active_adaptersm   s	     	r   strc                    d S )Nr%   r   s    r   active_adapterzPeftAdapterMixin.active_adapter{   s    %(Sr   dictc                    dS )a  
        If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
        official documentation: https://huggingface.co/docs/peft

        Gets the adapter state dict that should only contain the weights tensors of the specified adapter_name adapter.
        If no adapter_name is passed, the active adapter is used.

        Args:
            *args:
                Positional arguments to pass to the underlying AutoModel `get_adapter_state_dict` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.get_adapter_state_dict
            **kwargs:
                Keyword arguments to pass to the underlying AutoModel `get_adapter_state_dict` function. More information can be found in the transformers documentation
                https://huggingface.co/docs/transformers/main/en/peft#transformers.integrations.PeftAdapterMixin.get_adapter_state_dict
        Nr%   r&   s      r   get_adapter_state_dictz'PeftAdapterMixin.get_adapter_state_dict~   s	    " 	r   N)r   r   )r   r!   )r   r1   )r   r4   )r   r7   )r   
__module____qualname____doc__r    r   r   r'   r)   r+   r-   r0   r3   r6   r9   r%   r   r   r   r      s@        q q q q       \"    \&    \    \    \    \ ((( \(   \  r   r   N)

__future__r   	functoolsr   transformers.integrations.peftr   r   modelsr   r   r%   r   r   <module>rA      s    " " " " " "       [ [ [ [ [ [      	 	 	y y y y y y y y y yr   