
    oik                    h    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\	5      5       rg)	    )annotations)	dataclassfield)OptionalUnion)LycorisConfig)PeftTypec                  b  ^  \ 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%'   U 4S& jrS'rU =r$ )(
LoHaConfig   a  
This is the configuration class to store the configuration of a [`LoHaModel`].

Args:
    r (`int`):
        LoHa rank.
    alpha (`int`):
        The alpha parameter for LoHa scaling.
    rank_dropout (`float`):
        The dropout probability for rank dimension during training.
    module_dropout (`float`):
        The dropout probability for disabling LoHa modules during training.
    use_effective_conv2d (`bool`):
        Use parameter effective decomposition for Conv2d (and Conv1d) with ksize > 1 ("Proposition 3" from FedPara
        paper).
    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.
    init_weights (`bool`):
        Whether to perform initialization of adapter weights. This defaults to `True`, passing `False` is
        discouraged.
    layers_to_transform (`Union[List[int], int]`):
        The layer indices to transform. If a list of ints is passed, it will apply the adapter to the layer indices
        that are specified in this list. If a single integer is passed, it will apply the 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'`.
    rank_pattern (`dict`):
        The mapping from layer names or regexp expression to ranks which are different from the default rank
        specified by `r`. For example, `{'^model.decoder.layers.0.encoder_attn.k_proj': 16}`.
    alpha_pattern (`dict`):
        The mapping from layer names or regexp expression to alphas which are different from the default alpha
        specified by `alpha`. For example, `{'^model.decoder.layers.0.encoder_attn.k_proj': 16}`.
    modules_to_save (`Optional[List[str]]`):
        List of modules apart from adapter layers to be set as trainable and saved in the final checkpoint.
   helpz	LoHa rank)defaultmetadataintrz
LoHa alphaalphag        z:The dropout probability for rank dimension during trainingfloatrank_dropoutzBThe dropout probability for disabling LoHa modules during trainingmodule_dropoutFzqUse parameter effective decomposition for Conv2d (and Conv1d) with ksize > 1 ("Proposition 3" from FedPara paper)booluse_effective_conv2dNa
  List of module names or regex expression of the module names to replace with LoHa.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.zOptional[Union[list[str], str]]target_moduleszRList of module names or regex expression of the module names to exclude from LoHa.exclude_modulesTzWhether to initialize the weights of the LoHa layers with their default initialization. Don't change this setting, except if you know exactly what you're doing.init_weightszThe layer indexes to transform, is 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_transformzThe 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_patterna  List of modules apart from LoHA 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_savec                  > [         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g g )NzRWhen `layers_pattern` is specified, `layers_to_transform` must also be specified. )super__post_init__r	   LOHA	peft_type
isinstancer   listsetr   r   r   
ValueError)self	__class__s    Q/home/james-whalen/.local/lib/python3.13/site-packages/peft/tuners/loha/config.pyr!   LoHaConfig.__post_init__   s    !(243F3F(M(MC##$SWSfSf 	 *4D4H4H$)O)OC$$%UYUiUi 	 t'?'?qrr (@    )r   r#   r   )__name__
__module____qualname____firstlineno____doc__r   r   __annotations__r   r   r   r   r   r   r   r   r   r   r!   __static_attributes____classcell__)r)   s   @r*   r   r      s{   -^ 1'<=As=qFL+ABE3Bv'cdL%  "v'klNE  "'7
"$  7< w
7N3  8=no8O4  N
L$  <A  w
<8  7< n
7N3  ,1 v
,O( s sr,   r   N)
__future__r   dataclassesr   r   typingr   r   peft.tuners.lycoris_utilsr   
peft.utilsr	   r    r,   r*   <module>r;      s7    # ( " 3  ws ws wsr,   