ó
    >:jÕ  ã                   óZ   • S SK r S SKrS SKJrJr  S SKJr  SSKJrJ	r	J
r
   " S S\5      rg)é    N)Ú	BaseTunerÚBaseTunerLayer)Ú2TRANSFORMERS_MODELS_TO_BOFT_TARGET_MODULES_MAPPINGé   )Ú	BOFTLayerÚConv2dÚLinearc                   óF   • \ rS rSr% SrSr\\S'   \r	\
rS r\S 5       rSrg)	Ú	BOFTModelé   aJ  
Creates BOFT and OFT model from a pretrained transformers model. Paper: https://huggingface.co/papers/2311.06243
https://huggingface.co/papers/2306.07280

Args:
    model ([`transformers.PreTrainedModel`]): The model to be adapted.
    config ([`BOFTConfig`]): The configuration of the BOFT model.
    adapter_name (`str`): The name of the adapter, defaults to `"default"`.
    low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
        Create empty adapter weights on meta device. Useful to speed up the loading process.

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

Example::

    >>> import transformers >>> from transformers import AutoModelForSeq2SeqLM, BOFTConfig >>> from peft import
    BOFTConfig, get_peft_model

    >>> config = BOFTConfig( ... boft_block_size=8, ... boft_n_butterfly_factor=1, ... target_modules=["query",
    "value", "key", "output.dense", "mlp.fc1", "mlp.fc2"], ... boft_dropout=0.1, ... bias="boft_only", ...
    modules_to_save=["classifier"], ... )

    >>> model = transformers.Dinov2ForImageClassification.from_pretrained( ... "facebook/dinov2-large", ...
    num_labels=100, ... ) >>> boft_model = get_peft_model(model, config)

**Attributes**:
    - **model** ([`transformers.PreTrainedModel`]) -- The model to be adapted.
    - **peft_config** ([`BOFTConfig`]): The configuration of the BOFT model.
Úboft_Úprefixc           	      ó8  • Uc  [        S5      e[        US5      =(       a    UR                  S LnUR                  UR                  UR
                  UR                  UR                  UR                  S.n	X‰S'   [        U[        5      (       dG  U R                  " XU40 U	D6n
X R                  ;  a  U
R                  S5        U R                  XTX£5        g UR                  UUR                  UR                  UR
                  UR                  UR                  S9  g )NzCurrent Key shouldn't be `None`Úbias)Úboft_block_sizeÚboft_block_numÚboft_n_butterfly_factorÚboft_dropoutÚfan_in_fan_outÚinit_weightsF)r   r   r   r   r   )Ú
ValueErrorÚhasattrr   r   r   r   r   r   r   Ú
isinstancer   Ú_create_new_moduleÚactive_adaptersÚrequires_grad_Ú_replace_moduleÚupdate_layer)ÚselfÚboft_configÚadapter_nameÚtargetÚtarget_nameÚparentÚcurrent_keyÚoptional_kwargsr   ÚkwargsÚ
new_modules              ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/boft/model.pyÚ_create_and_replaceÚBOFTModel._create_and_replaceC   s
  € ð ÑÜÐ>Ó?Ð?ä�v˜vÓ&×B¨6¯;©;¸dÐ+Bˆà*×:Ñ:Ø)×8Ñ8Ø'2×'JÑ'JØ'×4Ñ4Ø)×8Ñ8Ø'×4Ñ4ñ
ˆð ˆv‰ô ˜&¤)×,Ñ,Ø×0Ò0°ÈFÑ]ÐV\Ñ]ˆJØ×#7Ñ#7Ó7à×)Ñ)¨%Ô0Ø× Ñ  °jÕIà×ÑØØ +× ;Ñ ;Ø*×9Ñ9Ø(3×(KÑ(KØ(×5Ñ5Ø(×5Ñ5ð  ò ó    c                 ó¤  • [        U[        5      (       a  UR                  5       nOUn[        U[        R                  R
                  5      (       a:  US   (       a"  [        R                  " S5        S=US'   U l        [        X!40 UD6nU$ [        U[        R                  R                  5      (       a  [        X!40 UD6nU$ [        SU S35      e)Nr   zjfan_in_fan_out is set to True but the target module is `torch.nn.Linear`. Setting fan_in_fan_out to False.FzTarget module zY is not supported. Currently, only `torch.nn.Linear` and `torch.nn.Conv2d` are supported.)r   r   Úget_base_layerÚtorchÚnnr	   ÚwarningsÚwarnr   r   r   )r    r!   r"   r'   Útarget_base_layerr(   s         r)   r   ÚBOFTModel._create_new_modulel   sÓ   € ä�fœn×-Ñ-Ø &× 5Ñ 5Ó 7Ñà &ÐäÐ'¬¯©¯©×9Ñ9ØÐ&×'Ü—’ð7ôð INÐM�Ð'Ñ(¨;Ô+EÜ Ñ?¸Ñ?ˆJð Ðô Ð)¬5¯8©8¯?©?×;Ñ;Ü Ñ?¸Ñ?ˆJð Ðô Ø   ð )Yð Yóð r,   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚstrÚ__annotations__r   Útuner_layer_clsr   Útarget_module_mappingr*   Ústaticmethodr   Ú__static_attributes__r5   r,   r)   r   r      s8   ‡ ñð> €FˆCÓØ€OØNÐò'ðR ñó ór,   r   )r1   r/   Úpeft.tuners.tuners_utilsr   r   Ú
peft.utilsr   Úlayerr   r   r	   r   r5   r,   r)   Ú<module>rD      s,   ðó$ ã ÷õ Jç ,Ñ ,ôd�	õ dr,   