
    oiv                   2   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  S SK	J
r
Jr  S SKJr  S SKJr  S SKJrJrJrJr  S SKrS SKrS SKrS SKJrJr  S S	KJrJrJr  S S
KJ r J!r!  S SK"J#r#J$r$J%r%J&r&  S SK'J(r(  S SK)J*r+  S SK,J-r-J.r.J/r/  S SKJ0r0J1r1J2r2J3r3  S SK4J5r5J6r6J7r7  S SK8J9r9  S SK:J;r;J<r<  S SK=J>r>J?r?  S SK@JArA  S SKBJCrC  S SKDJErE  S SKFJGrGJHrHJIrI  SSKJJKrK  SSKLJMrM  SSKNJOrOJPrPJQrQ  SSKRJSrSJTrTJUrUJVrVJWrWJXrXJYrYJZrZJ[r[J\r\J]r]J^r^J_r_J`r`JaraJbrb   " S S\9\R                  R                  5      re " S S \e5      rf " S! S"\e5      rg " S# S$\e5      rh " S% S&\e5      ri " S' S(\e5      rj " S) S*\e5      rk\ " S+ S,5      5       rlS2S- jrm\ " S. S/5      5       rnS3S0 jroS1 rpg)4    )annotationsN)Sequence)contextmanagernullcontext)deepcopy)	dataclass)AnyLiteralOptionalUnion)dispatch_modelinfer_auto_device_map)AlignDevicesHookadd_hook_to_moduleremove_hook_from_submodules)get_balanced_memorynamed_module_tensors)HfFileSystem	ModelCardModelCardDatahf_hub_download)	safe_open)	save_file)BCEWithLogitsLossCrossEntropyLossMSELoss)CacheDynamicCacheEncoderDecoderCachePreTrainedModel)QuestionAnsweringModelOutputSequenceClassifierOutputTokenClassifierOutput)PushToHubMixin)get_alora_offsets_for_forwardget_alora_offsets_for_generate)	BaseTunerBaseTunerLayer)AuxiliaryTrainingWrapper)DUMMY_MODEL_CONFIG)init_empty_weights)TrainableTokensWrappercreate_attention_mask set_additional_trainable_modules   )__version__)
PeftConfig)PEFT_TYPE_TO_CONFIG_MAPPINGPEFT_TYPE_TO_PREFIX_MAPPINGPEFT_TYPE_TO_TUNER_MAPPING)SAFETENSORS_WEIGHTS_NAME8TRANSFORMERS_MODELS_TO_PREFIX_TUNING_POSTPROCESS_MAPPINGWEIGHTS_NAMEPeftTypeTaskType_get_batch_size_prepare_prompt_learning_config_set_adapter_set_trainableget_peft_model_state_dictid_tensor_storageinfer_deviceload_peft_weightsmap_cache_to_layer_device_mapset_peft_model_state_dictshift_tokens_rightc                    ^  \ rS rSrSr   S(           S)U 4S jjjr\S*S j5       r\S+S j5       r\S,S j5       r	\R                  S-S j5       r     S.               S/S jjr\       S0                     S1S	 jj5       rS2S
 jrS3S jrS3S jrS4U 4S jjr S5       S6S jjrS7S jrS8S jrS9U 4S jjr\S 5       rS:S jrS rS;S jr\S 5       rS<S jrS;S=S jjrS>S jr\S?S j5       rS@S jr SAS jr!\SBS j5       r"SCS jr#SDS jr$      SE                 SFS  jjr%S>S! jr&SGSHS" jjr'\S# 5       r(\S$ 5       r)S% r*SIS& jr+S'r,U =r-$ )J	PeftModelH   a  
Base model encompassing various Peft methods.

Args:
    model ([`~transformers.PreTrainedModel`]): The base transformer model used for Peft.
    peft_config ([`PeftConfig`]): The configuration of the Peft model.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.
    low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
        Create empty adapter weights on meta device. Useful to speed up the loading loading process.

        > [!TIP] > Don't use `low_cpu_mem_usage=True` when creating a new PEFT adapter for training.

**Attributes**:
    - **base_model** ([`torch.nn.Module`]) -- The base transformer model used for Peft.
    - **peft_config** ([`PeftConfig`]) -- The configuration of the Peft model.
    - **modules_to_save** (`list` of `str`) -- The list of sub-module names to save when
        saving the model.
    - **prompt_encoder** ([`PromptEncoder`]) -- The prompt encoder used for Peft if
        using [`PromptLearningConfig`].
    - **prompt_tokens** (`torch.Tensor`) -- The virtual prompt tokens used for Peft if
        using [`PromptLearningConfig`].
    - **transformer_backbone_name** (`str`) -- The name of the transformer
        backbone in the base model if using [`PromptLearningConfig`].
    - **word_embeddings** (`torch.nn.Embedding`) -- The word embeddings of the transformer backbone
        in the base model if using [`PromptLearningConfig`].
