
    oi                     J    S SK r  " S S\ R                  R                  5      rg)    Nc                   N   ^  \ rS rSrSrU 4S jrS\R                  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           	        > [         TU ]  5         UR                  U l        UR                  nUR                  nUR
                  nUR                  nU R                  (       a  UR                  (       d  [        R                  R                  XR5      U l        [        R                  R                  [        R                  R                  X$5      [        R                  R                  5       [        R                  R                  XCS-  U-  5      5      U l        g [        R                  R                  XSS-  U-  5      U l        g )N   )super__init__prefix_projection	token_dim
num_layersencoder_hidden_sizenum_virtual_tokensinference_modetorchnn	Embedding	embedding
SequentialLinearTanh	transform)selfconfigr   r   r   r   	__class__s         Y/home/james-whalen/.local/lib/python3.13/site-packages/peft/tuners/prefix_tuning/model.pyr	   PrefixEncoder.__init__8   s    !'!9!9$$	&&
$88#66!!&*?*?"XX//0BNDN"XX00	? 3!^i5OPDN #XX//0BQRNU^D^_DN    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.forwardJ   sE    !! NN62M"nn];O  #nnV4Or   )r   r
   r   )__name__
__module____qualname____firstlineno____doc__r	   r   Tensorr"   __static_attributes____classcell__)r   s   @r   r   r      s$    !F`$ell  r   r   )r   r   Moduler    r   r   <module>r.      s   " <EHHOO <r   