o
    8wiq                     @   s\   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 deZdS )    N)	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t t	j
| _| jdu r6dg| _t| j| _| jdu rJdd | jD | _| jdu rXd	d | jD | _t| jt| j  krtt| j  krt| jksytd
 td
dS )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   c                 S      g | ]}d qS r    .0_r   r   S/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/peft/tuners/cpt/config.py
<listcomp>b       z+CPTConfig.__post_init__.<locals>.<listcomp>c                 S   r   r   r   r   r   r   r   r   e   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)selfr   r   r   __post_init__H   s0   


0zCPTConfig.__post_init__)r-   
__module____qualname____doc__r   r   r   listint__annotations__r   r   r   r   r   floatr   r   r   strr!   r4   r   r   r   r   r	      s8   
  r	   )r*   dataclassesr   r   typingr   r   peft.configr   
peft.utilsr   r   r	   r   r   r   r   <module>   s   