ó
    >:j;#  ã                  ót   • S SK Jr  S SKJrJ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	)
é    )Úannotations)Ú	dataclassÚfield)ÚOptionalÚUnion)ÚACT2FN)Ú
PeftConfig)ÚPeftTypec                  óF  ^ • \ rS rSr% Sr\" SSS0S9rS\S'   \" S	SS
0S9rS\S'   \" SSS0S9r	S\S'   \" SSS0S9r
S\S'   \" SSS0S9rS\S'   \" SSS0S9rS\S'   \" SSS0S9rS\S'   \" SSS0S9rS\S'   \" SSS 0S9rS\S!'   \" S"SS#0S9rS$\S%'   U 4S& jrS'rU =r$ )(ÚPeanutConfigé   ae  
This is the configuration class to store the configuration of a [`PeanutModel`].

Args:
    r (`int`):
        PEANuT rank. This is the hidden dimension used by the adapters. Similar to LoRA rank, larger `r` increases
        adapter capacity and trainable parameters.
    depth (`int`):
        Number of hidden adapter layers per encoder/decoder side in PEANuT. The input projection `A` and output
        projection `B` are always present in addition to these hidden layers. Therefore, `depth` must be a
        non-negative integer.

        - `depth=0`: `A`, `B`.
        - `depth=1`: `A`, one encoder, one decoder, `B`.
        - `depth=2`: `A`, two encoders, two decoders, `B`.
        - `depth=3`: `A`, three encoders, three decoders, `B`, etc.
    act_fn (`str`):
        Non-linear activation applied in the PEANuT network. This corresponds to `non_linear` in the vanilla
        PyTorch implementation. Default is `"relu"`. Any activation key available in
        `transformers.activations.ACT2FN` is supported and may perform better on different tasks.
    scaling (`float`):
        A scalar multiplier applied to the PEANuT output before adding it to the frozen base layer output. The
        final adapter contribution is `scaling * (x @ delta_w)`.
    target_modules (`Union[List[str], str]`, *optional*):
        The names of the modules to apply PEANuT to. Can be a list of module name strings (e.g. `['q_proj',
        'v_proj']`) or a regex pattern.
    modules_to_save (`List[str]`, *optional*):
        List of modules apart from PEANuT layers to be set as trainable and saved in the final checkpoint.
    exclude_modules (`Union[List[str], str]`, *optional*):
        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.
    layers_to_transform (`Union[list[int], int]`, *optional*):
        The layer indexes to transform. If this argument is specified, PEFT will transform only the layer indexes
        that are specified in this list. If a single integer is passed, PEFT will transform only the layer at this
        index.
    layers_pattern (`Optional[Union[List[str], str]]`, *optional*):
        The layer pattern name, used only if `layers_to_transform` is not None and if the layer pattern is not in
        the common layers pattern.
    init_weights (`bool`):
        Whether to initialize PEANuT adapter weights using the default initialization scheme:

        - If `True`: all weights except `B` are initialized with Kaiming uniform, and `B` is initialized to zero.
        - If `False`: all weights (including `B`) are initialized with Kaiming uniform.

        Initializing `B` to zero makes the adapter start as an exact no-op.

Notes:
    PEANuT uses a weight-aware pathway, where the delta weight is conditioned on the base weight. The `A` adapter
    is applied over the base weight's output dimension, so `A` has shape `(out_dim -> r)` rather than the usual
    `(in_dim -> r)` used by LoRA-like methods.
