o
    Ni                     @   sT   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 deZdS )    )	dataclassfield)LiteralOptional)PromptLearningConfig)PeftTypeTaskTypec                   @   s  e Zd ZU dZedddidZeee  e	d< edddidZ
eee  e	d< eddd	idZeee  e	d
< edddidZeed  e	d< edddidZee e	d< edddidZee e	d< edddidZee e	d< edddidZee e	d< dZdd ZdS )	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                 C   s   d| _ d| _d| _d| _d| _tj| _| jt	j
kr't| jj dt	j
j d| jdu r0dg| _t| j| _| jdu rDdd | jD | _| jdu rRd	d | jD | _t| jt| j  krnt| j  krn| jksstd
 td
dS )zh
        Post-initialization hook to set additional attributes after the config is initialized.
        TN   z only supports task_type = .r   c                 S      g | ]}d qS r    .0_r   r   J/home/ubuntu/.local/lib/python3.10/site-packages/peft/tuners/cpt/config.py
<listcomp>[       z+CPTConfig.__post_init__.<locals>.<listcomp>c                 S   r   r   r   r   r   r   r   r    ^   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
ValueError	__class____name__valuer   lennum_virtual_tokensr   r   )selfr   r   r   __post_init__G   s(   


0zCPTConfig.__post_init__)r-   
__module____qualname____doc__r   r   r   listint__annotations__r   r   r   r   r   floatr   r   r   strr"   r2   r   r   r   r   r	      s8   
  r	   N)dataclassesr   r   typingr   r   peft.configr   
peft.utilsr   r   r	   r   r   r   r   <module>   s   