
    bi$                    h    d dl m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 e G d de	             Zy)	    )annotations)	dataclassfield)OptionalUnion)
PeftConfig)PeftTypec                       e Zd ZU dZ edddi      Zded<    edddi      Zded	<    eddd
i      Zded<    edddi      Z	ded<    edddi      Z
ded<    edddi      Zded<    fdZ xZS )	IA3Configu  
    This is the configuration class to store the configuration of a [`IA3Model`].

    Args:
        target_modules (`Optional[Union[List[str], str]]`):
            The names of the modules to apply the adapter to. If this is specified, only the modules with the specified
            names will be replaced. When passing a string, a regex match will be performed. When passing a list of
            strings, either an exact match will be performed or it is checked if the name of the module ends with any
            of the passed strings. If this is specified as 'all-linear', then all linear/Conv1D modules are chosen,
            excluding the output layer. If this is not specified, modules will be chosen according to the model
            architecture. If the architecture is not known, an error will be raised -- in this case, you should specify
            the target modules manually.
        exclude_modules (`Optional[Union[List[str], str]]`):
            The names of the modules to not apply the adapter. When passing a string, a regex match will be performed.
            When passing a list of strings, either an exact match will be performed or it is checked if the name of the
            module ends with any of the passed strings.
        feedforward_modules (`Optional[Union[List[str], str]]`):
            The names of the modules to be treated as feedforward modules, as in the original paper. These modules will
            have (IA)³ vectors multiplied to the input, instead of the output. `feedforward_modules` must be a name or
            a subset of names present in `target_modules`.
        fan_in_fan_out (`bool`):
            Set this to True if the layer to replace stores weight like (fan_in, fan_out). For example, gpt-2 uses
            `Conv1D` which stores weights like (fan_in, fan_out) and hence this should be set to `True`.
        modules_to_save (`Optional[List[str]]`):
            List of modules apart from (IA)³ layers to be set as trainable and saved in the final checkpoint.
        init_ia3_weights (`bool`):
            Whether to initialize the vectors in the (IA)³ layers, defaults to `True`. Setting this to `False` is
            discouraged.
    Nhelpu  List of module names or regex expression of the module names to replace with (IA)³.For example, ['q', 'v'] or '.*decoder.*(SelfAttention|EncDecAttention).*(q|v)$'.This can also be a wildcard 'all-linear' which matches all linear/Conv1D layers except the output layer.If not specified, modules will be chosen according to the model architecture, If the architecture is not known, an error will be raised -- in this case, you should specify the target modules manually.)defaultmetadatazOptional[Union[list[str], str]]target_modulesuT   List of module names or regex expression of the module names to exclude from (IA)³.exclude_moduleszmList of module names or a regex expression of module names which are feedforwardFor example, ['output.dense']feedforward_modulesFzMSet this to True if the layer to replace stores weight like (fan_in, fan_out)boolfan_in_fan_outa  List of modules apart from (IA)^3 layers to be set as trainable and saved in the final checkpoint. For example, in Sequence Classification or Token Classification tasks, the final layer `classifier/score` are randomly initialized and as such need to be trainable and saved.zOptional[list[str]]modules_to_saveTz7Whether to initialize the vectors in the (IA)^3 layers.init_ia3_weightsc                   t         |           t        j                  | _        t        | j                  t              rt        | j                        n| j                  | _        t        | j                  t              rt        | j                        n| j                  | _	        t        | j                  t              rt        | j                        n| j                  | _
        t        | j                  t              rLt        | j                  t              r1| j                  j                  | j                        st        d      y y y )Nz<`feedforward_modules` should be a subset of `target_modules`)super__post_init__r	   IA3	peft_type
isinstancer   listsetr   r   issubset
ValueError)self	__class__s    Q/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/peft/tuners/ia3/config.pyr   zIA3Config.__post_init__`   s    !(243F3F(MC##$SWSfSf 	 *4D4H4H$)OC$$%UYUiUi 	 .88P8PRV-WC(()]a]u]u 	 
 d..4DDWDWY\9]++44T5H5HI !_`` J :^4    )__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r   r   r   __classcell__)r!   s   @r"   r   r      s    < 7<v
7N3  8=pq8O4  <A ,
<8  !ijND  ,1 v
,O(  #STd 
a ar#   r   N)
__future__r   dataclassesr   r   typingr   r   peft.configr   
peft.utilsr	   r    r#   r"   <module>r0      s7    # ( " "  Wa
 Wa War#   