ó
    >:jz  ã                   óN   • S SK r S SKJrJr  S SKJr  SSKJrJr   " S S\5      r	g)é    N)Ú	BaseTunerÚBaseTunerLayer)Ú2TRANSFORMERS_MODELS_TO_MISS_TARGET_MODULES_MAPPINGé   )Ú	MissLayerÚ
MissLinearc                   óF   • \ rS rSr% SrSr\\S'   \r	\
rS r\S 5       rSrg)	Ú	MissModelé   aw  
Creates Householder reflection adaptation (MiSS) model from a pretrained model. The method is described in
https://huggingface.co/papers/2409.15371

Args:
    model (`torch.nn.Module`): The model to which the adapter tuner layers will be attached.
    config ([`MissConfig`]): The configuration of the MiSS 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 MiSS model.

Example:
    ```py
    >>> from diffusers import StableDiffusionPipeline
    >>> from peft import MissModel, MissConfig

    >>> config_te = MissConfig(
    ...     r=8,
    ...     target_modules=["k_proj", "q_proj", "v_proj", "out_proj", "fc1", "fc2"],
    ...     init_weights=True,
    ... )
    >>> config_unet = MissConfig(
    ...     r=8,
    ...     target_modules=[
    ...         "proj_in",
    ...         "proj_out",
    ...         "to_k",
    ...         "to_q",
    ...         "to_v",
    ...         "to_out.0",
    ...         "ff.net.0.proj",
    ...         "ff.net.2",
    ...     ],
    ...     init_weights=True,
    ... )

    >>> model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> model.text_encoder = MissModel(model.text_encoder, config_te, "default")
    >>> model.unet = MissModel(model.unet, config_unet, "default")
    ```

**Attributes**:
    - **model** ([`~torch.nn.Module`]) -- The model to be adapted.
    - **peft_config** ([`MissConfig`]): The configuration of the MiSS model.
Úmiss_Úprefixc                 óö  • Uc  [        S5      e[        US5      =(       a    UR                  S Ln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                  S9  g )NzCurrent Key shouldn't be `None`Úbias)ÚrÚmini_rÚmiss_dropoutÚinit_weightsF)r   r   r   r   )Ú
ValueErrorÚhasattrr   r   r   r   r   Ú
isinstancer   Ú_create_new_moduleÚactive_adaptersÚrequires_grad_Ú_replace_moduleÚupdate_layer)ÚselfÚmiss_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/miss/model.pyÚ_create_and_replaceÚMissModel._create_and_replaceN   së   € ð ÑÜÐ>Ó?Ð?ä�v˜vÓ&×B¨6¯;©;¸dÐ+Bˆà—‘Ø!×(Ñ(Ø'×4Ñ4Ø'×4Ñ4ñ	
ˆð ˆv‰ô ˜&¤)×,Ñ,Ø×0Ò0°ÈFÑ]ÐV\Ñ]ˆJØ×#7Ñ#7Ó7à×)Ñ)¨%Ô0Ø× Ñ  °jÕIà×ÑØØ—-‘-Ø(×5Ñ5Ø(×5Ñ5Ø"×)Ñ)ð  ò ó    c                 óÞ   • [        U[        5      (       a  UR                  5       nOUn[        U[        R                  R
                  5      (       a  [        X!40 UD6nU$ [        SU S35      e)NzTarget module zB is not supported. Currently, only `torch.nn.Linear` is supported.)r   r   Úget_base_layerÚtorchÚnnÚLinearr   r   )r   r   r   r$   Útarget_base_layerr%   s         r&   r   ÚMissModel._create_new_modulet   sm   € ä�fœn×-Ñ-Ø &× 5Ñ 5Ó 7Ñà &ÐäÐ'¬¯©¯©×9Ñ9Ü# FÑC¸FÑCˆJð Ðô	 Ø   Ð(jÐkóð r)   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚstrÚ__annotations__r   Útuner_layer_clsr   Útarget_module_mappingr'   Ústaticmethodr   Ú__static_attributes__r1   r)   r&   r
   r
      s9   ‡ ñ/ðb €FˆCÓØ€OØNÐò$ðL ñó ór)   r
   )
r,   Úpeft.tuners.tuners_utilsr   r   Ú
peft.utilsr   Úlayerr   r   r
   r1   r)   r&   Ú<module>r@      s!   ðó  ç >Ý Iç (ôj�	õ jr)   