ó
    >:jv)  ã                  óp   • S SK Jr  S SK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\
5      5       rg)	é    )ÚannotationsN)Ú	dataclassÚfield)ÚOptionalÚUnion)Ú
PeftConfig)ÚPeftTypec                  óš  ^ • \ 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&'   \" 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$ )0ÚPveraConfigé   a•  
This is the configuration class to store the configuration of a [`PveraModel`].

Paper: https://www.arxiv.org/abs/2512.07703.

Args:
    r (`int`, *optional*, defaults to `256`):
        PVeRA parameter dimension ("rank"). Choose higher values than LoRA ranks here, since PVeRA shares
        parameters across layers and therefore uses far fewer parameters than LoRA.
    target_modules (`Union[List[str], str]`):
        The names of the modules to apply PVeRA to. Only linear layers are supported. When passing a string, a
        regex match will be performed. If this is specified as 'all-linear', then all linear/Conv1D modules are
        chosen. If this is not specified, modules will bechosen according to the model architecture. If the
        architecture is not known, an error will be raised.
    projection_prng_key (`int`):
        PVeRA PRNG init key. Used for initialising pvera_A and pvera_B for new models or when loading a checkpoint
        that did not include these projections. Defaults to `0`.
    save_projection (`bool`):
        Whether to save the pvera_A / pvera_B projections in the state dict alongside per layer lambda_b / lambda_d
        weights. This will increase the size of the checkpoint, but guarantee that we can reload the checkpoint on
        all system configurations. Defaults to `True`.
    pvera_dropout (`float`):
        The dropout probability for PVeRA layers.
    d_initial (`float`, *optional*, defaults to `0.1`):
        Initial value for `pvera_lambda_d` vector used when initializing the PVeRA parameters. Small values (<=0.1)
        are recommended.
    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`.
    bias (`str`):
        Bias type for PVeRA. Can be 'none', 'all' or 'pvera_only'. If 'all' or 'pvera_only', the corresponding
        biases will be updated during training. Be aware that this means that, even when disabling the adapters,
        the model will not produce the same output as the base model would have without adaptation.
    modules_to_save (`List[str]`):
        List of modules apart from PVeRA layers to be set as trainable and saved in the final checkpoint.
    init_weights (`bool`):
        Whether to initialize the weights of the PVeRA layers with their default initialization. Don't change this
        setting, except if you know exactly what you're doing.
    layers_to_transform (`Union[List[int],int]`):
        The layer indexes to transform, if this argument is specified, it will apply the PVeRA transformations on
        the layer indexes that are specified in this list. If a single integer is passed, it will apply the PVeRA
        transformations on the layer at this index.
    layers_pattern (`Optional[Union[List[str], str]]`):
        The layer pattern name, used only if `layers_to_transform` is different from `None`. This should target the
        `nn.ModuleList` of the model, which is often called `'layers'` or `'h'`.
    sample_at_inference (`bool` | `dict`, defaults to `False`):
        Whether to sample from the learned PVeRA distribution at inference. If false, the learned mean is used. The
        default is False (indicating false for all adapters). If True is provided, then the value will be true for
        all adapters. If a dict is provided, then a specific value can be specified per adapter (with False by
        default for non-specified adapters). For example
        `sample_at_inference={'encoder.layer.0.attention.attention.query': True}` will only sample at inference for
        one specific adapter.
é   Úhelpz­PVeRA parameter dimension ('rank'). Choose higher values than LoRA ranks here, since PVeRA shares parameters across layers and therefore uses far fewer parameters than LoRA.)ÚdefaultÚmetadataÚintÚrNaf  The names of the modules to apply PVeRA to. Only linear layers are supported. When passing a string, a regex match will be performed. If this is specified as 'all-linear', then all linear/Conv1D modules are chosen. If this is not specified, modules will bechosen according to the model architecture. If the architecture is not known, an error will be raised.zOptional[Union[list[str], str]]Útarget_modulesr   z£PVeRA PRNG init key. Used for initialising pvera_A and pvera_B for new models or when loading a checkpoint that did not include these projections. Defaults to `0`.Úprojection_prng_keyTa  Whether to save the pvera_A / pvera_B projections in the state dict alongside per layer lambda_b / lambda_d weights. This will increase the size of the checkpoint, but guarantee that we can reload the checkpoint on all system configurations. Defaults to `True`.ÚboolÚsave_projectiong        z)The dropout probability for PVeRA layers.ÚfloatÚpvera_dropoutgš™™™™™¹?z+Initial value for d vector. Default is 0.1.Ú	d_initialFzÃ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`.Úfan_in_fan_outÚnonea+  Bias type for PVeRA. Can be 'none', 'all' or 'pvera_only'. If 'all' or 'pvera_only', the corresponding biases will be updated during training. Be aware that this means that, even when disabling the adapters, the model will not produce the same output as the base model would have without adaptation.ÚstrÚbiaszaList of modules apart from PVeRA layers to be set as trainable and saved in the final checkpoint.zOptional[list[str]]Úmodules_to_savez¡Whether to initialize the weights of the PVeRA layers with their default initialization. Don't change this setting, except if you know exactly what you're doing.Úinit_weightszÿThe layer indexes to transform, if this argument is specified, it will apply the PVeRA transformations on the layer indexes that are specified in this list. If a single integer is passed, it will apply the PVeRA transformations on 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 from `None`. This should target the `nn.ModuleList` of the model, which is often called `'layers'` or `'h'`.Úlayers_patternað  Whether to sample from the learned PVeRA distribution at inference. If false, the learned mean is used. The default is False (indicating false for all adapters). If True is provided, then the value will be true for all adapters. If a dict is provided, then a specific value can be specified per adapter (with False by default for non-specified adapters). For example `sample_at_inference={'encoder.layer.0.attention.attention.query': True}` will only sample at inference for one specific adapter.Úsample_at_inferencec                ó€  >• [         TU ]  5         [        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                  (       d  [        R                  " S5        g g )NzRWhen `layers_pattern` is specified, `layers_to_transform` must also be specified. a   Specified to not save pvera_A and pvera_B within the state dictionary, instead they will be restored using the PRNG key store in `config.projection_prng_key`. Consider setting `config.save_projection` to `True` to guarantee restoring the checkpoint correctly on all system configurations.)ÚsuperÚ__post_init__r	   ÚPVERAÚ	peft_typeÚ
isinstancer   ÚlistÚsetr!   r    Ú
ValueErrorr   ÚwarningsÚwarn)ÚselfÚ	__class__s    €ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/pvera/config.pyr%   ÚPveraConfig.__post_init__¿   s‰   ø€ Ü‰ÑÔÜ!Ÿ™ˆŒä(2°4×3FÑ3FÌ×(MÑ(MŒC�×#Ñ#Ô$ÐSW×SfÑSfð 	Ôð ×× t×'?×'?ÜÐqÓrÐrØ×#×#Ü�MŠMðjõð $ó    )r'   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú__annotations__r   r   r   r   r   r   r   r   r   r    r!   r"   r%   Ú__static_attributes__Ú__classcell__)r/   s   @r0   r   r      sÐ  ø‡ ñ4ñl Øàð^ð
ñ€A€só ñ 7<ØàðFð
ñ
7€NÐ3ó 
ñ  %ØàðKð
ñ Ð˜ó ñ "ØàðAð
ñ	€O�Tó 	ñ !¨¸Ð@kÐ7lÑm€M�5ÓmÙ S°FÐ<iÐ3jÑk€IˆuÓkÙ Øàðoð
ñ€N�Dó ñ Øàðnð
ñ	€Dˆ#ó 	ñ ,1ØàØsð
ñ,€OÐ(ó ñ ØàðIð
ñ€L�$ó ñ <AØàð>ð
ñ	<ÐÐ8ó 	ñ 7<Øàð[ð
ñ7€NÐ3ó ñ !&Øàð(ð	
ñ!Ð˜ó ÷ó r2   r   )Ú
__future__r   r,   Údataclassesr   r   Útypingr   r   Úpeft.configr   Ú
peft.utilsr	   r   © r2   r0   Ú<module>rA      s7   ðõ #ã ß (ß "å "Ý ð ôt�*ó tó ñtr2   