
    biq                     h    d dl Z d dlmZmZ d dlmZmZ d dlmZ d dl	m
Z
mZ e G d de             Zy)    N)	dataclassfield)LiteralOptional)PromptLearningConfig)PeftTypeTaskTypec                   t   e Zd ZU dZ edddi      Zeee      e	d<    edddi      Z
eee      e	d<    eddd	i      Zeee      e	d
<    edddi      Zeed      e	d<    edddi      Zee   e	d<    edddi      Zee   e	d<    edddi      Zee   e	d<    edddi      Zee   e	d<   dZd Zy)	CPTConfigaa  
    CPT Configuration class extending PeftConfig for Context-aware Prompt Tuning (CPT).

    This class introduces additional parameters required for CPT, such as:
    - Token type masks
    - Prompt tuning initialization
    - Loss weighting
    - Projection settings

    For more details, see the paper: https://huggingface.co/papers/2410.17222
    Nhelpz)Tensor of token IDs used for CPT prompts.)defaultmetadatacpt_token_idsz"Tensor mask applied to CPT tokens.cpt_maskz+Mask indicating the type of each CPT token.cpt_tokens_type_masknonez)Type of weighted loss: 'none' or 'decay'.)r   decayopt_weighted_loss_typeg      ?z/Factor for exponential decay in loss weighting.opt_loss_decay_factorg?z#Epsilon value for input projection.opt_projection_epsilonz$Epsilon value for format projection.opt_projection_format_epsilonz`The tokenizer to use for prompt tuning initialization. Only used if prompt_tuning_init is `TEXT`tokenizer_name_or_pathTc                 b   d| _         d| _        d| _        d| _        d| _        t
        j                  | _        | j                  t        j                  k7  rat        j                  | j                  j                   dt        j                  j                   dt                t        j                  | _        | j"                  dg| _        t%        | j"                        | _        | j(                  | j"                  D cg c]  }d c}| _        | j*                  | j"                  D cg c]  }d c}| _        t%        | j"                        t%        | j(                        cxk(  r2t%        | j*                        cxk(  r| j&                  k(  st-        d       t-        d      yc c}w c c}w )zh
        Post-initialization hook to set additional attributes after the config is initialized.
        TN   z only supports task_type = zP, setting it automatically. This will raise an error starting from PEFT v0.18.0.r   zKcpt_token_ids, cpt_mask and cpt_tokens_type_mask must have the same length.)is_prompt_learning
num_layers	token_dimnum_attention_headsnum_transformer_submodulesr   CPT	peft_type	task_typer	   	CAUSAL_LMwarningswarn	__class____name__valueFutureWarningr   lennum_virtual_tokensr   r   
ValueError)self_s     Q/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/peft/tuners/cpt/config.py__post_init__zCPTConfig.__post_init__H   so   
 #'#' *+'!>>X///MM>>**++FxGYGYG_G_F` aa a
 &//DN%"#D"%d&8&8"9== (,(:(:;1Q;DM$$,484F4F(Gq(GD% ""#s4=='9vSAZAZ=[v_c_v_vvjkk wjkk w < )Hs   ?	F'*	F,)r'   
__module____qualname____doc__r   r   r   listint__annotations__r   r   r   r   r   floatr   r   r   strr   r0        r/   r   r      s?   
 */(ST*M8DI&  %*$&JnAo$pHhtCy!p05(UV1(49- 
 BG&*U!VBHW_%=>  .3v'XY.8E? 
 /4v'LM/HUO  6;v'MN6!8E? 
 -2v
-HSM  "lr:   r   )r$   dataclassesr   r   typingr   r   peft.configr   
peft.utilsr   r	   r   r9   r:   r/   <module>r?      s8     ( $ , ) Rl$ Rl Rlr:   