ó
    >:jU  ã                  ór   • S SK Jr  S SK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KJrJr   " S	 S
\5      rg)é    )ÚannotationsN)Ú	BaseTunerÚBaseTunerLayer)Ú4TRANSFORMERS_MODELS_TO_DELORA_TARGET_MODULES_MAPPING)Úget_pattern_keyé   )ÚDeloraConfig)ÚDeloraLayerÚDeloraLinearc                  ó^   ^ • \ rS rSr% SrSrS\S'   \r\	r
S
U 4S jjrS r\S 5       rS	rU =r$ )ÚDeloraModelé   am  
Creates DeLoRA model from a pretrained transformers model.

The method is described in detail in [DeLoRA: Decoupled Low-rank
Adaptation](https://huggingface.co/papers/2503.18225).

Args:
    model ([`torch.nn.Module`]): The model to be adapted.
    config ([`DeloraConfig`]): The configuration of the DeLoRA model.
    adapter_name (`str`): The name of the adapter, defaults to `"default"`.

Returns:
    `torch.nn.Module`: The DeLoRA model.

**Attributes**:
    - **model** ([`~transformers.PreTrainedModel`]) -- The model to be adapted.
    - **peft_config** ([`DeloraConfig`]): The configuration of the DeLoRA model.
Údelora_ÚstrÚprefixc                ó$   >• [         TU ]  U5        g)z´
A helper method to check the config when a new adapter is being added.

Raise a ValueError if there is something wrong with the config or if it conflicts with existing adapters.

N)ÚsuperÚ_check_new_adapter_config)ÚselfÚconfigÚ	__class__s     €ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/delora/model.pyr   Ú%DeloraModel._check_new_adapter_config4   s   ø€ ô 	‰Ñ)¨&Õ1ó    c                óX  • Uc  [        S5      e[        UR                  R                  5       U5      n[        UR                  R                  5       U5      n	UR                  R                  X�R                  5      n
UR                  R                  X‘R                  5      nU
UUR                  UR                  S.n[        U[        5      (       a  UR                  " U40 UD6  g U R                  " XU40 UD6nX R                  :w  a  UR                  S5        U R!                  XTXÓ5        g )NzCurrent Key shouldn't be `None`)ÚrÚdelora_lambdaÚmodule_dropoutÚinit_weightsF)Ú
ValueErrorr   Úrank_patternÚkeysÚlambda_patternÚgetr   r   r   r   Ú
isinstancer   Úupdate_layerÚ_create_new_moduleÚactive_adapterÚrequires_grad_Ú_replace_module)r   Údelora_configÚadapter_nameÚtargetÚtarget_nameÚparentÚcurrent_keyÚoptional_kwargsÚr_keyÚ
lambda_keyr   r   ÚkwargsÚ
new_modules                 r   Ú_create_and_replaceÚDeloraModel._create_and_replace=   s	  € ð ÑÜÐ>Ó?Ð?ô   × :Ñ :× ?Ñ ?Ó AÀ;ÓOˆÜ$ ]×%AÑ%A×%FÑ%FÓ%HÈ+ÓVˆ
Ø×&Ñ&×*Ñ*¨5·/±/ÓBˆØ%×4Ñ4×8Ñ8¸×E`ÑE`Óaˆð Ø*Ø+×:Ñ:Ø)×6Ñ6ñ	
ˆô �fœl×+Ñ+Ø×Ò Ñ7°Ó7à×0Ò0°ÈfÑ_ÐX^Ñ_ˆJØ×2Ñ2Ó2à×)Ñ)¨%Ô0Ø× Ñ  °jÕIr   c                óÀ   • [        U[        5      (       a  UR                  5       nOUn[        U[        R                  R
                  5      (       a  [        X!40 UD6nW$ )N)r%   r   Úget_base_layerÚtorchÚnnÚLinearr   )r+   r,   r-   r4   Útarget_base_layerr5   s         r   r'   ÚDeloraModel._create_new_module`   sO   € ä�fœn×-Ñ-Ø &× 5Ñ 5Ó 7Ñà &ÐäÐ'¬¯©¯©×9Ñ9Ü% fÑE¸fÑEˆJàÐr   © )r   r	   ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__annotations__r
   Útuner_layer_clsr   Útarget_module_mappingr   r6   Ústaticmethodr'   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s?   ø‡ ñð& €FˆCÓØ!€OØPÐ÷2ò!JðF ñ	ó ö	r   r   )Ú
__future__r   r:   Úpeft.tuners.tuners_utilsr   r   Ú
peft.utilsr   Úpeft.utils.otherr   r   r	   Úlayerr
   r   r   r?   r   r   Ú<module>rR      s.   ðõ #ã ç >õõ -å  ß ,ôN�)õ Nr   