
    bi                    t    d dl mZ d dlZd dlmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZ e G d de             Zy)	    )annotationsN)	dataclassfield)LiteralOptionalUnion)
PeftConfig)PeftTypec                  8    e Zd ZU dZ edddd      Zded<    ed	d
dd      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<    ed	dd i      Zd!ed"<    fd#Z xZS )$
BoneConfiga  
    This is the configuration class to store the configuration of a [`BoneModel`].

    Args:
        r (`int`):
            The rank of Bone across different layers. It is best to set 'r' to an even number; otherwise, the default
            initialization method will not work.
        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 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 | Literal["bat"]):
            Different initializations correspond to different Bone variants. By default, setting True uses the Bone
            structure, while "bat" selects the Bat structure.
        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 (`str`):
            The layer pattern name, used only if `layers_to_transform` is different from `None`.
        modules_to_save (`List[str]`):
            List of modules apart from adapter layers to be set as trainable and saved in the final checkpoint.
    @   z)The rank of Bone across different layers.zdIt is best to set 'r' to an even number; otherwise, the default initialization method will not work.)helpnote)defaultmetadataintrNzRList of module names or regex expression of the module names to replace with Bone.zPFor example, ['q', 'v'] or '.*decoder.*(SelfAttention|EncDecAttention).*(q|v)$' )r   examplezOptional[Union[list[str], str]]target_modulesr   zRList of module names or regex expression of the module names to exclude from Bone.exclude_modulesTzWhether to initialize the weights of the Bone layers with their default initialization. Don't change this setting, except if you know exactly what you're doing.zbool | Literal['bat']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.zOptional[str]layers_patternnonez7Bias type for Bone. Can be 'none', 'all' or 'Bone_only'strbiasa  List of modules apart from Bone 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         |           t        j                  | _        t        | j                  t              rt        | j                        n| j                  | _        t        | j                  t              rt        | j                        n| j                  | _	        t        | j                  t              r| j                  t        d      t        | j                  t              r| j                  t        d      t        j                  d       y )NzD`layers_to_transform` cannot be used when `target_modules` is a str.z?`layers_pattern` cannot be used when `target_modules` is a str.zBone will be removed in v0.19.0 of PEFT, use `MissConfig` instead. If you already have a Bone checkpoint, you can use `/scripts/convert-bone-to-miss.py` to convert it into )super__post_init__r
   BONE	peft_type
isinstancer   listsetr   r   r   
ValueErrorr   warningswarn)self	__class__s    R/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/peft/tuners/bone/config.pyr    zBoneConfig.__post_init__m   s    !(243F3F(MC##$SWSfSf 	 *4D4H4H$)OC$$%UYUiUi 	 d))3/D4L4L4Xcdd d))3/D4G4G4S^__x	
    )__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r   r   r   r   r    __classcell__)r*   s   @r+   r   r      s"   @ ?z
As  7<hi
7N3  8=no8O4  +0N
+L'  <A  w
<8  %*  d
%NM  f8q/rsD#s+0 v
,O( 
 
r,   r   )
__future__r   r'   dataclassesr   r   typingr   r   r   peft.configr	   
peft.utilsr
   r    r,   r+   <module>r9      s:    #  ( + + "  g
 g
 g
r,   