
    oi9                     `    S SK r S SKJrJr  S SKJr  S SKJr  S SKJ	r	  \ " S S\5      5       r
g)    N)	dataclassfield)Optional)
LoraConfig)PeftTypec                   R  ^  \ rS rSr% Sr\" SSS0S9r\\S'   \" SSS	0S9r	\\S
'   \" SSS0S9r
\\S'   \" SSS0S9r\\S'   \" SSS0S9r\\S'   \" SSS0S9r\\S'   \" SSS0S9r\\S'   \" SSS0S9r\\S'   \" SSS0S9r\\   \S'   \" SSS0S9r\\   \S'   U 4S jrS rU =r$ )!AdaLoraConfig   a  
This is the configuration class to store the configuration of a [`~peft.AdaLora`].

AdaLoRA has three phases defined by `tinit`, `tfinal` and `total_step`.

The initial phase can be understood as a step for pre-training the adapters so that when reducing their rank, there
is already some information encoded that can be reduced instead of random matrices. This phase is defined by
supplying `tinit`.

After the initial phase is over (`tinit` steps have passed) and the final phase has not begun, AdaLoRA reduces the
budget of how much rank each layer is allowed to have with each step. This is where the reduction of rank is
happening. This goes on until `total_step - tfinal` steps are reached.

The last phase, beginning once `total_step - tfinal` steps are reached, does not change the layer ranks anymore but
fine-tunes the reduced-rank layers that resulted from the previous phase.

A practical example: `tinit` is 10, `tfinal` is 20, `total_step` is 100. We spend 10 steps doing pre-training
without rank reduction because our budget is constant (init phase), then we spend 80 (100-20) steps in the
reduction phase where our budget decreases step-wise and, finally, 20 steps in the final fine-tuning stage without
reduction.

Args:
    target_r (`int`): The target average rank of incremental matrix.
    init_r (`int`): The initial rank for each incremental matrix.
    tinit (`int`): The steps of initial fine-tuning warmup.
    tfinal (`int`): The number of steps of final fine-tuning.
    deltaT (`int`): The time internval between two budget allocations.
    beta1 (`float`): The hyperparameter of EMA for sensitivity smoothing.
    beta2 (`float`): The hyperparameter of EMA for undertainty quantification.
    orth_reg_weight (`float`): The coefficient of orthogonal regularization.
    total_step (`int`): The total training steps that should be specified before training.
    rank_pattern (`list`): The allocated rank for each weight matrix by RankAllocator.
   helpzTarget Lora matrix dimension.)defaultmetadatatarget_r   zInitial Lora matrix dimension.init_rr   zThe steps of initial warmup.tinitzThe steps of final warmup.tfinal   z!Step interval of rank allocation.deltaTg333333?zHyperparameter of EMA.beta1beta2g      ?z*The orthogonal regularization coefficient.orth_reg_weightNzThe total training steps.
total_stepzThe saved rank pattern.rank_patternc                   > [         TU ]  5         [        R                  U l        U R
                  (       a  [        U R                   S35      eU R                  (       a  [        U R                   S35      e[        U R                  [        5      (       a  [        U R                  5      OU R                  U l	        [        U R                  [        5      (       a  [        U R                  5      OU R                  U l        [        U R                  [        5      (       a  U R                  b  [        S5      eU R                  (       a  U R                  (       d  [        S5      eU R                   S:w  a  ["        R$                  " S5        U R&                  b  U R&                  S::  a  [        S5      eU R(                  U R&                  U R*                  -
  :  a  [        S	5      eg )
Nz does not support DoRA.z does not support LOFTQ.zD`layers_to_transform` cannot be used when `target_modules` is a str.zRWhen `layers_pattern` is specified, `layers_to_transform` must also be specified. r   zwNote that `r` is not used in AdaLora and will be ignored.If you intended to set the initial rank, use `init_r` instead.r   zDAdaLoRA does not work when `total_step` is None, supply a value > 0.zsThe supplied schedule values don't allow for a budgeting phase. Decrease `tfinal`/`tinit` or increase `total_step`.)super__post_init__r   ADALORA	peft_typeuse_dora
ValueErrorloftq_config
isinstancetarget_moduleslistsetexclude_modulesstrlayers_to_transformlayers_patternrwarningswarnr   r   r   )self	__class__s    T/home/james-whalen/.local/lib/python3.13/site-packages/peft/tuners/adalora/config.pyr   AdaLoraConfig.__post_init__F   s~   !))==//FGHH//GHII )343F3F(M(MC##$SWSfSf 	 *4D4H4H$)O)OC$$%UYUiUi 	 d))3//D4L4L4Xcdd t'?'?qrr 66Q;MMQ
 ??"doo&:cdd::$//DKK78)  9    )r'   r   r$   )__name__
__module____qualname____firstlineno____doc__r   r   int__annotations__r   r   r   r   r   floatr   r   r   r   r   dictr   __static_attributes____classcell__)r/   s   @r0   r	   r	      s    D !v7V.WXHcXf6V-WXFCXqF4R+STE3TV5Q,RSFCSV5X,YZFCZ9Q0RSE5S9Q0RSE5S"3&Bn9opOUp %dfFa=b cJc#(Ib@c#dL(4.d& &r2   r	   )r,   dataclassesr   r   typingr   peft.tuners.lorar   
peft.utilsr   r	    r2   r0   <module>rC      s4     (  '  TJ T Tr2   