
    oiB                        S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJ	r	J
r
Jr  S SKJrJr  S SKrS SKJr  S SKJrJr  S SKJr  SS	KJrJrJr  S
1rS rSS jrSS jr\
 " S S\5      5       r \
 " S S\ 5      5       r!\
 " S S\!5      5       r"g)    )annotationsN)asdict	dataclassfield)OptionalUnion)hf_hub_download)PushToHubMixinhttp_user_agent)__version__   )CONFIG_NAMEPeftTypeTaskType	peft_typec                    [         R                  " U R                  5      R                  n[	        UR                  5       5      [	        UR                  5       5      -
  nU H  nX	 M     X4$ )zMake PEFT configs forward-compatible by removing unused kwargs that were added in later PEFT versions.

This assumes that removing the unused kwargs will not affect the default behavior.

Returns the filtered kwargs and the set of removed keys.
)inspect	signature__init__
parameterssetkeys)clskwargssignature_parametersunexpected_kwargskeys        E/home/james-whalen/.local/lib/python3.13/site-packages/peft/config.py_check_and_remove_unused_kwargsr   %   s\     #,,S\\:EEFKKM*S1E1J1J1L-MM K !$$    c                X    [         R                  R                  U 5      R                  S L$ N)	packagingversionVersiondev)r$   s    r   _is_dev_versionr'   4   s$    $$W-11==r    c                    [         R                  R                  U 5      nUR                  =(       d    /  Ho  nUR
                  S:X  d  M  [        R                  " UR                  U5      R                  5       5      nUR                  S5      nU(       d  Mb  SU;   d  Mj  US   s  $    g ! [         R                  R                   a     g f = f)Nzdirect_url.jsonvcs_info	commit_id)	importlibmetadatadistributionPackageNotFoundErrorfilesnamejsonloadslocate_file	read_textget)pkg_namedistpath
direct_urlr)   s        r   _get_commit_hashr:   9   s    !!..x8
 

 b 99))T%5%5d%;$F$F$HIJ!~~j1HxK83,, !  22 s   B* *C
Cc                  T   \ rS rSr% Sr\" SSS0S9rS\S'   \" SSS	0S9rS
\S'   \" SSS0S9r	S\S'   \" SSS0S9r
S\S'   S r\SS j5       rS S jrS!S jr\S 5       r\S"S#S jj5       r\S$S j5       r\S 5       r\  S%S j5       r\S 5       r\S&S j5       r\S&S j5       rSrg)'PeftConfigMixinL   a'  
This is the base configuration class for PEFT adapter models. It contains all the methods that are common to all
PEFT adapter models. This class inherits from [`~transformers.utils.PushToHubMixin`] which contains the methods to
push your model to the Hub. The method `save_pretrained` will save the configuration of your adapter model in a
directory. The method `from_pretrained` will load the configuration of your adapter model from a directory.

Args:
    peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.
NhelpzThe type of task.defaultr,   zOptional[TaskType]	task_typezThe type of PEFT model.zOptional[PeftType]r   zEAn auto mapping dict to help retrieve the base model class if needed.zOptional[dict]auto_mappingz'PEFT version, leave empty to auto-fill.Optional[str]peft_versionc                    U R                   bL  U R                   [        [        5      ;  a/  [        SU R                    SSR	                  [        5       S35      eU R
                  c  U R                  5       U l        g g )NzInvalid task type: 'z,'. Must be one of the following task types: z, .)rA   listr   
