ó
    >:j–  ã                   óJ   • S SK r  " S S\ R                  R                  5      rg)é    Nc                   ót   ^ • \ rS rSrSrU 4S jrS\R                  4S jrS\R                  SS4S	 jr	S
r
U =r$ )ÚPrefixEncoderé   aÛ  
The `torch.nn` model to encode the prefix.

Args:
    config ([`PrefixTuningConfig`]): The configuration of the prefix encoder.

Example:

```py
>>> from peft import PrefixEncoder, PrefixTuningConfig

>>> config = PrefixTuningConfig(
...     peft_type="PREFIX_TUNING",
...     task_type="SEQ_2_SEQ_LM",
...     num_virtual_tokens=20,
...     token_dim=768,
...     num_transformer_submodules=1,
...     num_attention_heads=12,
...     num_layers=12,
...     encoder_hidden_size=768,
... )
>>> prefix_encoder = PrefixEncoder(config)
```

**Attributes**:
    - **embedding** (`torch.nn.Embedding`) -- The embedding layer of the prefix encoder.
    - **transform** (`torch.nn.Sequential`) -- The two-layer MLP to transform the prefix embeddings if
      `prefix_projection` is `True`.
    - **prefix_projection** (`bool`) -- Whether to project the prefix embeddings.

Input shape: (`batch_size`, `num_virtual_tokens`)

Output shape: (`batch_size`, `num_virtual_tokens`, `2*layers*hidden`)
c           	      óx  >• [         TU ]  5         UR                  U l        UR                  nUR                  nUR
                  nUR                  nUR                  nU R                  (       GaT  UR                  (       GdB  [        R                  R                  XR5      U l        [        R                  R                  [        R                  R                  X$5      [        R                  R                  5       [        R                  R                  XCS-  U-  5      5      U l        US:X  a•  [        R                  R"                  R%                  U R                   S   R&                  R(                  5        [        R                  R"                  R%                  U R                   S   R*                  R(                  5        g g [        R                  R                  XSS-  U-  5      U l        US:X  aH  [        R                  R"                  R%                  U R                  R&                  R(                  5        g g )Né   Úzeroéÿÿÿÿ)ÚsuperÚ__init__Úprefix_projectionÚ	token_dimÚ
num_layersÚencoder_hidden_sizeÚnum_virtual_tokensÚinit_weightsÚinference_modeÚtorchÚnnÚ	EmbeddingÚ	embeddingÚ
SequentialÚLinearÚTanhÚ	transformÚinitÚzeros_ÚweightÚdataÚbias)ÚselfÚconfigr   r   r   r   r   Ú	__class__s          €Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/prefix_tuning/model.pyr   ÚPrefixEncoder.__init__8   sŒ  ø€ Ü‰ÑÔØ!'×!9Ñ!9ˆÔØ×$Ñ$ˆ	Ø×&Ñ&ˆ
Ø$×8Ñ8ÐØ#×6Ñ6ÐØ×*Ñ*ˆØ×!×!Ð!¨&×*?×*?Ð*?ä"ŸX™X×/Ñ/Ð0BÓNˆDŒNÜ"ŸX™X×0Ñ0Ü—‘—‘ 	Ó?Ü—‘—‘“Ü—‘—‘Ð 3À!±^ÀiÑ5OÓPóˆDŒNð ˜vÓ%Ü—‘—‘×$Ñ$ T§^¡^°BÑ%7×%>Ñ%>×%CÑ%CÔDÜ—‘—‘×$Ñ$ T§^¡^°BÑ%7×%<Ñ%<×%AÑ%AÕBð &ô #ŸX™X×/Ñ/Ð0BÐQRÁNÐU^ÑD^Ó_ˆDŒNØ˜vÓ%Ü—‘—‘×$Ñ$ T§^¡^×%:Ñ%:×%?Ñ%?Õ@ð &ó    Úprefixc                 ó’   • U R                   (       a$  U R                  U5      nU R                  U5      nU$ U R                  U5      nU$ )N)r   r   r   )r    r&   Úprefix_tokensÚpast_key_valuess       r#   ÚforwardÚPrefixEncoder.forwardQ   sE   € Ø×!×!Ø ŸN™N¨6Ó2ˆMØ"Ÿn™n¨]Ó;ˆOð Ðð #Ÿn™n¨VÓ4ˆOØÐr%   Úprompt_embeddingsÚreturnNc                 ó2  • U R                   (       a  [        S5      eUR                  U R                  R                  R                  :w  aL  [        S[        U R                  R                  R                  5       S[        UR                  5       S35      e[        R                  " 5          U R                  R                  R                  UR                  U R                  R                  R                  5      5        SSS5        g! , (       d  f       g= f)aì  
Load the flattened prompt embeddings saved by PEFT (`prompt_embeddings`).

For prefix tuning, this is only supported when `prefix_projection=False`, because in that case the learned
parameters are the KV prefix itself (`embedding.weight` has shape `[num_virtual_tokens,
num_layers*2*token_dim]`).

If `prefix_projection=True`, the parameters are (virtual token embeddings + an MLP) and there is no general way
to invert the projection to recover those parameters from a flattened KV prefix.
zFCannot load flattened prompt embeddings when `prefix_projection=True`.z,Invalid `prompt_embeddings` shape. Expected z, got Ú.N)r   Ú
ValueErrorÚshaper   r   Útupler   Úno_gradÚcopy_ÚtoÚdevice)r    r,   s     r#   Úload_prompt_embeddingsÚ$PrefixEncoder.load_prompt_embeddingsY   sÇ   € ð ×!×!ÜÐeÓfÐfØ×"Ñ" d§n¡n×&;Ñ&;×&AÑ&AÓAÜØ>Ü˜Ÿ™×.Ñ.×4Ñ4Ó5Ð6°f¼UÐCT×CZÑCZÓ=[Ð<\Ð\]ð_óð ô �]Š]�_Ø�N‰N×!Ñ!×'Ñ'Ð(9×(<Ñ(<¸T¿^¹^×=RÑ=R×=YÑ=YÓ(ZÔ[÷ �_Ž_ús   Â,ADÄ
D)r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   ÚTensorr*   r7   Ú__static_attributes__Ú__classcell__)r"   s   @r#   r   r      s?   ø† ñ!õFAð2˜eŸl™lô ð\¸¿¹ð \È÷ \ò \r%   r   )r   r   ÚModuler   © r%   r#   Ú<module>rC      s"   ðó" ôX\�E—H‘H—O‘Oõ X\r%   