é    ÚhelpzšPEANuT rank. This is the hidden dimension used by the adapter stack. Similar to LoRA rank, larger `r` increases adapter capacity and trainable parameters.)ÚdefaultÚmetadataÚintÚrr   zºNumber of hidden adapter layers per encoder/decoder side in PEANuT. The input projection `A` and output projection `B` are added automatically, so `depth` must be a non-negative integer.ÚdepthÚreluz¨Non-linear activation applied in the PEANuT pathway. This corresponds to `non_linear` in the vanilla implementation. Must be a key in `transformers.activations.ACT2FN`.ÚstrÚact_fng      ð?zŸA scalar multiplier applied to the PEANuT output before adding it to the frozen base layer output. The final adapter contribution is `scaling * (x @ delta_w)`.ÚfloatÚscalingNzõList of module names or regex expression of the module names to replace with PEANuT. For example, ['q', 'v'] or '.*decoder.*(SelfAttention|EncDecAttention).*(q|v)$'. If not specified, PEANuT will use architecture-specific default target modules.zOptional[Union[list[str], str]]Útarget_modulesa$  List of module names or regex expression of the module names to exclude from PEANuT. 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.Úexclude_moduleszbList of modules apart from PEANuT layers to be set as trainable and saved in the final checkpoint.zOptional[list[str]]Úmodules_to_savezàThe layer indexes to transform, if this argument is specified, PEFT will transform only the layers indexes that are specified inside this list. If a single integer is passed, PEFT will transform only the layer at this index.zOptional[Union[list[int], int]]Úlayers_to_transformzíThe layer pattern name, used only if `layers_to_transform` is different to None and if the layer pattern is not in the common layers pattern. This should target the `nn.ModuleList` of the model, which is often called `'layers'` or `'h'`.Úlayers_patternTa  Whether to initialize PEANuT adapter weights using the default initialization scheme: if `True`, all weights except `B` are initialized with Kaiming uniform and `B` is initialized to zero; if `False`, all weights including `B` are initialized with Kaiming uniform.ÚboolÚinit_weightsc           	     ó¾  >• [         TU ]  5         [        R                  U l        [        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                  (       a  U R                  (       d  [        S5      eU R                  S::  a  [        S5      eU R                  S:  a  [        S5      eU R                  [         ;  a8  [        SU R                   S[#        [         R$                  " 5       5       S35      eg )NzQWhen `layers_pattern` is specified, `layers_to_transform` must also be specified.r   z`r` must be a positive integer.z+`depth` can only be a non-negative integer.zUnsupported `act_fn`: z. Must be one of Ú.)ÚsuperÚ__post_init__r
   ÚPEANUTÚ	peft_typeÚ
isinstancer   ÚlistÚsetr   r   r   Ú
ValueErrorr   r   r   r   ÚsortedÚkeys)ÚselfÚ	__class__s    €ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/peanut/config.pyr$   ÚPeanutConfig.__post_init__°   s  ø€ Ü‰ÑÔÜ!Ÿ™ˆŒä(2°4×3FÑ3FÌ×(MÑ(MŒC�×#Ñ#Ô$ÐSW×SfÑSfð 	Ôô *4°D×4HÑ4HÌ$×)OÑ)OŒC�×$Ñ$Ô%ÐUY×UiÑUið 	Ôð ×× t×'?×'?ÜÐpÓqÐqØ�6‰6�Q‹;ÜÐ>Ó?Ð?Ø�:‰:˜‹>ÜÐJÓKÐKØ�;‰;œfÓ$ÜÐ5°d·k±k°]ÐBSÔTZÔ[a×[fÒ[fÓ[hÓTiÐSjÐjkÐlÓmÐmð %ó    )r   r&   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú__annotations__r   r   r   r   r   r   r   r   r    r$   Ú__static_attributes__Ú__classcell__)r.   s   @r/   r   r      s~  ø‡ ñ3ñj ØàðKð
ñ€A€só ñ Øàðlð
ñ€Eˆ3ó ñ Øàð^ð
ñ€FˆCó ñ ØàðOð
ñ€GˆUó ñ 7<Øàðbð
ñ	7€NÐ3ó 	ñ 8=Øàð2ð
ñ
8€OÐ4ó 
ñ ,1ØàØtð
ñ,€OÐ(ó ñ <AØàð+ð
ñ	<ÐÐ8ó 	ñ 7<Øàð=ð
ñ	7€NÐ3ó 	ñ Øàð[ð
ñ	€L�$ó 	÷nó nr1   r   N)Ú
__future__r   Údataclassesr   r   Útypingr   r   Útransformers.activationsr   Úpeft.configr	   Ú
peft.utilsr
   r   © r1   r/   Ú<module>rA      s:   ðõ #ç (ß "å +å "Ý ð ôfn�:ó fnó ñfnr1   