ValueErrorjoinrD   _get_peft_versionselfs    r   __post_init__PeftConfigMixin.__post_init___   ss    NN&T^^4>-Q&t~~&66bcgclclmucvbwwxy  $ $ 6 6 8D %r    c                     [         n [        U 5      (       d  U $  [        S5      nUc  SnU SU 3-   n U $ ! [         a    [        R
                  " S5        Sn N.f = f)NpeftUNKNOWNzA dev version of PEFT is used but there was an error while trying to determine the commit hash. Please open an issue: https://github.com/huggingface/peft/issues@)r   r'   r:   	Exceptionwarningswarn)r$   git_hashs     r   rJ   !PeftConfigMixin._get_peft_versionh   st     w''N
	!'/H$ azN*  	!MMS !H	!s   4 "AAc                    [        U 5      $ )zC
Returns the configuration for your adapter model as a dictionary.
)r   rK   s    r   to_dictPeftConfigMixin.to_dict~   s     d|r    c           	     >   [         R                  R                  U5      (       a  [        SU S35      e[         R                  " USS9  UR                  SS5      nU R                  5       nUR                  5        H)  u  pV[        U[        5      (       d  M  [        U5      XE'   M+     [         R                  R                  U[        5      nUb  X4S'   [        US5       nUR                  [        R                   " US	SS
95        SSS5        g! , (       d  f       g= f)a^  
This method saves the configuration of your adapter model in a directory.

Args:
    save_directory (`str`):
        The directory where the configuration will be saved.
    kwargs (additional keyword arguments, *optional*):
        Additional keyword arguments passed along to the [`~transformers.utils.PushToHubMixin.push_to_hub`]
        method.
zProvided path (z#) should be a directory, not a fileT)exist_okauto_mapping_dictNrB   w   )indent	sort_keys)osr8   isfileAssertionErrormakedirspoprY   items
isinstancer   rG   rI   r   openwriter1   dumps)	rL   save_directoryr   r]   output_dictr   valueoutput_pathwriters	            r   save_pretrainedPeftConfigMixin.save_pretrained   s     77>>.)) ?>2BBe!fgg
NT2"JJ':DAlln%++-JC%%%#';  . ggll>;? (*;' +s#vLLKTJK $##s   &D
Dc                   SSK Jn  SU;   a
  US   nX#   nOU n U" S0 UD6nU$ ! [         a  nS[        U5      ;  a  Ue[	        XA5      u  px[
        R                  [        UR                  5       5      5      (       d   [        SU R                   S[
         S35      e[        R                  " S[        U5       S	UR                   S
35        UR                  " S0 UD6n SnAU$ SnAff = f)ai  
This method loads the configuration of your adapter model from a set of kwargs.

The appropriate configuration type is determined by the `peft_type` argument. If `peft_type` is not provided,
the calling class type is instantiated.

Args:
    kwargs (configuration keyword arguments):
        Keyword arguments passed along to the configuration initialization.
r   )PEFT_TYPE_TO_CONFIG_MAPPINGr   z"got an unexpected keyword argumentzThe z> config that is trying to be loaded is missing required keys: rF   zUnexpected keyword arguments z for class a,  , these are ignored. This probably means that you're loading a configuration file that was saved using a higher version of the library and additional parameters have been introduced since. It is highly recommended to upgrade the PEFT version before continuing (e.g. by running `pip install -U peft`).N )peft.mappingrt   	TypeErrorstrr   MIN_EXPECTED_CONFIG_KEYSissubsetr   r   __name__rT   rU   sortedfrom_peft_type)	r   r   rt   r   
config_clsconfigexcfiltered_kwargsr   s	            r   r}   PeftConfigMixin.from_peft_type   s    	=" & {+I4?JJ	B)&)F4 3  	B 43s8C	1PQ[1d.O+44S9M9M9O5PQQ3<<.(f/03 
 MM/7H0I/J+V`ViViUj k   ..AAF3	Bs   $ 
C*B1C%%C*c                ^   Ub  [         R                  R                  X5      OUnU R                  U5      u  pVnSU;  a  [	        5       US'   [         R                  R                  [         R                  R                  U[        5      5      (       a%  [         R                  R                  U[        5      nO [        U[        4SU0UD6nU R                  U5      n
0 UEU
EnU R                  " S0 UD6nU R                  " S0 UD6$ ! [         a  n	[        S[         SU S35      U	eSn	A	ff = f)a\  
This method loads the configuration of your adapter model from a directory.

Args:
    pretrained_model_name_or_path (`str`):
        The directory or the Hub repository id where the configuration is saved.
    kwargs (additional keyword arguments, *optional*):
        Additional keyword arguments passed along to the child class initialization.
N
user_agent	subfolderCan't find '' at ''ru   )rb   r8   rI   _split_kwargsr   rc   r   r	   rS   rH   from_json_filecheck_kwargsr}   )r   pretrained_model_name_or_pathr   r   r8   hf_hub_download_kwargsclass_kwargs_config_filer   loaded_attributess              r   from_pretrainedPeftConfigMixin.from_pretrained   s-    $ GGLL6B. 	 362C2CF2K/a553B3D"<077>>"'',,t[9::'',,t[9Kn-1;JSWm  ..{;6L6$56!!+F+!!+F++  n <}FC`Baab!cdjmmns   8D 
D,D''D,c                    [        U5       n[        R                  " U5      nSSS5        SW;   a  [        R                  " S5        US	 U$ ! , (       d  f       N/= f)zt
Loads a configuration file from a json file.

Args:
    path_json_file (`str`):
        The path to the json file.
Nruntime_configzzThe configuration file contains a `runtime_config` key. This is ignored. Runtime configurations are only valid at runtime.)ri   r1   loadrT   rU   )r   path_json_filer   filejson_objects        r   r   PeftConfigMixin.from_json_file
  sV     .!T))D/K " {*MM M ,- "!s   A
Ac                    0 n0 n0 nUR                  5        HV  u  pVU[        R                  " [        5      R                  ;   a  XbU'   M3  U[        U R                  5      ;   a  XcU'   MR  XdU'   MX     X#U4$ r"   )rg   r   r   r	   r   rG   __annotations__)r   r   r   r   other_kwargsr   rn   s          r   r   PeftConfigMixin._split_kwargs  su    !# ,,.JCg''8CCC.3s+S0011$)S!$)S! ) &\AAr    c                   UR                  SS 5      nUb  [        R                  R                  X5      OUn[        R                  R	                  [        R                  R                  U[
        5      5      (       a%  [        R                  R                  U[
        5      nO [        U[
        40 UD6nU R                  U5      nUS   $ ! [         a    [        S[
         SU S35      ef = f)Nr   r   r   r   r   )
r5   rb   r8   rI   rc   r   r	   rS   rH   r   )r   model_idr   r   r8   r   r   s          r   _get_peft_typePeftConfigMixin._get_peft_type/  s     +..{DA	4=4Irww||H0x77>>"'',,t[9::'',,t[9KP- -  ..{; --	  P <}F8*A!NOOPs   #C
 
!C+c                    U$ )ztCheck kwargs before initializing the config instance.

Subclasses can override this method to add specific checks.

ru   )r   r   s     r   r   PeftConfigMixin.check_kwargsH  s	     r    c                    g)F
Utility method to check if the configuration is for prompt learning.
Fru   rK   s    r   is_prompt_learning"PeftConfigMixin.is_prompt_learningQ  s    
 r    c                    g)z1Return True if this is an adaption prompt config.Fru   rK   s    r   is_adaption_prompt"PeftConfigMixin.is_adaption_promptX  s     r    )rD   )returnrx   )r   dict)rl   rx   r   Noner"   )r   rx   r   rC   )r   rx   )r   rx   r   bool)r{   
__module____qualname____firstlineno____doc__r   rA   r   r   rB   rD   rM   staticmethodrJ   rY   rq   classmethodr}   r   r   r   r   r   propertyr   r   __static_attributes__ru   r    r   r<   r<   L   s?    %*$&J]A^$_I!_$)$&JcAd$eI!e#((op$L.  #(Hq?r"sL-s9  *LB > >@ !, !,F  ( B B .. .0      r    r<   c                      \ rS rSr% Sr\" SSS0S9rS\S'   \" SSS	0S9rS\S
'   \" SSS0S9r	S\S'   \" SSS0S9r
S\S'   \" SSS0S9rS\S'   Srg)
PeftConfigi^  az  
This is the base configuration class to store the configuration of a [`PeftModel`].

Args:
    peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.
    task_type (Union[[`~peft.utils.config.TaskType`], `str`]): The type of task to perform.
    inference_mode (`bool`, defaults to `False`): Whether to use the Peft model in inference mode.
Nr>   z"The name of the base model to use.r?   rC   base_model_name_or_pathz'The specific base model version to use.revisionz	Peft typezOptional[Union[str, PeftType]]r   z	Task typezOptional[Union[str, TaskType]]rA   FzWhether to use inference moder   inference_moderu   )r{   r   r   r   r   r   r   r   r   r   rA   r   r   ru   r    r   r   r   ^  s     .3(LM.]  $DFDm;noHmo05dfVaMb0cI-c05dfVaMb0cI-c &Ba9bcNDcr    r   c                      \ rS rSr% Sr\" SSS0S9rS\S'   \" SSS	0S9rS\S
'   \" SSS0S9r	S\S'   \" SSS0S9r
S\S'   \" SSS0S9rS\S'   \" SSS0S9rS\S'   \SS j5       rSrg)PromptLearningConfigir  a5  
This is the base configuration class to store the configuration of [`PrefixTuning`], [`PromptEncoder`], or
[`PromptTuning`].

Args:
    num_virtual_tokens (`int`): The number of virtual tokens to use.
    token_dim (`int`): The hidden embedding dimension of the base transformer model.
    num_transformer_submodules (`int`): The number of transformer submodules in the base transformer model.
    num_attention_heads (`int`): The number of attention heads in the base transformer model.
    num_layers (`int`): The number of layers in the base transformer model.
Nr>   zNumber of virtual tokensr?   intnum_virtual_tokensz<The hidden embedding dimension of the base transformer model	token_dimz Number of transformer submoduleszOptional[int]num_transformer_submoduleszNumber of attention headsnum_attention_headszNumber of transformer layers
num_layersa&  List of extra modules to be set as trainable and saved in the final checkpoint. For example, in Sequence Classification or Token Classification tasks, the final layer `classifier/score` are randomly initialized and as such need to be trainable and saved. The module(s) will be fully fine-tuned.zOptional[list[str]]modules_to_savec                    g)r   Tru   rK   s    r   r   'PromptLearningConfig.is_prompt_learning  s    
 r    ru   r   )r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ru   r    r   r   r   r  s    
 $DFD^;_``(fgIs  16(JK1  */tvOjFk)ll %dfFd=e fJf+0 6
,O(   r    r   )r$   rx   r   r   )r6   rx   r   z
str | None)#
__future__r   importlib.metadatar+   r   r1   rb   rT   dataclassesr   r   r   typingr   r   packaging.versionr#   huggingface_hubr	   transformers.utilsr
   r   rP   r   utilsr   r   r   ry   r   r'   r:   r<   r   r   ru   r    r   <module>r      s    #    	  0 0 "  + >  2 2 (= %>
& Nn N Nb d d d& %: % %r    