o
    8wÖi  ã                   @  s\   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 eG dd„ deƒƒZdS )	é    )ÚannotationsN)Ú	dataclass)ÚOptional)Ú
PeftConfig)ÚPeftTypec                      s¾   e Zd ZU dZdZded< dZded< dZded	< d
Zded< d
Z	ded< dZ
ded< dZded< dZded< d
Zded< dZded< dZded< dZded< dZded< ‡ fdd„Z‡  ZS )ÚXLoraConfiga²  
    This is the configuration class to store the configuration of a `XLoraModel`. When the config is reloaded, the
    paths of the `adapters` field is disregarded in favor of the saved adapters. As such, only the keys matter during
    loading.

    Args:
        hidden_size (`int`):
            Hidden size of the base model.
        adapters (`dict`):
            Mapping of adapter names to the LoRA adapter id, as per PeftModel.load_adapter. *They will be automatically
            loaded*, to use as LoRA experts. When using from_pretrained, pass the new adapters dict as a keyword
            argument.
        enable_softmax (`bool`, *optional*, defaults to `True`):
            Enable softmax application for the X-LoRA classifier.
        enable_softmax_topk (`bool`, *optional*, defaults to `False`):
            Enable softmax application for the top-k LoRA adapters. Mutually exclusive to `enable_softmax` and must
            only be set if `top_k_lora` is.
        softmax_temperature (`float`, *optional*, defaults to 1.0):
            Softmax temperature, lower yields sharper predictions
        layerwise_scalings (`bool`, *optional*, defaults to `False`):
            If True, generate scalings for each LoRA adapter (each layer). If this is False, then scalings will be
            broadcasted, the same, to each layer.
        top_k_lora (`int`, *optional*, defaults to None):
            Sparsely select the top_k LoRA experts instead of the default dense method.
        xlora_depth (`int`, *optional*, defaults to 1):
            Depth of the X-LoRA classifier.
        xlora_size (`int`, *optional*, defaults to 2048):
            Hidden size of the X-LoRA classifier, irrelevant if `xlora_depth=1`.
        xlora_dropout_p (`float`, *optional*, defaults to 0.2):
            Dropout probability of the X-LoRA classifier, irrelevant if `xlora_depth=1`.
        use_trainable_adapters (`bool`, *optional*, defaults to False):
            Make the adapters trainable.
        scaling_pass_value (`float`, *optional*, defaults to 0):
            Scaling pass value.
        global_scaling_weight (`float`, *optional*, defaults to 1):
            Weight to multiply output of each LoRA adapter by.
    NÚintÚhidden_sizezdict[str, str]ÚadaptersTÚboolÚenable_softmaxFÚenable_softmax_topkÚlayerwise_scalingsé   Úxlora_depthi   Ú
xlora_sizegš™™™™™É?ÚfloatÚxlora_dropout_pÚuse_trainable_adaptersg      ð?Úsoftmax_temperaturezOptional[int]Ú
top_k_lorag        Úscaling_pass_valueÚglobal_scaling_weightc                   s    t ƒ  ¡  tj| _| jd u rt d¡ d| _| jd u r#t d¡ i | _| j	r0| j
d u r0t d¡ | j	r;| jr;t d¡ | j
d urL| j
dk rNt d¡ d S d S d S )NzqNo value was provided for `hidden_size`. This will be set to 4096 by default, please ensure that this is correct.i   zhNo value was provided for for `adapters`. This will be set to empty, please ensure that this is correct.z5`enable_softmax_topk` enabled `top_k_lora` is not setzc`enable_softmax_topk` and `enable_softmax` are both enabled. This will result in worse performance.r   z&`top_k_lora` value must be at least 1.)ÚsuperÚ__post_init__r   ÚXLORAÚ	peft_typer	   ÚwarningsÚwarnr
   r   r   r   )Úself©Ú	__class__© úU/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/peft/tuners/xlora/config.pyr   N   s*   

ÿ
ÿ
ÿÿzXLoraConfig.__post_init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   Ú__annotations__r
   r   r   r   r   r   r   r   r   r   r   r   r   Ú__classcell__r"   r"   r    r#   r      s    
 &r   )Ú
__future__r   r   Údataclassesr   Útypingr   Úpeft.configr   Úpeft.utils.peft_typesr   r   r"   r"   r"   r#   Ú<module>   s   