c                  > [         TU ]  5         X0l        UR                  U l        SS1U l        UR
                  U l        U R                  (       a  X20U l        Xl        U R                  X2US9  OMS U l        [        UR                     nU(       a  [        O[        nU" 5          U" XU0U5      U l        S S S 5        [        U R                  S5      (       a  U R                  R                  X4S9  [        USS5      (       a  U R!                  U5      n[        U R                  S5      (       a@  [        U R                  R"                  S	5      (       a  S
U R                  R"                  l        SU l        g ! , (       d  f       N= f)Nadapter_namesalora_offsetslow_cpu_mem_usage_cast_adapter_dtypeadapter_nameautocast_adapter_dtypeis_gradient_checkpointingTconfigpretraining_tpr/   F)super__init__active_adapter	peft_typespecial_peft_forward_argsis_prompt_learning_is_prompt_learning_peft_config
base_modeladd_adapterr4   r+   r   hasattrrM   getattr(prepare_model_for_gradient_checkpointingrR   rS   _adapters_disabled)	selfmodelpeft_configrO   rP   rL   clsctx	__class__s	           I/home/james-whalen/.local/lib/python3.13/site-packages/peft/peft_model.pyrU   PeftModel.__init__h   sH    	*$.. +:?)K&#.#A#A ##!- ;D#O\J[\ $D,[-B-BCC(9${C"%eK-H,"W  4??$9::OO//) 0  55t<<AA%HE
 4??H--'$//:P:PRb2c2c45DOO""1"'# s   %E88
Fc                h    U R                   (       a  U R                  $ U R                  R                  $ NrZ   r[   r\   rd   rb   s    rh   rd   PeftModel.peft_config   s'    ##$$$***    c                    U R                   R                  n[        U[        5      (       d$  U R                  n[        U[
        5      (       a  U/nU$ ! [         a(    U R                  n[        U[
        5      (       a  U/n U$ f = frk   )r\   active_adapters
isinstancelistrV   strAttributeError)rb   adapterss     rh   rq   PeftModel.active_adapters   s    	&66Hh--  ..h,, (zH
 	  	&**H(C(($:		&s   AA .BBc                    U R                   U R                     R                  (       a  U R                  (       + $ U R                  (       + =(       d    U R                  (       + $ )a  Reflects whether the adapters are purposefully disabled (via disable_adapter) or if there
are no active adapters (enabled but inactive). They are two separate mechanisms but sometimes it is helpful to
know whether the model has any active/enabled adapter at all.
)rd   rV   rY   ra   rq   rm   s    rh   has_active_enabled_adapter$PeftModel.has_active_enabled_adapter   sJ     D//0CC....***F$2F2F.FFro   c                T    U R                   (       a  Xl        g XR                  l        g rk   rl   )rb   values     rh   rd   rn      s    ## %*/OO'ro   c                f
  ^  [         R                  R                  U5      (       a  [        SU S35      eUc$  [	        T R
                  R                  5       5      nOM[        U 4S jU 5       5      (       a3  [        S[	        T R
                  R                  5       5       SU S35      eU 4S jnU(       a&  [         R                  " US	S
9  T R                  U5        U GH=  n	T R
                  U	   n
[        T UR                  SS5      U	US9nU	S:w  a  [         R                  R                  X5      OUn[         R                  " US	S
9  U(       Gas  U(       Gak  [        R                  " [        5      nUR                  5        H`  u  p[!        U["        R$                  5      (       a  U['        U5         R)                  U5        MC  U[+        U5         R)                  U5        Mb     UR                  5        VVs0 s H  u  nn[-        U5      S:  d  M  UU_M     nnnUR                  5        H(  u  nnUSS  H  nUU   R/                  5       UU'   M     M*     Ub7  [0        R2                  " U
5      n
S	U
l        U
R7                  U5        U" XX5      n[9        U[         R                  R                  U[:        5      SS0S9  OzU(       as  Ub7  [0        R2                  " U
5      n
S	U
l        U
R7                  U5        U" XX5      n["        R<                  " U[         R                  R                  U[>        5      5        U
R@                  cl  U
RB                  (       a&  T RD                  RF                  R                  SS5      O/T RD                  RH                  RF                  R                  SS5      U
l         U
RJ                  nS	U
l%        U
RL                  c5  T RO                  U
RB                  S9nURP                  nURR                  US.nOSnU(       a  Ub  S	U
l        U
=RT                  S-  sl*        U
RV                  (       d  U
=RX                  S-  sl,        OU
=RX                  S-  sl,        U
RZ                  (       a9  U
RZ                  R                  5        VVs0 s H  u  nnUSU-  _M     snnU
l-        U
R\                  (       a9  U
R\                  R                  5        VVs0 s H  u  nnUSU-  _M     snnU
l.        U
R7                  UUS9  UU
l%        GM@     gs  snnf s  snnf s  snnf )u  
This function saves the adapter model and the adapter configuration files to a directory, so that it can be
reloaded using the [`PeftModel.from_pretrained`] class method, and also used by the [`PeftModel.push_to_hub`]
method.

Args:
    save_directory (`str`):
        Directory where the adapter model and configuration files will be saved (will be created if it does not
        exist).
    safe_serialization (`bool`, *optional*):
        Whether to save the adapter files in safetensors format, defaults to `True`.
    selected_adapters (`List[str]`,  *optional*):
        A list of adapters to be saved. If `None`, will default to all adapters.
    save_embedding_layers (`Union[bool, str]`, *optional*, defaults to `"auto"`):
        If `True`, save the embedding layers in addition to adapter weights. If `auto`, checks the common
        embedding layers `peft.utils.other.EMBEDDING_LAYER_NAMES` in config's `target_modules` when available.
        and automatically sets the boolean flag. This only works for 🤗 transformers models.
    is_main_process (`bool`, *optional*):
        Whether the process calling this is the main process or not. Will default to `True`. Will not save the
        checkpoint if not on the main process, which is important for multi device setups (e.g. DDP).
    path_initial_model_for_weight_conversion (`str, *optional*`):
        The path to the initialized adapter, which is obtained after initializing the model with
        PiSSA/CorDA/OLoRA and before performing any training. When `path_initial_model_for_weight_conversion`
        is not None, the difference in adapter before and after fine-tuning is calculated. This difference can
        be represented as the parameters of a standard LoRA adapter. Using this converted adapter does not
        require changes to the base model, thus conveniently allowing the use of multiple PiSSA/CorDA/OLoRA
        adapters with LoRA adapters, and the activation or deactivation of any adapters. Note that this
        conversion is not supported if `rslora` is used in combination with `rank_pattern` or `alpha_pattern`.
    kwargs (additional keyword arguments, *optional*):
        Additional keyword arguments passed along to the `push_to_hub` method.

zProvided path (z#) should be a directory, not a fileNc              3  p   >#    U  H+  nU[        TR                  R                  5       5      ;  v   M-     g 7frk   )rs   rd   keys).0selected_adapter_namerb   s     rh   	<genexpr>,PeftModel.save_pretrained.<locals>.<genexpr>   s2      ->) &T$2B2B2G2G2I-JJ->s   36zYYou passed an invalid `selected_adapters` arguments, current supported adapter names are z - got .c                  >^  T R                   (       a/  T R                  (       d  T R                  (       a  Sn[        U5      e[	        U 4S jS 5       5      (       d  [
        R                  " S5        [        R                  R                  U5      n T	R                  [        R                  R                  U5      UUS9  [        T	R                  U   R                  5      R                  5       R!                  S5      n[        T	R                  U   R                  5      R                  5       S:H  n[        T	R                  U   R                  5      R                  5       S:H  nU(       d  U(       d  U(       a  [        S	5      eT	R"                  R%                  X%U5      nT	R'                  U5        U$ ! T	R'                  U5        f = f)
NzPassing `path_initial_model_for_weight_conversion` to `save_pretrained` is not supported when using `rank_pattern` or `alpha_pattern` at the same time as `use_rslora=True`.c              3     >#    U  H7  n[        TR                  5      R                  5       R                  U5      v   M9     g 7frk   )rt   init_lora_weightslower
startswith)r   prefixrd   s     rh   r   JPeftModel.save_pretrained.<locals>.save_mutated_as_lora.<locals>.<genexpr>   s:      AF K11288:EEfMMAs   ?A)pissacordaoloratruezr`path_initial_model_for_weight_conversion` only works for converting a PiSSA/CorDA/OLoRA adapter to a LoRA adapter)	subfolderrO   r   r   r   zThe `init_lora_weights` parameter of the initial adapter should be set to `True`. Otherwise, `self.load_adapter` will subtract the decomposed values again based on the residual model.)
use_rslorarank_patternalpha_pattern
ValueErroranywarningswarnospathbasenameload_adapterdirnamert   rd   r   r   r   r\   subtract_mutated_initdelete_adapter)
rd   (path_initial_model_for_weight_conversionoutput_state_dictkwargsmsginitial_adapter_nameis_pissais_cordais_olorarb   s
   `        rh   save_mutated_as_lora7PeftModel.save_pretrained.<locals>.save_mutated_as_lora   s   %%;+C+C{G`G`e  !o% A   % $&77#3#34\#] :!!GGOO$LM2!5 " 
 t//0DEWWX^^`kklstt//0DEWWX^^`dkkt//0DEWWX^^`dkkx8$* 
 %)OO$I$I%V%! ##$89$$ ##$89s   DF5 5GT)exist_ok
state_dict)r   rO   save_embedding_layersdefaultr/   formatptmetadataname_or_path)is_prompt_tuning)base_model_classparent_library   g;f?)auto_mapping_dict)/r   r   isfiler   rs   rd   r   r   makedirscreate_or_update_model_cardr>   getjoincollectionsdefaultdictitemsrr   torchTensorr?   appendidlenclonecopyr   r   save_pretrainedsafe_save_filer5   saver7   base_model_name_or_pathrY   r\   __dict__rc   inference_mode	task_type_get_base_model_class
__module____name__rr   
lora_alphar   r   )rb   save_directorysafe_serializationselected_adaptersr   is_main_processr   r   r   rO   rd   r   
output_dirptrsnametensorptrnamesshared_ptrs_shared_tensor_namer   r   r   r   keyvals   `                          rh   r   PeftModel.save_pretrained   s   T 77>>.))~.>>abcc$ $T%5%5%:%:%< = ->   !T--22456g>O=PPQS 
%	%N KK6,,^<-L**<8K 9!::lD9)&;	! HTW`G`nCftJKK
T2#5 #..t4$5$;$;$=LD "&%,,77.v67>>tD RZ(//5 %> =AJJL[Ljc5CPUJYZNzsEzL[ + 1 1 3HAu /4ABi*@QRd@e@k@k@m)*<= /8 !4
 <G"&--"<K48K1//0XY(<#O`)% %GGLL-EF&-
 !;G"&--"<K48K1//0XY(<#O`)% 

,bggll:|.TU 22: #55 OO,,00F..77;;NDQ 3
 )77N)-K&$$,#'#=#=%0%C%C $> $  "2!<!< )9(A(A&4%!
 %)!;G48K1MMQ&M&11#..!3. $..&8."//Q\QiQiQoQoQq3rQqXS#CSLQq3r0"00R]RkRkRqRqRs4tRshc3S!c'\Rs4t1++JJ[+\)7K&A .6 \@ 4s4ts   :T!T!T'(T-c
           
     R   SSK Jn  SSKJnJn  Uc  U
R                  SS5      U
R                  SS5      U
R                  SS5      U
R                  SS5      S	.nU
R                  S
S5      =n(       a  XS
'   [        [        R                  " U40 UD6   R                  " U40 U
D6nO:[        U[        5      (       a  U(       + Ul        O[        SUR                   35      eU	c  UR                  (       d  [        US0 5      n	[!        US5      (       a  XuR"                  l        OU(       a  [&        R(                  " S5        [!        US5      (       Ga  [+        [-        USS95      n[/        5       nSnUR1                  5        GH  u  nn[!        US5      (       d  M  [!        UR2                  S5      (       d  M7  [!        UR2                  R4                  S5      (       a*  UR2                  R4                  R6                  R8                  nUR2                  R:                  R=                  5        H_  nUR2                  R:                  U   [>        R@                  " S5      :X  d  M6  URC                  [E        U5      S-   [E        U5      -   5        Ma     GM     U(       a"  U
R                  SS5      (       d  [        S5      eU(       a^  UR=                  5        Vs0 s H>  nUU;   d  M  UUU   S   U[E        UU   RF                  5      RI                  SS5      S._M@     nnUU
S'   [        USS5      bL  [K        [/        URL                  RO                  5       5      RQ                  SS15      5      S :  a  [S        U5        UR                  (       a  U(       a  [        S!5      eU(       + Ul        [        [        US"S5      U5      (       a  [        X\5      (       d  [U        S#[W        U5       S$35      eS%U
;   a  U
S%   Ul,        O[Z        R\                  R_                  U5      (       d  [a        5       nURc                  U5       Vs/ s H"  nUS&   S':X  d  M  US(   [K        U5      S-   S PM$     nn0 nU H%  n[Z        R\                  Re                  X"5      UU'   M'     UUl,        UUl3        OS%U
;  a  [        S)5      eURh                  UR=                  5       ;  a  U " UUUUUS*9nOXRh                     " UUUUUS*9nURj                  " UU4UUUU	S+.U
D6nURl                   Vs/ s H  nS,U;  d  M  S-U;  d  M  UPM     nnU(       aU  S.U S3n[n        R
                  " URp                  5      n U (       a  UU ;   a  S/U S0U  S13U-   n[&        R(                  " U5        U$ s  snf s  snf s  snf )2u  
Instantiate a PEFT model from a pretrained model and loaded PEFT weights.

Note that the passed `model` may be modified inplace.

Args:
    model ([`torch.nn.Module`]):
        The model to be adapted. For 🤗 Transformers models, the model should be initialized with the
        [`~transformers.PreTrainedModel.from_pretrained`].
    model_id (`str` or `os.PathLike`):
        The name of the PEFT configuration to use. Can be either:
            - A string, the `model id` of a PEFT configuration hosted inside a model repo on the Hugging Face
              Hub.
            - A path to a directory containing a PEFT configuration file saved using the `save_pretrained`
              method (`./my_peft_config_directory/`).
    adapter_name (`str`, *optional*, defaults to `"default"`):
        The name of the adapter to be loaded. This is useful for loading multiple adapters.
    is_trainable (`bool`, *optional*, defaults to `False`):
        Whether the adapter should be trainable or not. If `False`, the adapter will be frozen and can only be
        used for inference.
    config ([`~peft.PeftConfig`], *optional*):
        The configuration object to use instead of an automatically loaded configuration. This configuration
        object is mutually exclusive with `model_id` and `kwargs`. This is useful when configuration is already
        loaded before calling `from_pretrained`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Only relevant for specific adapter types.
    ephemeral_gpu_offload (`bool`, *optional*):
        Whether to use ephemeral GPU offloading for partially loaded modules. Defaults to `False`. This is
        useful when parts of the model and/or components (such as adapters) are kept in CPU memory until they
        are needed. Rather than perform expensive operations on small data, the data is transferred to the GPU
        on-demand, the operation(s) performed, and the results moved back to CPU memory. This brings a slight
        momentary VRAM overhead but gives orders of magnitude speedup in certain cases.
    low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
        Create empty adapter weights on meta device before loading the saved weights. Useful to speed up the
        process.
    torch_device (`str`, *optional*, defaults to None):
        The device to load the adapter on. If `None`, the device will be inferred.
    key_mapping (dict, *optional*, defaults to None)
        Extra mapping of PEFT `state_dict` keys applied before loading the `state_dict`. When this mapping is
        applied, the PEFT-specific `"base_model.model"` prefix is removed beforehand and the adapter name (e.g.
        `"default"`) is not inserted yet. Only pass this argument if you know what you're doing.
    kwargs: (`optional`):
        Additional keyword arguments passed along to the specific PEFT configuration class.
r/   ) MODEL_TYPE_TO_PEFT_MODEL_MAPPING)XLoraConfig
XLoraModelNr   revision	cache_dirtoken)r   r   r   r   use_auth_tokenz+The input config must be a PeftConfig, got _checkpoint_conversion_mappingruntime_configzCEphemeral GPU offloading is not supported for this model. Ignoring.hf_device_mapT)recurse_hf_hookoriginal_devicesdatasetmetar   use_safetensorsz8Disk offloading currently only supported for safetensorssafetensors_fileztorch. )r   weight_namedtypeoffload_indexcpudiskr   RCannot set a prompt learning adapter to trainable when loading pretrained adapter.r\   zExpected 'XLoraConfig', got 'z
' instead.rv   type	directoryr   zFIf model_id is a local path, then `adapters` must be passed in kwargs.)rP   rL   )is_trainablerP   rL   key_mappingvblora_vector_bankprompt_encoderz9Found missing adapter keys while loading the checkpoint: Adapter name ')' should not be contained in the prefix 'z@'. This could be the potential reason for missing adapter keys. )9autor   tunersr   r   r   r2   r1   _get_peft_typefrom_pretrainedrr   r   r   rg   rY   r_   r^   r   ephemeral_gpu_offloadr   r   dictr   setnamed_modulesr   weights_mapr   indexr   r   r   deviceaddrt   r   replacer   r   valuesintersectionr   	TypeErrorr   rv   r   r   existsr   lsr   _subfoldersr   r   missing_keysr3   rW   )!re   rc   model_idrO   r   rR   rP   r  rL   r   r   r   r   r   	hf_kwargsr   
weight_mapdisk_modulesr  r   moduler   pr   sfilerI   adapter_pathsload_resultkr  warn_messager   s!                                    rh   r  PeftModel.from_pretrained  ss   t 	;3 >#ZZT:"JJz48#ZZT:GT2	I "(,<d!CC~C.<*+01J1J81aW`1abrr"F 
++(4$4F!J6K[K[J\]^^ &*C*C!%)I2NK 6+,,:O!!7$cd5/**25$GHJ 5LE % 3 3 5f6:..76??L^3_3_v::IFF & ; ; C C I I%??DDF!??;;C@ELLQWDXX(,,SY_s3x-GH  G	 !6 FJJ/@$$G$G ![\\ (__.! /L(A,1!H5G,H'(!$Z]%8%8!9!A!A(B!O 
 /  ! +8'E?D1=3##**,-::E6?KD
D (.$$qrr(4$4F!ge\48*EEf22"?V~Z XYYV#"("4 ww~~h//$A GHdd8n%FTdX\]cXdhsXs9VS]Q%6%89n " % %'M(568ggll86Vl3 )6&3FO)6F&!/()qrr#C#H#H#JJ'="3E 55E5EF'="3E ((
 &#9/#
 
 #//
/!3Gq3PAUemnUnA/ 	 
  WWcVddefL044V5E5EFF,&0$\N2[\b[c dT T  !
 MM,'}!@%T
s*   
V#7V VV
V$,V$4V$c                   U R                   U   n[        U S5      (       d+  [        R                  R	                  0 5      U l        0 U l        S nU R                  R                  5        HG  u  pEUR                  5        H
  nSUl
        M     [        U[        5      (       d  M:  Ub  M?  UnX@l        MI     Uc  U R                  nUR                  c'  UR                  [         R"                  :X  a  SOSUl        S n U R                  R%                  S5      nUGc-  [)        UR+                  5       5       GH  u  p[-        U	SS 5      n
[        U R                  R.                  S5      (       a/  U R                  R.                  R1                  5       R2                  nOeSU R                  R.                  ;   a+  U R                  R.                  R4                  R2                  nO U R                  R.                  R2                  nU	R6                  S	   U:X  d  U
c  M  U
S	   U:X  d  M  UR%                  UR9                  S
S5      5      n  O   Xpl        [<        UR>                     nUR>                  [@        RB                  [@        RD                  [@        RF                  4;   a  U" X R:                  5      nOUR>                  [@        RH                  :X  a	  U" U5      nOpUR>                  [@        RJ                  :X  aG  [M        S U RO                  5       RQ                  5        5       5      (       a  [S        S5      eU" U5      nO[S        S5      eURU                  U RV                  5      nU R
                  RY                  [        R                  R	                  X05      5        [        RZ                  " UR\                  UR                  -  5      R_                  5       U R                  U'   g ! [&         a     GNf = f)Nr   Fr   r/   zembeddings.word_embeddingsds_shapeget_text_configtext_configr   z.weightr   c              3  <   #    U  H  n[        US S5      v   M     g7f)gradient_checkpointingFNr_   )r   r  s     rh   r   2PeftModel._setup_prompt_encoder.<locals>.<genexpr>  s     rRq76#;UCCRqs   z8Prefix tuning does not work with gradient checkpointing.zNot supported)0rd   r^   r   nn
ModuleDictr   prompt_tokensr\   named_children
parametersrequires_gradrr   r    transformer_backbone_namenum_transformer_submodulesr   r9   SEQ_2_SEQ_LMget_submoduleru   rs   named_parametersr_   rR   r&  
vocab_sizer'  shaper  word_embeddingsr4   rW   r8   PROMPT_TUNINGMULTITASK_PROMPT_TUNINGCPTP_TUNINGPREFIX_TUNINGr   get_base_modelmodulesr   tor  updatearangenum_virtual_tokenslong)rb   rO   rR   transformer_backboner   r  paramr9  named_paramr|   "deepspeed_distributed_tensor_shaper7  	model_clsr   s                 rh   _setup_prompt_encoderPeftModel._setup_prompt_encoderZ  s<   !!,/t-.."'(("5"5b"9D!#D# OO::<LD**,&+# -&/22'/+1(592 =  '#'?? ,,45;5E5EI^I^5^deF- 	 #oo;;<XYO " '++?+P+P+R&S"
 6=UJPT5U2 4??113DEE!%!7!7!G!G!I!T!TJ"doo&<&<<!%!7!7!C!C!N!NJ!%!7!7!B!BJ;;q>Z/6B:1=K&:&H&HI\I\]fhjIk&lO+ 'T.  /.v/?/?@	 6 68X8XZbZfZfgg&v/C/CDN!2!22&v.N!7!77rRVReReRgRoRoRqrrr ![\\&v.N_--'**4;;7""588#6#67U#VW+0<<%%(I(II,

$& 	<(]  		s   9O" "
O0/O0c                &    U R                  U5        g)z<
Prepares the model for gradient checkpointing if necessary
N))_prepare_model_for_gradient_checkpointing)rb   rc   s     rh   r`   2PeftModel.prepare_model_for_gradient_checkpointing  s     	66u=ro   c                   [        USS5      (       dz  [        USS5      (       dh  [        USS5      (       dV  [        US5      (       a  UR                  5         U$ [        US5      (       a"  S nUR                  5       R	                  U5        U$ )Nis_loaded_in_8bitFis_loaded_in_4bitis_quantizedenable_input_require_gradsget_input_embeddingsc                &    UR                  S5        g )NT)requires_grad_)r  inputoutputs      rh   make_inputs_require_gradUPeftModel._prepare_model_for_gradient_checkpointing.<locals>.make_inputs_require_grad  s    ))$/ro   )r_   r^   rT  rU  register_forward_hook)rb   rc   rZ  s      rh   rN  3PeftModel._prepare_model_for_gradient_checkpointing  s    E.66u1599une44u:;;002   6770 **,BBC[\ro   c                |  > U R                   U   nU R                  U   R                  S5      R                  SS5      R	                  UR
                  R                  R                  5      nU R                  U   R                  nU R                  U   R                  [        R                  :X  a"  USS2SU R                  U   R                  24   nU R                  U   R                  [        R                  :X  a  [        U   n[        XR]C  U5      nOU" U5      nUS   R#                  5       R%                  5       $ )zr
Returns the prompt embedding to save when saving the model. Only applicable when using a prompt learning
method.
r   r/   N)r   r.  	unsqueezeexpandrA  	embeddingweightr  rd   rW   r8   r>  rD  r;  r4   rT   forwarddetachr   )rb   rO   r   r.  rW   prompt_embedding_clsprompt_embeddingsrg   s          rh   get_prompt_embedding_to_save&PeftModel.get_prompt_embedding_to_save  s   
 ,,\:|,66q9@@BGJJ>KcKcKjKjKqKqr 	 $$\2<<	L)33x7M7MM)!-`t/?/?/M/`/`-`*`aML)33x7W7WW#=i#H  %&: STa b .} = #**,0022ro   c                   U R                   nU R                  U R                     nU R                  U R                     R	                  S5      R                  US5      R                  UR                  R                  R                  5      nUR                  [        R                  :X  Gan  USS2SUR                  24   nUR                  (       a(  UR                  R                  R                  USS5      nOU" U5      nU R                   b  UR                  U R                   5      nUR#                  UUR                  UR$                  S-  UR&                  UR(                  UR&                  -  5      nUR*                  S:X  a  [,        R.                  " Xw/SS9nUR1                  / SQ5      R3                  UR*                  S-  5      nU R5                  5       n[7        USS5      n	[7        U	S	S
5      n
[8        R:                  " U R<                  R>                  S5      b'  [8        U R<                  R>                     nU" U5      nGOSU
;   d  SU
;   Ga@  [@        RB                  RE                  [F        RH                  5      [@        RB                  RE                  S5      :  nU(       a  Ub  US:X  a  [K        S5      eUR<                  n[M        US5      (       a  URO                  5       nU(       a+  SSK#J(n  U" UUUUS   RR                  US   R                  S9nO	[U        US9n[,        RV                  " UR                  US   R                  S9n[Y        UR$                  5       H'  nUS   U   US   U   nnUR[                  UUUSU0S9  M)     UnGOhUR*                  S:X  aw  [@        RB                  RE                  [F        RH                  5      [@        RB                  RE                  S5      :  nU(       a  [T        R\                  " U5      nO[U        U5      nOUR*                  S:X  a  [7        U R^                  SS5      (       a  [@        RB                  RE                  [F        RH                  5      [@        RB                  RE                  S5      :  nU(       a  [`        R\                  " U5      nO[a        U5      n[U        5       Ul1        URd                  Rg                  5        H  nSURd                  U'   M     [i        U R5                  5       U5        U$ UR                  [        Rj                  :X  a
  U" Xb5      nU$ UR                  (       a  UR                  R                  nOUSS nU" U5      nUR                  USS5      nU$ )zc
Returns the virtual prompts to use for Peft. Only applicable when using a prompt learning method.
r   r_  Nr/   r   dim)r   r      r/      rR   
model_typer   gemma2gemma3_textz4.56.0.dev0zmax_cache_len is missing but it should have been passed. Something went wrong, please open an issue on GitHub with a reproducer: https://github.com/huggingface/peft/issuesr&  )HybridCache)rR   max_batch_sizemax_cache_lenr   r  )rR   r  cache_position)cache_kwargs_supports_cache_classTF)6active_peft_configr   rV   r.  r`  ra  rA  rb  rc  r  rW   r8   r>  rD  r   repeatbase_model_torch_dtypeview
num_layersnum_attention_heads	token_dimr3  r   catpermutesplitr?  r_   r6   r   rR   ro  	packagingversionparsetransformersr0   r   r^   r&  rr  r   r   rC  rangerB  from_legacy_cacher\   r   cross_attention_cache
is_updatedr   rB   r;  )rb   
batch_sizetask_idsrt  rd   r   r.  past_key_valuesr\   model_configro  post_process_fntransformers_lt_4_56base_configrr  	new_cacherv  	layer_idx
key_statesvalue_statesr   promptss                         rh   
get_promptPeftModel.get_prompt  s    --,,T-@-@At223Yq\VJ#R((//667	 	   H$:$::)!-M{/M/M-M*MNM))"0":":"A"A"H"HUVXY"Z"0"?**6"1"4"4T5P5P"Q-22..&&*//%%)H)HHO 55:"'))_,NTU"V .55oFLL66:O ,,.J":x>L |R@JGKKDKKLbLbdhiu"Z[_[f[f[q[q"r"1/"Bj(mz.I'0'8'8'>'>|?W?W'X[d[l[l[r[r!\ ($ (m.CZ\I\$h  )//;(9::"-"="="?K' 9 +*'1&3-a066.q188!I !-K @I!&k.L.LUdefUgUnUn!o!&{'='=!>I/>q/A)/Lo^_N`ajNkJ$$"L)K[]kJl %  "?
 #,771< (1'8'8'>'>|?W?W'X[d[l[l[r[r!\ ($ (&2&D&D_&UO&2?&CO88A=7!8$D D (1'8'8'>'>|?W?W'X[d[l[l[r[r!\ ($ (&9&K&KO&\O&9/&JO8D5*55::<C6;O..s3 =)$*=*=*?Q""$$(H(HH(A N --,66==G %2"1$5M,];G!..Q:Nro   c                   SnSnU R                  5        H  u  p4UR                  5       nUS:X  a  [        US5      (       a  UR                  nUR                  R
                  S:X  aT  [        US5      (       a  UR                  5       nO*[        US5      (       d  SnOUR                  R                  nUS-  U-  nX%-  nUR                  (       d  M  X-  nM     X4$ )z[
Returns the number of trainable parameters and the number of all parameters in the model.
r   ds_numel
Params4bitelement_sizequant_storager/   r   )
r6  numelr^   r  rg   r   r  r  itemsizer1  )rb   trainable_params	all_paramr   rG  
num_params	num_bytess          rh   get_nb_trainable_parameters%PeftModel.get_nb_trainable_parametersN  s     	--/HAJQ75*#=#="^^

 ''<75.11 % 2 2 4I 88 !I % 3 3 < <I'!^i7
#I""" . ) 0,  **ro   c           	     b    U R                  5       u  p[        SUS SUS SSU-  U-  S 35        g)a  
Prints the number of trainable parameters in the model.

Note: print_trainable_parameters() uses get_nb_trainable_parameters() which is different from
num_parameters(only_trainable=True) from huggingface/transformers. get_nb_trainable_parameters() returns
(trainable parameters, all parameters) of the Peft Model which includes modified backbone transformer model.
For techniques like LoRA, the backbone transformer model is modified in place with LoRA modules. However, for
prompt tuning, the backbone transformer model is unmodified. num_parameters(only_trainable=True) returns number
of trainable parameters of the backbone transformer model which can be different.
ztrainable params: z,dz || all params: z || trainable%: d   z.4fN)r  print)rb   r  r  s      rh   print_trainable_parameters$PeftModel.print_trainable_parametersl  sa     '+&F&F&H# !1" 55EiPR^Scdgjzdz  ~G  eG  HK  dL  M	
ro   c                ~   >  [         TU ]  U5      $ ! [         a     US:X  a  e [        U R                  U5      s $ f = f)z1Forward missing attributes to the wrapped module.r\   )rT   __getattr__ru   r_   r\   )rb   r   rg   s     rh   r  PeftModel.__getattr__}  sC    	27&t,, 	2|#4??D11	2s    '<<c              /     #    [        U R                  S5      (       a;  U R                  (       a*  U R                  R                  " U0 UD6   S v   S S S 5        g S v   g ! , (       d  f       g = f7f)N_enable_peft_forward_hooks)r^   r\   ry   r  )rb   argsr   s      rh   r  $PeftModel._enable_peft_forward_hooks  sX      4??$@AAdFeFe;;TLVL M  MLs   A	A/AA/
A,(A/c                    U R                   " U0 UD6   UR                  5        VVs0 s H  u  p4X0R                  ;  d  M  X4_M     nnnU R                  5       " U0 UD6sSSS5        $ s  snnf ! , (       d  f       g= f)z
Forward pass of the model.
N)r  r   rX   r?  rb   r  r   r!  vs        rh   rd  PeftModel.forward  sl     ,,d=f='-||~a~tqB`B`9`dad~Fa&&($9&9 >=a >=s"   A.A( A(A.(A..
A<c                   U R                   " U0 UD6   UR                  5        VVs0 s H  u  p4X0R                  ;  d  M  X4_M     nnnU R                  5       R                  " U0 UD6sS S S 5        $ s  snnf ! , (       d  f       g = frk   )r  r   rX   r?  generater  s        rh   r  PeftModel.generate  sp    ,,d=f='-||~a~tqB`B`9`dad~Fa&&(114B6B >=a >=s"   A8A2 A2"A82A88
Bc                |    U(       d   U R                   R                  R                  $ U R                   R                  $ )z
Returns the base model class.
)r\   rc   rg   )rb   r   s     rh   r   PeftModel._get_base_model_class  s-      ??((222(((ro   c              #    #    U R                   U R                     R                  (       an   U R                  nU R                  R                  U l        U R
                  nU R                  R
                  U l        SU l        Sv   Xl        X l        SU l        gU R                   U R                     R                  (       aH   U R                  R                  5         SU l        Sv   U R                  R                  5         SU l        gU R                  5       nUR                  S:X  a  [        R                  " S5         U R                  R                  5         SU l        Sv   UR                  SLa  U R                  R                  5         SU l        g! WU l        WU l        SU l        f = f! U R                  R                  5         SU l        f = f! UR                  SLa  U R                  R                  5         SU l        f = f7f)z
Context manager that disables the adapter module. Use this to run inference on the base model.

Example:

```py
>>> with model.disable_adapter():
...     model(inputs)
```
TNF	irregularzThe model contains some adapter layers that are enabled and others that are disabled. This is most likely unintentional. After exiting the disable_adapter context, all adapters will be enabled)rd   rV   rY   rd  r\   prepare_inputs_for_generationra   is_adaption_promptdisable_adapter_layersenable_adapter_layersget_model_statusenabledr   r   )rb   old_forward!old_prepare_inputs_for_generationmodel_statuss       rh   disable_adapterPeftModel.disable_adapter  s     D//0CC0 #ll#66484V4V159__5b5b2*.'*5V2*/'d112EE0668*.'557*/'  002L##{2&
0668*.'''u4OO99;*/';  +5V2*/' 557*/'  ''u4OO99;*/'sN   )HAF <H%F0 'AH %G %1HF--H0#GH2HHc                |    U R                   R                  (       a  U R                  $ U R                  R                  $ )z
Returns the base model.
)ry  rY   r\   rc   rm   s    rh   r?  PeftModel.get_base_model  s.     #'"9"9"L"LtgRVRaRaRgRggro   c                   [         R                  " UR                  5      nU(       a"  X;   a  [        R                  " SU SU S35        UR                  U R                  :w  a&  [        SU R                   SUR                   S35      e UR                  (       a  X R                  U'   [        U R                  S5      (       a  U R                  R                  5       nOU R                  n[        X%5      nU R                  U5        [        U R                  U[        R                   " U 5      US9  g
UR"                  (       aF  U R                  R%                  X5        [        U R                  U[        R                   " U 5      US9  g
X R                  U'   U R                  R'                  U R                  R(                  XS	9  g
! [*         a    XR                  ;   a  U R                  U	 e f = f)  
Add an adapter to the model based on the passed configuration.

This adapter is not trained. To load a trained adapter, check out [`PeftModel.load_adapter`].

The name for the new adapter should be unique.

The new adapter is not automatically set as the active adapter. Use [`PeftModel.set_adapter`] to set the active
adapter.

Args:
    adapter_name (`str`):
        The name of the adapter to be added.
    peft_config ([`PeftConfig`]):
        The configuration of the adapter to be added.
    low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
        Create empty adapter weights on meta device. Useful to speed up the process when loading saved
        adapters. Don't use this option when creating a new PEFT adapter for training.

r  r  zK'. This may lead to reinitialization of the adapter weights during loading.z9Cannot combine adapters with different peft types. Found z and r   to_dict)rc   rd   r  rO   rK   N)r3   r   rW   r   r   r   rY   rd   r^   rR   r  r;   rK  r.   r\   r'   get_model_configr  r]   inject_adapterrc   	Exception)rb   rO   rd   rL   r   dict_configs         rh   r]   PeftModel.add_adapter  s   * -001F1FGl,MM .WX^W_ `[ [
   DNN2(k.C.C-DAG 
 	--1<  .4;;	22"&++"5"5"7K"&++K=kW**<80// +!*!;!;D!A!-	 //++LF0// +!*!;!;D!A!-	 2=  ...OO))< /   	///$$\2	s   B'G 3AG 
<G (G/c                    XR                   ;  a  [        SU S35      eU R                  R                  US9  U R                  n[        U5      nUS:X  a  US   U l        gg)z`
Deletes an existing adapter.

Args:
    adapter_name (str): Name of the adapter to be deleted.
Adapter z does not exist)rO   r/   r   N)rd   r   r\   r   rq   r   rV   )rb   rO   new_active_adaptersnum_adapterss       rh   r   PeftModel.delete_adapter(  sl     ///x~_EFF&&L&A"22./ 1"5a"8D ro   c                    [        5       nU R                  R                  5        H.  n[        USS 5      c  M  UR	                  UR
                  5        M0     U(       d  g U$ )Nmodules_to_save)r	  rd   r  r_   rB  r  )rb   r@  rR   s      rh   r  PeftModel.modules_to_save;  sQ    E&&--/Fv0$7Cv556 0
 ro   c                    [        U 5      $ )a  Get the status of each adapter layer in the model.

This method returns a list of `TunerLayerStatus` dataclass instances, each of which contains the following
attributes:

- `name` (`str`):
   The name of the adapter layer, e.g. `model.encoder.block.0.layer.0.SelfAttention.q`.
- `module_type` (`str`):
   The type of the adapter layer, e.g. `lora.Linear`.
- `enabled` (`bool`):
   Whether the adapter layer is enabled.
- `active_adapters` (`list[str]`):
   The names of the active adapters, if any, e.g. `["default"]`.
- `merged_adapters` (`list[str]`):
   The names of the merged adapters, if any, e.g. `["default"]`.
- `available_adapters` (`list[str]`):
   The names of the available adapters, e.g. `["default"]`.

Args:
    model ([`~PeftModel`]):
        The model to get the adapter layer status from.

Returns:
    list[`peft.peft_model.TunerLayerStatus`]:
        A list of dataclasses, each containing the status of the corresponding adapter layer.

)get_layer_statusrm   s    rh   r  PeftModel.get_layer_statusH  s    8  %%ro   c                    [        U 5      $ )a  Get the status of tuners of the model.

This method returns a `TunerModelStatus` dataclass instance, which contains the following attributes:

- `base_model_type` (`str`):
   The type of the base model, e.g. `T5Model`.
- `adapter_model_type` (`str`):
   The type of the adapter model, e.g. `LoraModel`.
- `peft_types` (`dict[str, str]`):
   The mapping of adapter name to adapter type, e.g. `{"default": "LORA"}`.
- `trainable_params` (`int`):
   The number of trainable parameters in the model.
- `total_params` (`int`):
   The total number of parameters in the model.
- `num_adapter_layers` (`int`):
   The number of adapter layers in the model.
- `enabled` (`bool`, `Literal["irregular"]`):
   Whether all adapter layers are enabled. If some are enabled and some are not, this will be `"irregular"`.
   This means that your model is in an inconsistent state and might not work as expected.
- `active_adapters` (`list[str]`, `Literal["irregular"]`):
   The names of the active adapters. If the active adapters are not consistent across all layers, this will be
   `"irregular"`, which means that your model is in an inconsistent state and might not work as expected.
- `merged_adapters` (`list[str]`, `Literal["irregular"]`):
   The names of the merged adapters. If the merged adapters are not consistent across all layers, this will be
   `"irregular"`, which means that your model is in an inconsistent state and might not work as expected.
- `available_adapters` (`list[str]`):
   The names of the available adapters, e.g. `["default"]`.

Args:
    model ([`~PeftModel`]):
        The model to get the adapter layer status from.

Returns:
    `peft.peft_model.TunerModelStatus`:
        A dataclass containing the status of the model.

)r  rm   s    rh   r  PeftModel.get_model_statusf  s    L  %%ro   c                    Sn0 n0 nUR                  5        H<  u  pVU[        R                  " [        5      R                  ;   d  XR;   a  XcU'   M8  XdU'   M>     X44$ )N)r   )r   inspect	signaturer   r0  )re   r   (_kwargs_not_in_hf_hub_download_signaturehf_hub_download_kwargsother_kwargsr   r|   s          rh   _split_kwargsPeftModel._split_kwargs  s^    3F0!# ,,.JCg''8CCCsGv.3s+$)S!	 ) &33ro   c           
        U(       d  U$ Sn[        U R                  R                  5       5      nU GH  n[        UR                  5       5      nUS   R                  S5      S   S-   nU Ho  nUR	                  S5      n	X8SU	 -   n
[        U R                  5       5      U
   n[        U[        5      (       a  X8SU	 -   S-   XS -   nOX8-   nXU   S'   X   X'   X	 Mq     [        5       n[        UR                  5       5       GH3  nX   S   n[        UR                  [        R                  5      5      n[        U5       H  u  nnSU;   d  M  UU==   S	-  ss'     O   [        R                  R                  " U6 nX;   a  M  0 n[        US
S9 nUR                  5        H  nUR!                  U5      nUR#                  5       nUR	                  S5      n	X7-   USU	 -   n
[        U R                  5       5      U
   n[        U[        5      (       az  U
S-   UU	S -   nUR%                  5        VVs0 s H  u  nnX;   d  M  UU_M     nnnUR%                  5        H-  u  nnUR	                  S5      nUSU SU 3-   UUS -   nUUU'   M/     OX7-   U-   nUUU'   M     UR'                  U5        UR                  5        H
  nUUS.X'   M     [        R                  R)                  U5      n[        R                  R+                  U5      (       d  [        R,                  " U5        [/        UUWS9  SSS5        GM6     GM
     gs  snnf ! , (       d  f       GMT  = f)ab  
Update the offload_index and safetensors files for loading and mergine PeftModels with disk-offloaded modules.

Args:
    offload_index (Dict[str: str]):
        Dictionary of disk-offloaded modules with their metadata and safetensors filenames
    adapters_weights (Dict[str: torch.tensor]):
        Dictionary of Peft adapter module names and weights
zbase_model.model.r   r   Nz.base_layerr   r   z--z-peftr   )	framework)r   r   r   )rs   rd   r   r  rfindr  r
  rr   r(   r	  r   sep	enumerater   r   r   
get_tensorr   r   r  r   r  r   r   ) rb   r   adapters_weightsr   rI   rO   r   block_idr   
suffix_posextended_prefixr  new_key
files_seenfnamenew_fname_listir   	new_fname	safe_dictfsafe_keysafe_tensorr   safe_module	final_keyr   	lora_dictlora_keylora_valdivide	base_names                                    rh   _update_offloadPeftModel._update_offload  sF      $T--2245)L**,-DAw}}S)!,s2H  YYs^
"({
+;";d0023ODfn55$;J'77-G#kJZZG$lG4;c"=1)6);&!&  J 2 2 45%./AB "&ekk"&&&9!:(8GAtt|&q)W4)  9 GGLL.9	&	u5$%FFH&'ll8&<#$::<%-^^C%8
*0*;h{
>S*S&*4+=+=+?&@&Q%k>BB(7-(G(S]S^J_(_IBRBXBXBZ(uBZhc3^m^tcBZI(u 7@oo6G 2()1)<*27F*;,>P*PS[\b\cSd*d5=	' 2 7H
 )/(9H(DI/:	),# %-$ NN9-  )~~/BK\_-`*  0 !#	 :I77>>)44I."9i(K9 65 6' *T )v 65s&   BM,L><L>C(M>M
Mc                   UR                   (       a  U(       a  [        S5      eU/[        U R                  R	                  5       5      -   n[        U5      S:  a  [        S U 5       5      (       a  Sn[        R                  " U5        g	[        S U 5       5      (       a  Sn[        R                  " U5        g	[        S U 5       5      (       a  Sn[        R                  " U5        g	g	g	)
z?Perform checks on newly added PEFT configs to ensure integrity.r   r/   c              3  B   #    U  H  n[        US S5      S:H  v   M     g7f)r   Nr   r*  r   rR   s     rh   r   6PeftModel._check_new_adapter_config.<locals>.<genexpr>  s!     cWbV76#6=HWb   zPiSSA changes the base weights of the model and should thus not be used with other adapters. Consider converting the PiSSA adapter into a normal LoRA adapter: https://github.com/huggingface/peft/tree/main/examples/pissa_finetuning#convert-pissa-to-lorac              3  B   #    U  H  n[        US S5      S:H  v   M     g7f)r   Nr   r*  r  s     rh   r   r    !     eYdvWV%8$?7JYdr  zCorDA changes the base weights of the model and should thus not be used with other adapters. Consider converting the CorDA adapter into a normal LoRA adapter: https://github.com/huggingface/peft/tree/main/examples/corda_finetuning#convert-corda-to-lorac              3  B   #    U  H  n[        US S5      S:H  v   M     g7f)r   Nr   r*  r  s     rh   r   r    r
  r  zOLoRA changes the base weights of the model and should thus not be used with other adapters. Consider converting the OLoRA adapter into a normal LoRA adapter: https://github.com/huggingface/peft/tree/main/examples/olora_finetuning#olora-and-loraN)	rY   r   rs   rd   r  r   r   r   r   )rb   rd   r   all_configsr   s        rh   _check_new_adapter_config#PeftModel._check_new_adapter_config  s    ))lqrr #md4+;+;+B+B+D&EE{acWbccct 
 c"eYdeeet 
 c"eYdeeem 
 c" f  ro   c	                   SSK Jn
  U R                  U	5      u  pUc
  [        5       nX R                  ;  aX  U
[
        R                  " U40 UD6   R                  " U4SU0UD6nU R                  XS9  U(       + Ul	        U R                  X,US9  [        U4XHS.UD6nU	R                  SS	5      n[        U UUUUS
9nU R                  U   R                  n[        R                  " US5      n/ nUR                    H$  nUU;   d  M  UU;   d  M  UR#                  U5        M&     UR                   R%                  5         UR                   R'                  U5        [)        U SS5      Gb  [+        [-        U R.                  R1                  5       5      R3                  SS15      5      S:  Gav  [+        U R                  5      S:X  Ga\  U	R                  SS5      nU	R                  SS5      nU	R                  SS5      nU	R                  SS5      nU	R                  SS5      nUb  Ub  [5        S5      eUc  Un0 nS[6        R8                  " [:        5      R<                  ;   a  UUS'   U R>                  nUS:w  a  [A        U UUUS:H  S9n[C        U[D        5      (       a  [G        U UUS9nU RI                  UU5        UUS'   [;        U 4UUS.UD6  [K        SS9nU R                  U   RL                  (       a  [O        U RP                  5        [S        U RU                  5       U5        [W        U RX                  S5      (       a  U RX                  R[                  X%S9  U(       d  U R]                  5         U$ ) a  
Load a trained adapter into the model.

The name for the new adapter should be unique.

The new adapter is not automatically set as the active adapter. Use [`PeftModel.set_adapter`] to set the active
adapter.

Args:
    model_id (`str` or `os.PathLike`):
        The name of the PEFT configuration to use. Can be either:
            - A string, the `model id` of a PEFT configuration hosted inside a model repo on the Hugging Face
              Hub.
            - A path to a directory containing a PEFT configuration file saved using the `save_pretrained`
              method (`./my_peft_config_directory/`).
    adapter_name (`str`):
        The name of the adapter to be added.
    is_trainable (`bool`, *optional*, defaults to `False`):
        Whether the adapter should be trainable or not. If `False`, the adapter will be frozen and can only be
        used for inference.
    torch_device (`str`, *optional*, defaults to None):
        The device to load the adapter on. If `None`, the device will be inferred.
    autocast_adapter_dtype (`bool`, *optional*, defaults to `True`):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter
        weights using float16 and bfloat16 to float32, as this is typically required for stable training, and
        only affect select PEFT tuners.
    ephemeral_gpu_offload (`bool`, *optional*, defaults to `False`):
        Whether to use ephemeral GPU offloading for partially loaded modules. Defaults to `False`.
    low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
        Create empty adapter weights on meta device before loading the saved weights. Useful to speed up the
        process.
    key_mapping (dict, *optional*, defaults to None)
        Extra mapping of PEFT `state_dict` keys applied before loading the `state_dict`. When this mapping is
        applied, the PEFT-specific `"base_model.model"` prefix is removed beforehand and the adapter name (e.g.
        `"default"`) is not inserted yet. Only pass this argument if you know what you're doing.
    kwargs: (`optional`):
        Additional arguments to modify the way the adapter is loaded, e.g. the token for Hugging Face Hub.
r/   )r2   Nr  )r   rK   )r  r   ignore_mismatched_sizesF)rO   r  rL   r   r   r   r   r   
device_mapr  
max_memoryoffload_folderoffload_dirr   z<Cannot use `offload_folder` when `offload_dir` is specified.
sequentialbalanced_low_0)r  no_split_module_classeslow_zero)r  r  )r  r  T)io_same_devicerM   rN   )/mappingr2   r  r@   rd   r1   r  r  r  r   r]   rA   r   rC   rW   r3   r  r   clearextendr_   r   r	  r   r  r  r   r  r  r   r0  _no_split_modulesr   rr   rt   r   r  r   rY   r   r   r   r?  r^   r\   rM   eval)rb   r  rO   r   torch_devicerP   r  rL   r   r   r2   r  rd   r  r  r   tunertuner_prefixadapter_missing_keysr   r  r  r  r  r   dispatch_model_kwargsr  hooks                               rh   r   PeftModel.load_adapter
  s   d 	9)-););F)C&'>L///5)),
 o 	 '<	 )	K **;*R-9)9K&\J[\,
)
F\

 #)**-F"N/%$;/
   .88266ubA! ++Cs"|s':$++C0 , 	  &&(  ''(<= T?D1=S++2245BBE6?STWXXD$$%*L&9JL$7J#ZZ(8$?N **]D9K"JJ=M&>+E !_``$,$&! '"3"3N"C"N"NN9F%o6&*&<&<#\)0),C(,<<	
 *c**2ZI`
   0@A5B!/2%' (	 $48D-@@+D,?,?@t224d;4??$9::OO//) 0 
 IIKro   c                    XR                   ;  a  [        SU S35      eXl        U R                   U   R                  (       d  U R                  R                  U5        g[        X5        g)a  
Sets the active adapter.

Only one adapter can be active at a time.

Additionally, this function will set the specified adapter to trainable (i.e., requires_grad=True). If this is
not desired, use the following code.

```py
>>> for name, param in model_peft.named_parameters():
...     if ...:  # some check on name (ex. if 'lora' in name)
...         param.requires_grad = False
```

Args:
    adapter_name (`str`):
        The name of the adapter to be set as active. The adapter must be loaded first.
r  z not found.N)rd   r   rV   rY   r\   set_adapterr<   )rb   rO   s     rh   r'  PeftModel.set_adapter  sZ    & ///x~[ABB*-@@OO''5 ,ro   c                    U R                   R                  (       a-  [        SU R                   R                  R                   S35      eU R
                  R                  XS9  g)ag  
Enable or disable gradients on the given adapter(s).

Note: Not supported for prompt learning methods like prompt tuning.

Args:
    adapter_name (`str` or `Sequence[str]`):
        The name of the adapter(s) whose gradients should be enabled/disabled.
    requires_grad (`bool`, *optional*)
        Whether to enable (`True`, default) or disable (`False`).
zJSetting `requires_grad` is not supported for prompt learning methods like r   )rI   r1  N)ry  rY   r  rW   r|   r\   set_requires_grad)rb   rI   r1  s      rh   r*  PeftModel.set_requires_grad  sY     ""55\**44::;1> 
 	)))cro   c                0    [        U R                  SS 5      $ )Nr   )r_   r\   rm   s    rh   r{   PeftModel.base_model_torch_dtype  s    t66ro   c                4    U R                   U R                     $ rk   )rd   rV   rm   s    rh   ry  PeftModel.active_peft_config  s     3 344ro   c                   U R                   R                  n[        U[        5      (       d  UR                  n/ n[        U R                  S5      (       aD  [        U R                  R                  [        R                  5      (       a  UR                  S5        US:X  a  UR                  S5        [        U R                  S5      (       a(  UR                  SU R                  R                   35        U$ )zDerive tags for the model card from the adapter's config. For example, setting the
base model is important for enabling support for HF inference providers but it also makes models more
searchable on the HF hub.
rc   r  LORAlorar   zbase_model:adapter:)ry  rW   rr   rt   r|   r^   r\   rc   r  r    r   r   )rb   peft_methodtagss      rh   _get_peft_specific_model_tags'PeftModel._get_peft_specific_model_tags  s    
 --77+s++%++K4??G,,DOO<Q<QS_SoSo1p1pKK'& KK4??N33KK-doo.J.J-KLMro   c                .   [         R                  R                  US5      n[         R                  R                  U5      (       a  [        R
                  " U5      O[        R                  " [        5       5      nSUR                  S'   [        5       nU R                  5       n[        US5      (       a$  UR                  UR                  =(       d    / 5      nUR                  U R                  5       5      nU(       a  [        U5      UR                  S'   UR                  R                   (       d&  [#        U [$        5      (       a  SUR                  l        [&        R(                  " U 5      nU[*        :X  a  SOUnUb  SU;   a  US   UR                  S	'   UR,                  R/                  5       nSn[        US
5      (       a$  U R0                  R2                  R5                  5       nSn	Sn
UbK  U	SU
 S3-  n	U	SR                  UR7                  5        VVs/ s H  u  pSU SU 3PM     snn5      -  n	U	S-  n	SnX;  aP  [9        U	5      (       a@  X;   a%  UR;                  UR=                  U5      S-   U	5        OUR?                  U SU	 35        SnS[@         3U;  aK  X;   a,  UR;                  UR=                  U5      S-   S[@         35        OUR?                  U S[@         35        SR                  U5      Ul        URC                  U5        gs  snnf )z
Updates or create model card to include information about peft:
1. Adds `peft` library tag
2. Adds peft version
3. Adds base model info
4. Adds quantization information if it was used
z	README.mdpeftlibrary_name
model_tagsr4  ztext-generationN_name_or_pathr\   quantization_configr   zJThe following `bitsandbytes` quantization config was used during training:
z- z: z## Training procedurer   z### Framework versionsz- PEFT z	

- PEFT )"r   r   r   r  r   loadfrom_templater   datar	  r?  r^   unionr:  r5  sortedpipeline_tagrr   PeftModelForCausalLMr'   r  r*   text
splitlinesrR   r<  r  r   boolinsertr  r   r0   r   )rb   r   filenamecardr4  r\   r  linesr<  training_config_textquantization_prefixr   r|   training_procedure_headingframework_block_headings                  rh   r   %PeftModel.create_or_update_model_card  s    77<<
K8+-77>>(+C+Cy~~h'I`I`anapIq$*		.!u((*
:|,,::j339r:Dzz$<<>? &tDIIf yy%%*T;O*P*P%6DII" 11$7+/AAt|#<(G&2?&CDIIl#		$$&"<!677"&++"A"A"I"I"K!j* b)<(=R$@@  DIIWjWpWpWr.sWrD6E7/CWr.s$tt  D( %<"+5I0J0J)2U[[)CDqHJ^_ :;2>R=STU #;[M"%/&/U[[)@AAEQ\P]G^_ 78K=QRIIe$			(' /ts   L)ra   rZ   r[   rV   r\   rd  rW   r  r   r.  rX   r2  r9  )r   TF)rc   r    rd   r1   rO   rt   rP   rG  rL   rG  returnNone)rQ  dict[str, PeftConfig])rQ  	list[str])rQ  rG  )r|   rS  )TNr  TN)r   rt   r   rG  r   zOptional[list[str]]r   zUnion[str, bool]r   rG  r   Optional[str]r   r	   rQ  rR  )r   FNTFFN)rc   torch.nn.Moduler  Union[str, os.PathLike]rO   rt   r   rG  rR   zOptional[PeftConfig]rP   rG  r  rG  rL   rG  r   Optional[dict[str, str]]r   r	   rQ  rF   )rO   rt   )rc   r    )rO   rt   rQ  torch.Tensor)NN)r  intr  Optional[torch.Tensor]rt  zOptional[int]rQ  rY  )rQ  ztuple[int, int])rQ  rR  )r   rt   )r  r	   r   r	   F)rQ  rV  rO   rt   rd   r1   rL   rG  rQ  rR  )rO   rt   rQ  rR  )rQ  zOptional[set[str]])rQ  list[TunerLayerStatus])rQ  TunerModelStatus)r   zdict[str, Any])r   zdict[str, dict[str, str]]r  zdict[str, torch.tensor])rd   r1   r   rG  rQ  rR  )FNTFFN)r  rW  rO   rt   r   rG  r  rU  rP   rG  r  rG  rL   rG  r   rX  r   r	   )T)rI   zstr | Sequence[str]r1  rG  rQ  rR  )r   rt   ).r   r   __qualname____firstlineno____doc__rU   propertyrd   rq   ry   setterr   classmethodr  rK  r`   rN  rh  r  r  r  r  r   r  rd  r  r   r  r?  r]   r   r  r  r  r  r  r  r   r'  r*  r{  ry  r5  r   __static_attributes____classcell__rg   s   @rh   rF   rF   H   sf   F &'+"')()(  )( 	)(
 !%)(  )( 
)( )(V + +
  $ G G 0 0 $(1528 $BFD8D8 !D8 /	D8
  0D8 D8 3@D8 D8 
D8L 
 &"'+'+&+"'04SS *S 	S
 S %S !%S  $S  S .S S 
S SjJX> 3, hl{{)?{Wd{	{z+<
"2 
 
:C
) 30 30jhBH9& 
 
&<&&P 4 4NL`#D #&*'+&+"'04`)` ` 	`
 $` !%`  $`  ` .` `D-:d( 7 7 5 5,? ?ro   rF   c                     ^  \ rS rSrSr S       S	U 4S jjjrS
SU 4S jjjr        SS jr       SS jrSr	U =r
$ )"PeftModelForSequenceClassificationi=  a  
Peft model for sequence classification tasks.

Args:
    model ([`~transformers.PreTrainedModel`]): Base transformer model.
    peft_config ([`PeftConfig`]): Peft config.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.

**Attributes**:
    - **config** ([`~transformers.PretrainedConfig`]) -- The configuration object of the base model.
    - **cls_layer_name** (`str`) -- The name of the classification layer.

Example:

    ```py
    >>> from transformers import AutoModelForSequenceClassification
    >>> from peft import PeftModelForSequenceClassification, get_peft_config

    >>> config = {
    ...     "peft_type": "PREFIX_TUNING",
    ...     "task_type": "SEQ_CLS",
    ...     "inference_mode": False,
    ...     "num_virtual_tokens": 20,
    ...     "token_dim": 768,
    ...     "num_transformer_submodules": 1,
    ...     "num_attention_heads": 12,
    ...     "num_layers": 12,
    ...     "encoder_hidden_size": 768,
    ...     "prefix_projection": False,
    ...     "postprocess_past_key_value_function": None,
    ... }

    >>> peft_config = get_peft_config(config)
    >>> model = AutoModelForSequenceClassification.from_pretrained("bert-base-cased")
    >>> peft_model = PeftModelForSequenceClassification(model, peft_config)
    >>> peft_model.print_trainable_parameters()
    trainable params: 370178 || all params: 108680450 || trainable%: 0.3406113979101117
    ```
c           	       >^ SS/n[        US5      (       a3  UR                  c  US S  Ul        OUR                  R                  U5        [        TU ]  " XU40 UD6  [        US5      (       aQ  U R
                  R                  5        H3  u  mn[        U4S jU R                   5       5      (       d  M,  TU l          O   [        U U[        USS 5      UR                  S9  g )N
classifierscorer  c              3  ,   >#    U  H	  oT;   v   M     g 7frk    r   module_namer   s     rh   r   >PeftModelForSequenceClassification.__init__.<locals>.<genexpr>|  s     S>R{d*>R   module_namesr   )r^   r  r  rT   rU   r\   r/  r   cls_layer_namer=   r_   r   	rb   rc   rd   rO   r   classifier_module_namesr   r   rg   s	          @rh   rU   +PeftModelForSequenceClassification.__init__j  s     $0"9; 122**2.Ea.H+++223JK
 	\DVD; 122??99;aSd>R>RSSS*.D' < 	 .?F&55		
ro   c                   > [        US5      (       a7  SS/nUR                  c  USS Ul        OUR                  R                  U5        [        TU ]  XUS9$ r  r  rl  rm  NrK   r^   r  r  rT   r]   rb   rO   rd   rL   rx  rg   s        rh   r]   .PeftModelForSequenceClassification.add_adapter  b    , ; 122'3W&=#**2.Ea.H+++223JKw"<Pa"bbro   c	                F   Ub  UOU R                   R                  nU R                  n
U
R                  (       d  U R                  " S0 U	D6   U	R                  5        VVs0 s H  u  pXR                  ;  d  M  X_M     n	nnU
R                  [        R                  :X  a  XS'   U R                  " SUUUUUUUS.U	D6sS S S 5        $ [        X5      nUbO  [        R                  " XR                  5      R                  UR                   5      n[        R"                  " X4SS9nU	R%                  SS 5      b  [&        R(                  " S5        S U	S'   U	R+                  UUUUUS.5        U
R                  [        R,                  :X  a  U R.                  " SSU0U	D6$ U	R%                  S	S 5      bv  [        R"                  " [        R0                  " XR                  5      R                  U R2                  R4                  R                   5      U	S	   4SS9R7                  5       U	S	'   Uc  U R3                  U5      nU R9                  XS
9nUR                  UR:                  5      n[        R"                  " X4SS9nU R                  " SSU0U	D6$ s  snnf ! , (       d  f       GN= fNr  	input_idsattention_maskinputs_embedslabelsoutput_attentionsoutput_hidden_statesreturn_dictr/   rk  position_idsUPosition ids are not supported for parameter efficient tuning. Ignoring position ids.r  r  r  r  r  r  token_type_idsr  r  r  ro  )rR   use_return_dictry  rY   r  r   rX   rW   r8   POLYr\   r:   r   onesrD  rA  r  r  r   r   r   rB  r>  _prefix_tuning_forwardzerosr9  rc  rE  r  r   rb   r  r  r  r  r  r  r  r  r   rd   r!  r  r  prefix_attention_maskr  s                   rh   rd  *PeftModelForSequenceClassification.forward  sl    &1%<k$++B]B]----00:6:+1<<>e>41QFdFd=d$!$>e((HMM9)1:& 	'#1"/!&7)= +	 		 ;: %Y>
%$)JJz;Y;Y$Z$]$]^l^s^s$t!"YY(='NTUVN::nd+7MMqr%)F>""0 %6(<*	
   H$:$::..MMfMMzz*D1=+099J0N0NORRSWSgSgSnSnSuSuv/0 , $& '( $ $ 4 4Y ?oooOGjj!4!45G!IIw&>AFM??II&IIa f ;:$   JJ8J>>JJ
J c           
     j   [        X5      n	U R                  U	5      n
[        [        R                  " U R
                  R                  5      R                  R                  5       5      nUR                  UUUUUUU
S.5        SU;   a  U R
                  " SSU0UD6$ U R
                  R                  U R                  5      n[        [        R                  " UR                  5      R                  R                  5       5      nSU;  a  [        S5      eU" S0 UD6n[        U5      S:  a  US   OUS   nS[        U R
                  R                  5       5       VVs/ s H  u  nnUPM
     snn;   a  U R
                  R                  U5      nU R
                  R                  U R                   5      " U5      nS nUGb  U R"                  R$                  c  U R
                  R&                  S:X  a  SU R"                  l        OyU R
                  R&                  S:  aN  UR(                  [*        R,                  :X  d  UR(                  [*        R.                  :X  a  S	U R"                  l        OS
U R"                  l        U R"                  R$                  S:X  aT  [1        5       nU R
                  R&                  S:X  a&  U" UR3                  5       UR3                  5       5      nOU" UU5      nOU R"                  R$                  S	:X  aG  [5        5       nU" UR7                  SU R
                  R&                  5      UR7                  S5      5      nO-U R"                  R$                  S
:X  a  [9        5       nU" UU5      nU(       d  U4USS  -   nUb  U4U-   $ U$ [;        UUUR<                  UR>                  S9$ s  snnf )Nr  r  r  r  r  r  r  r  r  LModel does not support past key values which are required for prefix tuning.r/   r   dropout
regressionsingle_label_classificationmulti_label_classificationr_  r   losslogitshidden_states
attentionsro  ) r:   r  rs   r  r  r\   rd  r0  r   rB  r5  r2  r   r   r/  r  rv  rR   problem_type
num_labelsr   r   rE  rZ  r   squeezer   r|  r   r"   r  r  )rb   r  r  r  r  r  r  r  r   r  r  
fwd_paramsr2  outputspooled_outputr   r   r  r  loss_fctrY  s                        rh   r  9PeftModelForSequenceClassification._prefix_tuning_forward  s    %Y>
//*5'++DOO,C,CDOOTTVW
&"0!.%6(<*#2
	
 
*??;&;F;;(,(E(EdFdFd(e%g//0I0Q0QR]]bbdeJ 
2 !opp/9&9G*-g,*:GAJ
Mdoo6T6T6V1WX1WgdAT1WXX $ 7 7 F__2243F3FGVFD!;;++311Q63?033a7V\\UZZ=W[a[g[gkpktkt[t3P03O0;;++|;&yH11Q6'(8&..:JK'7[[--1NN/1H#FKKDOO4N4N$OQWQ\Q\]_Q`aD[[--1MM02H#FF3D WQR[0-1-=&(I6I+%33"--	 = Ys   N/rv  r   rc   rV  rd   r1   rO   rt   rQ  rR  r\  r]  NNNNNNNNNNNNNNNr   r   r`  ra  rb  rU   r]   rd  r  rf  rg  rh  s   @rh   rj  rj  =  s    *Z T]
$
3=
MP
	
 
<c cB !@JH !E Ero   rj  c                  |   ^  \ rS rSrSr S       SU 4S jjjr        SS jrS rS rSS.SS	 jjr	S
r
U =r$ )rD  i1  a  
Peft model for causal language modeling.

Args:
    model ([`~transformers.PreTrainedModel`]): Base transformer model.
    peft_config ([`PeftConfig`]): Peft config.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.

Example:

    ```py
    >>> from transformers import AutoModelForCausalLM
    >>> from peft import PeftModelForCausalLM, get_peft_config

    >>> config = {
    ...     "peft_type": "PREFIX_TUNING",
    ...     "task_type": "CAUSAL_LM",
    ...     "inference_mode": False,
    ...     "num_virtual_tokens": 20,
    ...     "token_dim": 1280,
    ...     "num_transformer_submodules": 1,
    ...     "num_attention_heads": 20,
    ...     "num_layers": 36,
    ...     "encoder_hidden_size": 1280,
    ...     "prefix_projection": False,
    ...     "postprocess_past_key_value_function": None,
    ... }

    >>> peft_config = get_peft_config(config)
    >>> model = AutoModelForCausalLM.from_pretrained("gpt2-large")
    >>> peft_model = PeftModelForCausalLM(model, peft_config)
    >>> peft_model.print_trainable_parameters()
    trainable params: 1843200 || all params: 775873280 || trainable%: 0.23756456724479544
    ```
c                `   > [         TU ]  " XU40 UD6  U R                  R                  U l        g rk   )rT   rU   r\   r  (base_model_prepare_inputs_for_generationrb   rc   rd   rO   r   rg   s        rh   rU   PeftModelForCausalLM.__init__Z  s+     	\DVD8<8e8e5ro   Nc	                   U R                   n
U
R                  (       d  [        XU40 U	D6n	U R                  R                  R
                  S:X  a'  Ub  [        S5      eU R                  " SUUUUUUS.U	D6$ U
R                  [        R                  :X  a  XS'   U R                  " S0 U	D6   U	R                  5        VVs0 s H  u  pXR                  ;  d  M  X_M     n	nnU R                  " SUUUUUUUS.U	D6sS S S 5        $ [        X5      nUbO  [        R                  " XR                   5      R#                  UR$                  5      n[        R&                  " X4SS9nU	R)                  SS 5      b  [*        R,                  " S	5        S U	S'   U	R)                  S
S 5      b  [*        R,                  " S5        S U	S
'   U	R/                  UUUUUS.5        U
R                  [        R0                  :X  ab  Ub  UR2                  S   U
R                   -   nOUR2                  S   U
R                   -   nU R5                  XS9U	S'   U R                  " SXS.U	D6$ U
R                  [        R6                  :X  a  U R8                  " XXU40 U	D6$ Uc  U R;                  U5      nUbU  [        R<                  " XR                   4S5      R#                  UR$                  5      n[        R&                  " UU4SS9U	S'   U R5                  XS9nUR#                  UR>                  5      n[        R&                  " UU4SS9nU R                  " SSU0U	D6$ s  snnf ! , (       d  f       GNY= f)Nmptz8forward in MPTForCausalLM does not support inputs_embeds)r  r  r  r  r  r  r  r  r/   rk  r  r  r  XToken type ids are not supported for parameter efficient tuning. Ignoring token type idsr  )rt  r  )r  r  r  r  r  ro  ) ry  rY   r%   r\   rR   ro  AssertionErrorrW   r8   r  r  r   rX   r:   r   r  rD  rA  r  r  r   r   r   rB  r>  r8  r  r<  _cpt_forwardr9  fullr   )rb   r  r  r  r  r  r  r  r  r   rd   r!  r  r  r  rt  prefix_labelsr  s                     rh   rd  PeftModelForCausalLM.forward`  sF    ----24M\U[\F%%00E9 ,()cdd '#1!&7)= +   $$5%-z"00:6:+1<<>e>41QFdFd=d$!$>e 	'#1"/!&7)= +	 	 ;: %Y>
%$)JJz;Y;Y$Z$]$]^l^s^s$t!"YY(='NTUVN::nd+7MMqr%)F>"::&-9MMtu'+F#$"0 %6(<*	
   H$:$:: $ ) 2[5S5S S - 3 3A 69W9W W(,
(`F$%??^Y^W]^^""hll2$$Y{V`kdjkk$ $ 4 4Y ?! %

J8V8V+WY] ^ a abhbobo p#(99mV-D!#Lx oooOGjj!4!45G!IIw&>AFM??II&IIo f ;:s$   *M>MMMM
Mc                D   UR                  S5      nXU4 Vs/ s H  oc  M  UR                  PM     snS   n	SUR                  5       ;   a!  UR                  S5      R                  U	5      n
OKUc  UR                  S   nOUR                  S   n[
        R                  " X[45      R                  U	5      S-  n
UR                  nUR                  nUc  U R                  U5      nU R                  XTS9nUR                  UR                  5      n[
        R                  " X4SS9nS nUGb   [
        R                  " U5      R                  5       R                  SS5      nUR!                  US5      R                  UR                  5      n[
        R                  " UU4SS9n[
        R                  " U5      R                  5       R                  SS5      nUR!                  US5      R                  UR                  5      nU
nUUS:  ==   UR#                  5       -  ss'   [
        R                  " UU4SS9nUS:  US-  S:H  -  nS	UU) '   XS'   U R$                  " SS
U0UD6nUc  U$ [&        UR(                     nUR+                  UUWU R,                  S   5      nU$ s  snf )Nr  r   input_type_maskr/   rn  r  rk  r_  r  r  r   ro  )popr  r   rA  r8  r   r  cpt_token_idscpt_tokens_type_maskr9  r  r   r  r   rE  r|  rz  maxr\   r4   rW   calculate_lossrd   )rb   r  r  rd   r  r  r   r  r  r  r  N_tokensr  r  r  
cpt_labelsr  prefix_type_maskadjusted_input_type_maskcpt_type_mask
labels_idxbase_model_outputcpt_embeddings                          rh   r  !PeftModelForCausalLM._cpt_forward  s   H%%.v$FX$Fq(!(($FXYZ[-$jj):;>>vFO (..q1$??1-#jj*)?@CCFKaOO#11*??   00;M//Z/K**]001		7":B
!LL7<<>CCArJM)00Q?BB6==QMM6#:BJ$||,@AFFHMMaQST/66z1EHHW'6$$%=%ABFVFZFZF\\B!II'79Q&RXYZM'!+0AQ0FGJ&*J
{# &x OOR-R6R>$$ 7{7L7LMM - < <!:}d>N>Ny>Y! %$g Ys
   JJc                   U R                   nU R                  U R                  l        [        U R                  S5      (       a&  U R                  U R                  R
                  l        OU R                  U R                  l         UR                  (       d|  [        U /UQ70 UD6nU R                  " U0 UD6   UR                  5        VVs0 s H  u  pEX@R                  ;  d  M  XE_M     nnnU R                  R                  " U0 UD6nS S S 5        OU R                  R                  " S0 UD6nU R                  U R                  l        W$ s  snnf ! , (       d  f       N1= f!   U R                  U R                  l        e = f)Nrc   ro  )ry  r  r\   r^   generation_configrc   rY   r&   r  r   rX   r  r  )rb   r  r   rd   r!  r  r  s          rh   r  PeftModelForCausalLM.generate  s:   --8<8Z8Z54??G,,6:6L6LDOO!!3040F0FDOO-	117NtNvN44dEfE/5||~i~tqJhJhAhdad~Fi"oo66GGG FE //22<V<
 =A<i<iDOO9N j FE
	<@<i<iDOO9s<   2E" 7EE$E*E	%E" E
EE" "F r  c               L   U R                   nU R                  " U0 UD6n[        R                  R	                  [
        R                  5      [        R                  R	                  S5      :  n[        R                  R	                  [
        R                  5      [        R                  R	                  S5      :  n/ SQn[        R                  R	                  [
        R                  5      [        R                  R	                  S5      :  a  UR                  S5        U=(       d,    U=(       a#    U R                  R                  R                  U;   n	UR                  S5      S L=(       a    US   S   S:H  n
UR                  [        R                  :X  a  XS'   UR                  (       Ga  U	(       a  UR                  S	S 5      bl  US	   n[!        U["        [$        45      (       a  US   S   R&                  S
   nOUR)                  5       nXS   R&                  S   :  a  US   S S 2SS 24   US'   UR                  SS 5      =nGb  [!        U[*        5      (       aC  [-        U5      S:w  a  [/        S[-        U5       S35      e[%        UR1                  5       5      S   nUS   R&                  S   UR2                  4n[4        R6                  " U5      R9                  US   R:                  5      nUR=                  5       S:X  a  UR&                  S   nUR&                  S   UR&                  S   -   n[4        R6                  " UU4UR>                  S9nU
(       aA  UR                  [        R@                  :w  a#  [4        RB                  " UUS   R:                  S9nOUS   n[E        U RG                  5       S UUR                  S	5      UUUUR                  SS 5      S9nUUS'   O[4        RH                  " X4SS9US'   UR                  SS 5      b  [J        RL                  " S5        S US'   UR                  SS 5      b  [J        RL                  " S5        S US'   UR                  S	S 5      nUS L =(       d6    [!        U[
        RN                  5      =(       a    UR)                  5       (       + nU(       a  UR                  [        R@                  :X  as  [!        U[
        RN                  5      (       a,  [!        U[
        RP                  5      (       d  URR                  nOSnU RU                  US   R&                  S   US9nUUS	'   OuU(       an  U RW                  US   5      nU RU                  US   R&                  S   US9nUR9                  UR>                  5      n[4        RH                  " UU4SS9US'   S US'   U
(       a7  UR                  [        R@                  :X  a  US==   UR2                  -  ss'   U$ UR                  [        R@                  :w  a  URY                  SS 5      nU$ )Nz4.38.0z4.36.0)llamamistral	persimmonphiz4.43.3bloomrv  r   r  r  r  r/   r_  r  z&Expected a single attention mask, got za instead, please open an issue (https://github.com/huggingface/peft/issues) and report the error.rn  r   )r   ru  r  )model_inputr  r  rv  r  sequence_lengthr  rk  r  r  r  )r  rt  r  r  )-ry  r  r  r  r  r  r0   r   r\   rR   ro  r   rW   r8   r  rY   rr   tuplers   r8  get_seq_lengthr  r   r   r  rD  r   r  rA  r  rl  r   r>  rC  r-   r?  r  r   r   r   r   rt  r  r9  r  )rb   r  r  r   rd   model_kwargsuses_transformers_4_38uses_transformers_4_36transformers_new_cache_archs
uses_cache
is_prefillr  seq_lenr  sizer  bstotal_seq_lenattention_mask_2dcache_position_attention_mask_newcacherequires_prompt_injectionrt  new_past_key_valuesr  r  r   s                               rh   r  2PeftModelForCausalLM.prepare_inputs_for_generation
  s   --DDdUfU
 "+!2!2!8!89Q9Q!RV_VgVgVmVmnvVw!w!*!2!2!8!89Q9Q!RV_VgVgVmVmnvVw!w'O$""<#;#;<y?P?P?V?VW_?``(//8+ 
"ht'='='H'HLh'h 	 #&&'78Dr<XhKijkKlpqKq
  HMM1'/$)))|//0A4HT #//@"Aot}==-a0399"=G-<<>G;7==a@@0<[0I!RS&0QL-"."2"23CT"JJWnd33 >*a/(DSEXDY Zg g  &*.*?*?*A%B1%EN#K066q9;;Y;YY(-

4(8(;(;L<U<\<\(]%!%%'1,
 (--a0B$9$?$?$B^EYEYZ[E\$\M(-

B3FnNbNb(c%!{'<'<@V@V'V +0,,}\ZeMfMmMm*n +77G*H)>++-$('8(4(8(89J(K'6#%(5%1%5%5nd%K	*& 6HL!12 6;YY@U?flm5nL!125Auv/3^,zz*D1=n ,0'(/;/?/?@QSW/XE).$ )5,"4"45Te>R>R>T:T & )[-B-BhF\F\-\e\%7%788ES_SlSlAmAm$)$7$7M$&M&*oo+K8>>qA"/ '6 '# 3F./* $ 4 4\+5N O//\+5N5T5TUV5Wbj/k!**]%8%8905		7M:RXY0Z_-,0[) ;00H4J4JJ)*k.L.LL*  ""h&<&<<
   !148Aro   )r  r  r  r  )r  r[  )r   r   r`  ra  rb  rU   rd  r  r  r  rf  rg  rh  s   @rh   rD  rD  1  s    &R T]f$f3=fMPf	f f !YJv6%p. W[  ro   rD  c                  |   ^  \ rS rSrSr S
       SU 4S jjjr           SS jrS rSS.SS jjrS	r	U =r
$ )PeftModelForSeq2SeqLMi  av  
Peft model for sequence-to-sequence language modeling.

Args:
    model ([`~transformers.PreTrainedModel`]): Base transformer model.
    peft_config ([`PeftConfig`]): Peft config.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.

Example:

    ```py
    >>> from transformers import AutoModelForSeq2SeqLM
    >>> from peft import PeftModelForSeq2SeqLM, get_peft_config

    >>> config = {
    ...     "peft_type": "LORA",
    ...     "task_type": "SEQ_2_SEQ_LM",
    ...     "inference_mode": False,
    ...     "r": 8,
    ...     "target_modules": ["q", "v"],
    ...     "lora_alpha": 32,
    ...     "lora_dropout": 0.1,
    ...     "fan_in_fan_out": False,
    ...     "enable_lora": None,
    ...     "bias": "none",
    ... }

    >>> peft_config = get_peft_config(config)
    >>> model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")
    >>> peft_model = PeftModelForSeq2SeqLM(model, peft_config)
    >>> peft_model.print_trainable_parameters()
    trainable params: 884736 || all params: 223843584 || trainable%: 0.3952474242013566
    ```
c                   > [         TU ]  " XU40 UD6  U R                  R                  U l        U R                  R
                  U l        g rk   )rT   rU   r\   r  r  ._prepare_encoder_decoder_kwargs_for_generation8base_model_prepare_encoder_decoder_kwargs_for_generationr  s        rh   rU   PeftModelForSeq2SeqLM.__init__  s@     	\DVD8<8e8e5OOJJ 	Ero   Nc                
   U R                   nUR                  (       d  UR                  [        R                  :X  a  XS'   U R
                  " S0 UD6   UR                  5        VVs0 s H  u  pXR                  ;  d  M  X_M     nnnU R                  " SUUUUUUUUU	U
S.
UD6sS S S 5        $ [        X5      nUb  [        R                  " UUR                  5      R                  UR                  5      nUR                  [        R                  [        R                   4;  a  [        R"                  " UU4SS9nUR%                  SS 5      b  [&        R(                  " S5        S US'   UR%                  SS 5      b  [&        R(                  " S5        S US'   UR+                  UUUUU	U
S	.5        UR                  [        R,                  :X  a*  U R/                  U5      US
'   U R                  " SUUUS.UD6$ UR                  [        R                  [        R                   4;   a  Uc  U R1                  U5      nUbT  [        R                  " UUR                  5      R                  UR                  5      n[        R"                  " UU4SS9US'   U R/                  US9nUR                  UR2                  5      n[        R"                  " US S 2S UR                  24   U4SS9nU R                  " SUUUS.UD6$ Uc  U R1                  U5      nUcH  UcE  [5        XpR6                  R8                  U R6                  R:                  5      nU R1                  U5      nUbT  [        R                  " UUR                  5      R                  UR                  5      n[        R"                  " UU4SS9US'   Ub{  UR<                  S:X  a  X|S'   OfUR<                  S:X  aV  [        R>                  " UUR                  4S5      R                  UR                  5      n[        R"                  " UU4SS9US'   U R/                  UUS9nUR                  UR2                  5      n[        R"                  " US S 2S UR                  24   U4SS9nUR<                  S:X  a  U R                  " SSU0UD6$ UR<                  S:X  a>  [        R"                  " US S 2UR                  S 24   U4SS9nU R                  " SX6S.UD6$ g s  snnf ! , (       d  f       GN]= f)Nr  )
r  r  r  decoder_input_idsdecoder_attention_maskdecoder_inputs_embedsr  r  r  r  r/   rk  r  r  r  r  )r  r  r  r  r  r  r  )r  r  r  r  r  )r  r  r  r  r   r  r  r  )r  r  ro  ) ry  rY   rW   r8   r  r  r   rX   r\   r:   r   r  rD  rA  r  r:  r=  r  r   r   r   rB  r>  r  r9  r   rD   rR   pad_token_iddecoder_start_token_idr3  r  )rb   r  r  r  r  r  r  r  r  r  r  r  r   rd   r!  r  r  r  r  r  s                       rh   rd  PeftModelForSeq2SeqLM.forward  s    ----$$5%-z"00:6:+1<<>e>41QFdFd=d$!$>e '#1"/&7+A*?!&7)= +  ;:  %Y>
!-$)JJz;;Y;Y$Z$]$]&--%! $$X-C-CXEVEV,WW).4IKa3bhi)j&::nd+7MMqr%)F>"::&-9MMtu'+F#$"0*@ %6(<*		
   H$:$::(,
(CF$%?? #"3&; 	  ""x'='=x?P?P&QQ$ $ 4 4Y ?)(-

:{?]?](^(a(a")))% ,1996K^5\bc+d'(ooo<Gjj!4!45G!IIwq2RK4R4R2R/R'SUb&cijkM?? +"3&; 	  $ $ 4 4Y ?$,1B1J$6KK44dkk6X6X%! )-(<(<=N(O%)(-

:{?]?](^(a(a")))% ,1996K^5\bc+d'(!99Q>'-8$ ;;q@$)JJ
K<Z<Z/[]a$b$e$eflfsfs$tM',yy-1Ha'PF8$oohoOGjj!4!45G!IIwq2RK4R4R2R/R'SUb&cijkM55:M]MfMM771<(-		Q > > @@ACXY_`)%  "/`f 	 =E f ;:s$   S<&S6?S6S<6S<<
Tc                   U R                   nU R                  U R                  l        U R                  U R                  l         UR                  (       dn  U R
                  " S0 UD6   UR                  5        VVs0 s H  u  p4X0R                  ;  d  M  X4_M     nnnU R                  R                  " S0 UD6nS S S 5        GO*SU;  a  [        S5      eUR                  SS 5      b  [        R                  " S5        S US'   UR                  SS 5      b  [        R                  " S5        S US'   UR                  [        R                  :X  a  U R                  R                  " S0 UD6nGOUR                  [        R                   [        R"                  [        R$                  4;   Ga=  ['        U5      nSU;   a  US	 [        R                  " S5        UR)                  S5      nU R+                  U5      nUR,                  S	   nU R/                  XR)                  S
S 5      S9n	U	R1                  UR2                  5      n	[4        R6                  " U	S S 2S UR8                  24   U4SS9nXqS'   SU;   aX  [4        R:                  " XR8                  5      R1                  US   R<                  5      n
[4        R6                  " XS   4SS9US'   U R                  R                  " S0 UD6$ [>        eU R@                  U R                  l        U RB                  U R                  l        W$ s  snnf ! , (       d  f       NL= f!   U R@                  U R                  l        U RB                  U R                  l        e = f)Nr  z4input_ids must be provided for Peft model generationr  r  r  r  encoder_outputsz[`encoder_outputs` should not be passed to `generate` when using prompt tuning. Ignoring it.r   r  r  r/   rk  r  r  ro  )"ry  r  r\   r  rY   r  r   rX   r  r   r   r   r   rW   r8   r>  r:  r=  r;  r   r  r9  r8  r  rA  r   r   r  rD  r  r  NotImplementedErrorr  r  )rb   r   rd   r!  r  r  r  r  r  r  r  s              rh   r  PeftModelForSeq2SeqLM.generate<	  s   --8<8Z8Z5?? 	F?	1144>v>/5||~i~tqJhJhAhdad~Fi"oo66@@G ?> f,$%[\\::nd3?MMo .2F>*::.5AMMr 04F+,((H,B,BB"oo66@@G ****%%44/ 
 &f-F(F2"#45 y !'

; 7I$($8$8$CM!.!4!4Q!7J"oojjYceiNjokG%jj)<)<=G$)IIwq:ZK<Z<Z:Z7Z/[]j.kqr$sM.;?+'6105

:GeGe0f0i0i"#34;;1- 4999>S\lUm=ntu3v/0??33=f==-- =A<i<iDOO9MM OOJ Ny j ?>d	<@<i<iDOO9MM OOJ sC   #L< 'L+;L%L%L+9H-L< 'L< %L++
L95L< <9M5r  c                  U R                   nU R                  " U0 UD6nUR                  [        R                  :X  a  XS'   U$ UR                  [        R
                  :X  a}  UR                  SS 5      nUR                  SS /5      nUS L =(       d    [        U[        5      =(       a    US   S:H  nU(       a'  US   R                  S   n	U R                  U	5      n
XS'   U$ )Nr  r  rv  r   r  )ry  r  rW   r8   r  r>  r   rr   r   r8  r  )rb   r  r  r   rd   r  r  rv  is_prefill_stager  r  s              rh   r  3PeftModelForSeq2SeqLM.prepare_inputs_for_generation	  s    --DDdUfU  HMM1'/$   ""h&<&<<*../@$GO)--.>GN !D( U6SN1<MQR<R	   )*=>DDQG
&*ooj&A#2E./ro   )r  r  r  r  NNNNNNNNNNN)r  rY  )r   r   r`  ra  rb  rU   rd  r  r  rf  rg  rh  s   @rh   r  r    s|    %P T]
$
3=
MP
	
 
 #"!}~EN MQ  ro   r  c                     ^  \ rS rSrSr S       S	U 4S jjjrS
SU 4S jjjr        SS jr       SS jrSr	U =r
$ )PeftModelForTokenClassificationi	  a  
Peft model for token classification tasks.

Args:
    model ([`~transformers.PreTrainedModel`]): Base transformer model.
    peft_config ([`PeftConfig`]): Peft config.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.

**Attributes**:
    - **config** ([`~transformers.PretrainedConfig`]) -- The configuration object of the base model.
    - **cls_layer_name** (`str`) -- The name of the classification layer.

Example:

    ```py
    >>> from transformers import AutoModelForSequenceClassification
    >>> from peft import PeftModelForTokenClassification, get_peft_config

    >>> config = {
    ...     "peft_type": "PREFIX_TUNING",
    ...     "task_type": "TOKEN_CLS",
    ...     "inference_mode": False,
    ...     "num_virtual_tokens": 20,
    ...     "token_dim": 768,
    ...     "num_transformer_submodules": 1,
    ...     "num_attention_heads": 12,
    ...     "num_layers": 12,
    ...     "encoder_hidden_size": 768,
    ...     "prefix_projection": False,
    ...     "postprocess_past_key_value_function": None,
    ... }

    >>> peft_config = get_peft_config(config)
    >>> model = AutoModelForTokenClassification.from_pretrained("bert-base-cased")
    >>> peft_model = PeftModelForTokenClassification(model, peft_config)
    >>> peft_model.print_trainable_parameters()
    trainable params: 370178 || all params: 108680450 || trainable%: 0.3406113979101117
    ```
c           	       >^ [         TU ]  " XU40 UD6  SS/n[        US5      (       a3  UR                  c  US S  Ul        OUR                  R	                  U5        U R
                  R                  5        H3  u  mn[        U4S jU R                   5       5      (       d  M,  TU l          O   [        U U[        USS 5      UR                  S9  g )Nrl  rm  r  c              3  ,   >#    U  H	  oT;   v   M     g 7frk   ro  rp  s     rh   r   ;PeftModelForTokenClassification.__init__.<locals>.<genexpr>	       O:N;$&:Nrs  rt  rT   rU   r^   r  r  r\   r/  r   rv  r=   r_   r   rw  s	          @rh   rU   (PeftModelForTokenClassification.__init__	  s     	\DVD#/"9; 122**2.Ea.H+++223JK557GD!O$:N:NOOO&*# 8 	 .?F&55		
ro   c                   > [        US5      (       a7  SS/nUR                  c  USS Ul        OUR                  R                  U5        [        TU ]  XUS9$ r{  r|  r}  s        rh   r]   +PeftModelForTokenClassification.add_adapter	  r  ro   c	                F   U R                   n
Ub  UOU R                  R                  nU
R                  (       d  U R                  " S0 U	D6   U	R                  5        VVs0 s H  u  pXR                  ;  d  M  X_M     n	nnU
R                  [        R                  :X  a  XS'   U R                  " SUUUUUUUS.U	D6sS S S 5        $ [        X5      nUbO  [        R                  " XR                  5      R                  UR                   5      n[        R"                  " X4SS9nU	R%                  SS 5      b  [&        R(                  " S5        S U	S'   U	R+                  UUUUUS.5        U
R                  [        R,                  :X  a  U R.                  " SSU0U	D6$ U	R%                  S	S 5      bv  [        R"                  " [        R0                  " XR                  5      R                  U R2                  R4                  R                   5      U	S	   4SS9R7                  5       U	S	'   Uc  U R3                  U5      nU R9                  XS
9nUR                  UR:                  5      n[        R"                  " X4SS9nU R                  " SSU0U	D6$ s  snnf ! , (       d  f       GN= fr  )ry  rR   r  rY   r  r   rX   rW   r8   r  r\   r:   r   r  rD  rA  r  r  r   r   r   rB  r>  r  r  r9  rc  rE  r  r   r  s                   rh   rd  'PeftModelForTokenClassification.forward	  sl    --%0%<k$++B]B]--00:6:+1<<>e>41QFdFd=d$!$>e((HMM9)1:& 	'#1"/!&7)= +	 		 ;: %Y>
%$)JJz;Y;Y$Z$]$]^l^s^s$t!"YY(='NTUVN::nd+7MMqr%)F>""0 %6(<*	
   H$:$::..MMfMMzz*D1=+099J0N0NORRSWSgSgSnSnSuSuv/0 , $& '( $ $ 4 4Y ?oooOGjj!4!45G!IIw&>AFM??II&IIa f ;:r  c           
     H   [        X5      n	U R                  U	5      n
[        [        R                  " U R
                  R                  5      R                  R                  5       5      nUR                  UUUUUUU
S.5        SU;   a  U R
                  " S
SU0UD6$ U R
                  R                  U R                  5      n[        [        R                  " UR                  5      R                  R                  5       5      nSU;  a  [        S5      eU" S
0 UD6nUS   nS[        U R
                  R                  5       5       VVs/ s H  u  nnUPM
     snn;   a  U R
                  R                  U5      nU R
                  R                  U R                  5      " U5      nS nUb<  [!        5       nU" UR#                  SU R$                  5      UR#                  S5      5      nU(       d  U4USS  -   nUb  U4U-   $ U$ ['        UUUR(                  UR*                  S	9$ s  snnf )Nr  r  r  r  r   r  r_  r   r  ro  )r:   r  rs   r  r  r\   rd  r0  r   rB  r5  r2  r   r/  r  rv  r   r|  r  r#   r  r  )rb   r  r  r  r  r  r  r  r   r  r  r  r2  r  sequence_outputr   r   r  r  r  rY  s                        rh   r  6PeftModelForTokenClassification._prefix_tuning_forwardB
  s    %Y>
//*5'++DOO,C,CDOOTTVW
&"0!.%6(<*#2
	
 
*??;&;F;;(,(E(EdFdFd(e%g//0I0Q0QR]]bbdeJ 
2 !opp/9&9G%ajOdoo6T6T6V1WX1WgdAT1WXX"&//"9"9/"J__2243F3FGXFD!+-B @&++b/R WQR[0-1-=&(I6I(%33"--	  Ys   Hr  )Nr   r  r\  r]  r  r  r  rh  s   @rh   r  r  	  s    *Z [d
$
3=
TW
	
 
2c cB !AJJ !4 4ro   r  c                     ^  \ rS rSrSr S       S	U 4S jjjrS
SU 4S jjjr           SS jr        SS jrSr	U =r
$ )PeftModelForQuestionAnsweringiy
  a>  
Peft model for extractive question answering.

Args:
    model ([`~transformers.PreTrainedModel`]): Base transformer model.
    peft_config ([`PeftConfig`]): Peft config.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.

**Attributes**:
    - **config** ([`~transformers.PretrainedConfig`]) -- The configuration object of the base model.
    - **cls_layer_name** (`str`) -- The name of the classification layer.

Example:

    ```py
    >>> from transformers import AutoModelForQuestionAnswering
    >>> from peft import PeftModelForQuestionAnswering, get_peft_config

    >>> config = {
    ...     "peft_type": "LORA",
    ...     "task_type": "QUESTION_ANS",
    ...     "inference_mode": False,
    ...     "r": 16,
    ...     "target_modules": ["query", "value"],
    ...     "lora_alpha": 32,
    ...     "lora_dropout": 0.05,
    ...     "fan_in_fan_out": False,
    ...     "bias": "none",
    ... }

    >>> peft_config = get_peft_config(config)
    >>> model = AutoModelForQuestionAnswering.from_pretrained("bert-base-cased")
    >>> peft_model = PeftModelForQuestionAnswering(model, peft_config)
    >>> peft_model.print_trainable_parameters()
    trainable params: 592900 || all params: 108312580 || trainable%: 0.5473971721475013
    ```
c           	       >^ [         TU ]  " XU40 UD6  S/n[        US5      (       a3  UR                  c  US S  Ul        OUR                  R	                  U5        U R
                  R                  5        H3  u  mn[        U4S jU R                   5       5      (       d  M,  TU l          O   [        U U[        USS 5      UR                  S9  g )N
qa_outputsr  c              3  ,   >#    U  H	  oT;   v   M     g 7frk   ro  rp  s     rh   r   9PeftModelForQuestionAnswering.__init__.<locals>.<genexpr>
  r  rs  rt  r  )	rb   rc   rd   rO   r   qa_module_namesr   r   rg   s	          @rh   rU   &PeftModelForQuestionAnswering.__init__
  s     	\DVD'.; 122**2.=a.@+++22?C557GD!O$:N:NOOO&*# 8 	 .?F&55		
ro   c                   > [        US5      (       a6  S/nUR                  c  USS Ul        OUR                  R                  U5        [        TU ]  XUS9$ )r  r  r  NrK   r|  )rb   rO   rd   rL   r  rg   s        rh   r]   )PeftModelForQuestionAnswering.add_adapter
  s]    , ; 122+nO**2.=a.@+++22?Cw"<Pa"bbro   c                R   U R                   nU
b  U
OU R                  R                  n
UR                  (       d  UR                  [
        R                  :X  a  XS'   U R                  " S0 UD6   UR                  5        VVs0 s H  u  pXR                  ;  d  M  X_M     nnnU R                  " SUUUUUUU	U
S.UD6sS S S 5        $ [        X5      nUbQ  [        R                  " UUR                  5      R                  UR                   5      n[        R"                  " UU4SS9nUR%                  SS 5      b  [&        R(                  " S5        S US'   UR+                  UUUUU	U
S.5        UR                  [
        R,                  :X  a  U R.                  " SSU0UD6$ UR%                  S	S 5      bw  [        R"                  " [        R0                  " UUR                  5      R                  U R2                  R4                  R                   5      US	   4SS9R7                  5       US	'   Uc  U R3                  U5      nU R9                  US
9nUR                  UR:                  5      n[        R"                  " UU4SS9nU R                  " SSU0UD6$ s  snnf ! , (       d  f       GN= f)Nr  )r  r  r  start_positionsend_positionsr  r  r  r/   rk  r  r  )r  r   r!  r  r  r  r  r  r  r  ro  )ry  rR   r  rY   rW   r8   r  r  r   rX   r\   r:   r   r  rD  rA  r  r  r   r   r   rB  r>  r  r  r9  rc  rE  r  r   )rb   r  r  r  r  r  r   r!  r  r  r  r  r   rd   r!  r  r  r  r  s                      rh   rd  %PeftModelForQuestionAnswering.forward
  sz    --%0%<k$++B]B]--$$5%-z"00:6:+1<<>e>41QFdFd=d$!$>e 
'#1"/$3"/&7)= +
 
 ;: %Y>
%$)JJz;;Y;Y$Z$]$]^l^s^s$t!"YY(=~'NTUVN::nd+7MMqr%)F>""0#2!.%6(<*		
   H$:$::..MMfMMzz*D1=+099J0N0NORRSWSgSgSnSnSuSuv/0 , $& '( $ $ 4 4Y ?ooo<Gjj!4!45G!IIw&>AFM??II&IIa f ;:s$   -JJJ JJ
J&c	           
        [        X5      n
U R                  U
5      n[        [        R                  " U R
                  R                  5      R                  R                  5       5      nU	R                  UUUUUUUS.5        SU;   a  U R
                  " SXES.U	D6$ U R
                  R                  U R                  5      n[        [        R                  " UR                  5      R                  R                  5       5      nSU;  a  [        S5      eU" S0 U	D6nUS   nS[        U R
                  R                  5       5       VVs/ s H  u  nnUPM
     snn;   a  U R
                  R                  U5      nU R
                  R                  U R                  5      " U5      nUR!                  SSS	9u  nnUR#                  S5      R%                  5       nUR#                  S5      R%                  5       nS nUb  Ub  ['        UR)                  5       5      S:  a  UR#                  S5      n['        UR)                  5       5      S:  a  UR#                  S5      nUR)                  S5      nUR+                  SU5      nUR+                  SU5      n[-        US
9nU" UU5      nU" UU5      nUU-   S-  nU(       d  UU4USS  -   nUb  U4U-   $ U$ [/        UUUUR0                  UR2                  S9$ s  snnf )Nr  r  )r   r!  r  r   r  r/   r_  rk  )ignore_indexr   )r  start_logits
end_logitsr  r  ro  )r:   r  rs   r  r  r\   rd  r0  r   rB  r5  r2  r   r/  r  rv  r  r  
contiguousr   r  clampr   r!   r  r  )rb   r  r  r  r   r!  r  r  r  r   r  r  r  r2  r  r  r   r   r  r%  r&  
total_lossignored_indexr  
start_lossend_lossrY  s                              rh   r  4PeftModelForQuestionAnswering._prefix_tuning_forward%  s    %Y>
//*5'++DOO,C,CDOOTTVW
&"0!.%6(<*#2
	
 
*??j?jcijj(,(E(EdFdFd(e%g//0I0Q0QR]]bbdeJ 
2 !opp/9&9G%ajOdoo6T6T6V1WX1WgdAT1WXX"&//"9"9/"J__2243F3FGXF'-||A2|'>$L*'//3>>@L#++B/::<JJ*}/H++-.2&5&=&=b&AO}))+,q0$1$9$9"$=M , 1 1! 4"1"7"7="I - 3 3A} E+G%lOD
#J>(83q8
&
3gabkA3=3I.UvU/)%%33"-- 9 Ys   K,r  r  r  r\  r]  r  r  r  rh  s   @rh   r  r  y
  s    (V T]
$
3=
MP
	
 
2c cB !GJV !E Ero   r  c                  L   ^  \ rS rSrSrSSU 4S jjjr       SS jrSrU =r$ )	PeftModelForFeatureExtractionim  a  
Peft model for extracting features/embeddings from transformer models

Args:
    model ([`~transformers.PreTrainedModel`]): Base transformer model.
    peft_config ([`PeftConfig`]): Peft config.
    adapter_name (`str`,  *optional*): The name of the adapter, defaults to `"default"`.
    autocast_adapter_dtype (`bool`, *optional*):
        Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter weights
        using float16 and bfloat16 to float32, as this is typically required for stable training, and only affect
        select PEFT tuners.

**Attributes**:
    - **config** ([`~transformers.PretrainedConfig`]) -- The configuration object of the base model.

Example:

    ```py
    >>> from transformers import AutoModel
    >>> from peft import PeftModelForFeatureExtraction, get_peft_config

    >>> config = {
    ...     "peft_type": "LORA",
    ...     "task_type": "FEATURE_EXTRACTION",
    ...     "inference_mode": False,
    ...     "r": 16,
    ...     "target_modules": ["query", "value"],
    ...     "lora_alpha": 32,
    ...     "lora_dropout": 0.05,
    ...     "fan_in_fan_out": False,
    ...     "bias": "none",
    ... }
    >>> peft_config = get_peft_config(config)
    >>> model = AutoModel.from_pretrained("bert-base-cased")
    >>> peft_model = PeftModelForFeatureExtraction(model, peft_config)
    >>> peft_model.print_trainable_parameters()
    ```
c                *   > [         TU ]  " XU40 UD6  g rk   )rT   rU   r  s        rh   rU   &PeftModelForFeatureExtraction.__init__  s    \DVDro   c                ~   U R                   n	U	R                  (       d  U	R                  [        R                  :X  a  XxS'   U R
                  " S0 UD6   UR                  5        V
Vs0 s H  u  pXR                  ;  d  M  X_M     nn
nU R                  " SUUUUUUS.UD6sS S S 5        $ [        X5      nUbO  [        R                  " XR                  5      R                  UR                  5      n[        R                  " X4SS9nUR!                  SS 5      b  ["        R$                  " S5        S US'   UR!                  SS 5      b  ["        R$                  " S5        S US'   UR'                  UUUUS	.5        U	R                  [        R(                  :X  a(  U R+                  U5      US
'   U R                  " SSU0UD6$ Uc  U R-                  U5      nU R+                  US9nUR                  UR.                  5      n[        R                  " X4SS9nU R                  " SSU0UD6$ s  snn
f ! , (       d  f       GN= f)Nr  )r  r  r  r  r  r  r/   rk  r  r  r  r  )r  r  r  r  r  r  r  r  ro  )ry  rY   rW   r8   r  r  r   rX   r\   r:   r   r  rD  rA  r  r  r   r   r   rB  r>  r  r9  r   )rb   r  r  r  r  r  r  r  r   rd   r!  r  r  r  r  s                  rh   rd  %PeftModelForFeatureExtraction.forward  s    ----$$5%-z"00:6:+1<<>e>41QFdFd=d$!$>e '#1"/&7)= +  ;: %Y>
%$)JJz;Y;Y$Z$]$]^l^s^s$t!"YY(='NTUVN::nd+7MMqr%)F>"::&-9MMtu'+F#$"0%6(<*		
   H$:$::(,
(CF$%??AYA&AA$ $ 4 4Y ?ooo<Gjj!4!45G!IIw&>AFM??II&IIU f ;:s$   H-&H'?H'H-'H--
H<ro  r  )rc   rV  rd   r1   rO   rt   r  )	r   r   r`  ra  rb  rU   rd  rf  rg  rh  s   @rh   r/  r/  m  s8    %NE E
 !;J ;Jro   r/  c                  f    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S	'   S
\S'   S\S'   S\S'   Srg)TunerLayerStatusi  rt   r   module_typerG  r  rT  rq   merged_adapters&dict[str, bool | Literal['irregular']]r1  available_adaptersdict[str, list[str]]devicesro  Nr   r   r`  ra  __annotations__rf  ro  ro   rh   r5  r5    s0    
IM99!!!!ro   r5  c                   [        U [        5      (       a-  U R                  n[        U[        5      (       d  [	        S5      eOU n/ nUR                  5        GH|  u  p4[        U[        [        45      (       d  M#  [        U[        5      (       a  M:  [        R                  " [        5      nUR                   H  n[        XF5      n[        U[        R                  R                   5      (       aO  UR#                  5        H9  u  pU	R%                  5        H   n
XX   R'                  U
R(                  5        M"     M;     M  [        U[        R                  R*                  5      (       a8  UR#                  5        H"  u  pXX   R'                  U
R(                  5        M$     M  M     SS jnUR#                  5        VVs0 s H  u  pX" U5      _M     nnn[        R                  " [        5      nUR                  UR,                  -    GH  n[        XF5      n[        U[        R                  R                   5      (       a`  UR#                  5        HJ  u  pX   R/                  U	R%                  5        V
s/ s H  oR0                  R2                  PM     sn
5        ML     M  [        U[        R                  R*                  5      (       d  UR4                  R6                  S:X  d  M  UR#                  5        H,  u  pX   R'                  U
R0                  R2                  5        M.     GM      UR#                  5        VVs0 s H  u  pU[9        [;        U5      5      _M     nnn[=        U[?        U5      RA                  S5      S   URB                  (       + URD                  URF                  U[9        URI                  5       5      US9nUR'                  U5        GM     U(       d  [K        S5      eU$ s  snnf s  sn
f s  snnf )	a  Get the status of each adapter layer in the model.

This function returns a list of `TunerLayerStatus` dataclass instances, each of which contains the following
attributes:

- `name` (`str`):
   The name of the adapter layer, e.g. `model.encoder.block.0.layer.0.SelfAttention.q`.
- `module_type` (`str`):
   The type of the adapter layer, e.g. `lora.Linear`.
- `enabled` (`bool`):
   Whether the adapter layer is enabled.
- `active_adapters` (`list[str]`):
   The names of the active adapters, if any, e.g. `["default"]`.
- `merged_adapters` (`list[str]`):
   The names of the merged adapters, if any, e.g. `["default"]`.
- requires_grad : dict[str, bool | Literal["irregular"]]
   The requires_grad status of the parameters for each adapter module. Ideally, it should be either `True` or
   `False`. If the requires_grad status is not consistent across all parameters, the value will be set to
   `"irregular"`.
- `available_adapters` (`list[str]`):
   The names of the available adapters, e.g. `["default"]`.
- `devices` (`dict[str, list[str]]`):
   The devices where the parameters of the given adapter are stored, e.g. `["cuda"]`.

Args:
    model ([Union[`~PeftModel`, `~transformers.PreTrainedModel`, `nn.Module`]]):
        The model to get the adapter layer status from.

Returns:
    list[`peft.peft_model.TunerLayerStatus`]:
        A list of dataclasses, each containing the status of the corresponding adapter layer.

zjget_layer_status() got an invalid PeftModel instance; prefix tuning and adaption prompt are not supported.c                H    [        U 5      (       a  g[        U 5      (       d  gg)NTFr  )allr   valss    rh   check_irrgular(get_layer_status.<locals>.check_irrgular&  s    4yyt99ro   
BufferDict(r   )r   r6  r  rq   r7  r1  r9  r;  zNo adapter layers found in the model, please ensure that it's a PEFT model or that you have PEFT adapters injected in the model.)rB  z
list[bool]rQ  bool | Literal['irregular'])&rr   rF   r\   r'   r  r
  r(   r)   r,   r   r   rs   adapter_layer_namesr_   r   r,  r-  r   r0  r   r1  ParameterDictother_param_namesr  r  r   rg   r   rB  r	  r5  repr	partitiondisable_adaptersrq   r7  _get_available_adaptersr   )rc   r\   layer_statusr   r  mapping_requires_grad_listadapter_module_nameadapter_moduler   	submodulerG  rC  rB  r1  
devices_ddr   r;  statuss                     rh   r  r    sM   D %##%%
*i00  1 
+-L"002&>3K"LMMf455  =H<S<STX<Y"#)#=#=$VAN.%((*=*=>>&4&:&:&<NC!*!5!5!727>>u?R?RS "8 '= NEHH,B,BCC"0"6"6"8JC.3::5;N;NO #9  $>	 E_DdDdDfgDfysnT22Dfg ,,T2
#)#=#=@X@X#X$VAN.%((*=*=>>&4&:&:&<NCO**9K_K_Ka+bKa%LL,=,=Ka+bc '=NEHH,B,BCC((11\A"0"6"6"8JCO**5<<+<+<= #9 $Y :D9I9I9KL9KXS3s3x((9KL!V..s3A6///"22"22'%f&D&D&FG	
 	F#o 3r %
 	

 C h ,c Ms   :O,0O29!O7c                      \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S	'   S\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   Srg)r_  iQ  rt   base_model_typeadapter_model_typezdict[str, str]
peft_typesrZ  r  total_paramsnum_adapter_layersrG  r  z list[str] | Literal['irregular']rq   r7  r8  r1  rT  r9  r:  r;  ro  Nr<  ro  ro   rh   r_  r_  Q  sJ    ((555599!!!!ro   r_  c                   [        U [        5      (       a  [        U R                  [        5      (       d  [	        S5      eU R                  5       R                  R                  nU R                  5       u  p#U R                  nUR                  R                  5        VVs0 s H-  u  pVU[        UR                  5      R                  S5      S   _M/     nnnUR                  R                  nOh[        U [        5      (       a4  U R                  R                  n[        R                  U 5      u  p#U n0 nSnOSn[        R                  U 5      u  p#U n0 nSn[        U 5      n	[!        U	5      n
U	 Vs1 s H  oR"                  iM     nn[!        U5      S:X  a  UR%                  5       nOSn['        [)        5       R*                  " S U	 5       6 5      nU	 Vs1 s H  n[-        UR.                  5      iM     nnU(       d  / nO+[!        U5      S:X  a  [1        UR%                  5       5      nOSn[)        5       nU	 H  nUR3                  UR4                  5        M      ['        U5      nU	 H<  n[)        UR6                  5      [)        UR4                  5      -
  nUU-  (       d  M:  Sn  O   [8        R:                  " [0        5      nU	 H;  nUR<                  R                  5        H  u  nnUU   R?                  U5        M     M=     SS	 jnUR                  5        VVs0 s H  u  nnUU" U5      _M     nnn[8        R:                  " [0        5      nU	 H;  nUR@                  R                  5        H  u  nnUU   RC                  U5        M     M=     UR                  5        VVs0 s H  u  nnU['        [)        U5      5      _M     nnn[E        UUUUUU
UUUUUUS
9nU$ s  snnf s  snf s  snf s  snnf s  snnf )a  Get the status of tuners of the model.

This function returns a `TunerModelStatus` dataclass instance, which contains the following attributes:

- `base_model_type` (`str`):
   The type of the base model, e.g. `T5Model`.
- `adapter_model_type` (`str`):
   The type of the adapter model, e.g. `LoraModel`.
- `peft_types` (`dict[str, str]`):
   The mapping of adapter name to adapter type, e.g. `{"default": "LORA"}`.
- `trainable_params` (`int`):
   The number of trainable parameters in the model.
- `total_params` (`int`):
   The total number of parameters in the model.
- `num_adapter_layers` (`int`):
   The number of adapter layers in the model.
- `enabled` (`bool`, `Literal["irregular"]`):
   Whether all adapter layers are enabled. If some are enabled and some are not, this will be `"irregular"`. This
   means that your model is in an inconsistent state and might not work as expected.
- `active_adapters` (`list[str]`, `Literal["irregular"]`):
   The names of the active adapters. If the active adapters are not consistent across all layers, this will be
   `"irregular"`, which means that your model is in an inconsistent state and might not work as expected.
- `merged_adapters` (`list[str]`, `Literal["irregular"]`):
   The names of the merged adapters. If the merged adapters are not consistent across all layers, this will be
   `"irregular"`, which means that your model is in an inconsistent state and might not work as expected.
- `requires_grad` (`dict[str, bool | Literal["irregular"]]`):
   Whether for the given adapter, all adapter layers have `requires_grad` set to `True` or `False`. If there is a
   mix, this will be set to `"irregular"`, which means that your model is in an inconsistent state and might not
   work as expected.
- `available_adapters` (`list[str]`):
   The names of the available adapters, e.g. `["default"]`.
- `devices` (`dict[str, list[str]]`):
   The devices where the parameters of the given adapter are stored, e.g. `["cuda"]`.

Args:
    model ([Union[`~PeftModel`, `~transformers.PreTrainedModel`, `nn.Module`]]):
        The model to get the adapter layer status from.

Returns:
    `peft.peft_model.TunerModelStatus`:
        A dataclass containing the status of the model.

zjget_model_status() got an invalid PeftModel instance; prefix tuning and adaption prompt are not supported.r   r_  rR  otherr/   r  c              3  8   #    U  H  oR                   v   M     g 7frk   )r9  )r   rU  s     rh   r   #get_model_status.<locals>.<genexpr>  s     8namW]9R9Rams   c                d    [        S U  5       5      (       a  g[        S U  5       5      (       a  gg)Nc              3  (   #    U  H  oS L v   M
     g7f)TNro  r   r   s     rh   r   ;get_model_status.<locals>.check_irrgular.<locals>.<genexpr>  s     +dsd{d   Tc              3  (   #    U  H  oS L v   M
     g7f)FNro  rb  s     rh   r   rc    s     ,te|trd  Fr  )r@  rA  s    rh   rC  (get_model_status.<locals>.check_irrgular  s-    +d+++,t,,,ro   )rW  rX  rY  r  rZ  r[  r  rq   r7  r1  r9  r;  )rB  z!list[bool | Literal['irregular']]rQ  rG  )#rr   rF   r\   r'   r  r?  rg   r   r  rd   r   rt   rW   rL  r    r  r   r  r  rB  r	  rA  r  rq   rs   rB  r7  r9  r   r   r1  r   r;  r  r_  )rc   rW  r  rZ  r\   r   rR   rY  rX  rO  r[  rU  enabled_setr  r9  all_active_adaptersrq   
merged_allr7  unmergedrequires_grad_allr   rC  rB  r1  rT  r;  adapter_model_statuss                               rh   r  r  a  s   X %##%**I66   ..0::CC).)J)J)L&%%
WaWmWmWsWsWuvWuc3v//0::3?CCWu
v'11::	E?	+	+//22)2)N)Nu)U&

#!)2)N)Nu)U&

##E*L\*;GH<nn<KH
;1//#$*35;;8nam8n+o$p ^j0j]iSYv7M7M1N]i0j	 	!Q	&26689% 5J&001  9?z8JOv001C8N8N4OOj  )O  GRF]F]^bFc,,224HCc"))#. 5 
 AR@W@W@YZ@Y93S...@YMZ((.J,,.HCsO""3' /  6@5E5E5GH5GcsF3s8$$5GGH+'-)!-''#-  y w$ I 1kT [ Is   4O/OO$O)"O/c                ~    U S:X  a!  Sn[         R                  " U[        S9  [        $ [	        S[
        < SU < 35      e)NPEFT_TYPE_TO_MODEL_MAPPINGzPEFT_TYPE_TO_MODEL_MAPPING is deprecated, please use `from peft import PEFT_TYPE_TO_TUNER_MAPPING` instead. The deprecated variable will be removed in 2026.)categoryzmodule z has no attribute )r   r   DeprecationWarningr4   ru   r   )r   r   s     rh   r  r    sE    ++? 	 	c$67))
78,.@I
JJro   )rc   rV  rQ  r^  )rc   rV  rQ  r_  )q
__future__r   r   r   r  r   r   collections.abcr   
contextlibr   r   r   dataclassesr   typingr	   r
   r   r   packaging.versionr  r   r  
accelerater   r   accelerate.hooksr   r   r   accelerate.utilsr   r   huggingface_hubr   r   r   r   safetensorsr   safetensors.torchr   r   torch.nnr   r   r   r   r   r   r    transformers.modeling_outputsr!   r"   r#   transformers.utilsr$   peft.tuners.lora.variantsr%   r&   peft.tuners.tuners_utilsr'   r(   
peft.utilsr)   peft.utils.constantsr*   peft.utils.integrationsr+   peft.utils.otherr,   r-   r.   r   r0   rR   r1   r  r2   r3   r4   utilsr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   r,  ModulerF   rj  rD  r  r  r  r/  r5  r  r_  r  r  ro  ro   rh   <module>r     sV   #    	  $ 2  ! 0 0    < ^ ^ F S S ! 9 A A R R w w - c > / 3 6 l l   i i    (r rj/q qhX9 Xv
KI K\\i \~qI qhfJI fJR " " "l^ " " "Q hKro   