
    oi                     b    S SK r S SKrSSKJrJr   " S S\R
                  R                  5      rg)    N   )PromptEncoderConfig#PromptEncoderReparameterizationTypec                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )PromptEncoder   az  
The prompt encoder network that is used to generate the virtual token embeddings for p-tuning.

Args:
    config ([`PromptEncoderConfig`]): The configuration of the prompt encoder.

Example:

```py
>>> from peft import PromptEncoder, PromptEncoderConfig

>>> config = PromptEncoderConfig(
...     peft_type="P_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_reparameterization_type="MLP",
...     encoder_hidden_size=768,
... )

>>> prompt_encoder = PromptEncoder(config)
```

**Attributes**:
    - **embedding** (`torch.nn.Embedding`) -- The embedding layer of the prompt encoder.
    - **mlp_head** (`torch.nn.Sequential`) -- The MLP head of the prompt encoder if `inference_mode=False`.
    - **lstm_head** (`torch.nn.LSTM`) -- The LSTM head of the prompt encoder if `inference_mode=False` and
    `encoder_reparameterization_type="LSTM"`.
    - **token_dim** (`int`) -- The hidden embedding dimension of the base transformer model.
    - **input_size** (`int`) -- The input size of the prompt encoder.
    - **output_size** (`int`) -- The output size of the prompt encoder.
    - **hidden_size** (`int`) -- The hidden size of the prompt encoder.
    - **total_virtual_tokens** (`int`): The total number of virtual tokens of the
    prompt encoder.
    - **encoder_type** (Union[[`PromptEncoderReparameterizationType`], `str`]): The encoder type of the prompt
      encoder.


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

Output shape: (`batch_size`, `total_virtual_tokens`, `token_dim`)
c           	        > [         TU ]  5         UR                  U l        U R                  U l        U R                  U l        UR
                  U l        UR                  UR                  -  U l	        UR                  U l        [        R                  R                  U R                  U R                  5      U l        UR                   (       Gd  U R                  ["        R$                  :X  Ga  UR&                  nUR(                  n[        R                  R%                  U R                  U R                  UUSSS9U l        [        R                  R-                  [        R                  R/                  U R                  S-  U R                  S-  5      [        R                  R1                  5       [        R                  R/                  U R                  S-  U R                  5      5      U l        g U R                  ["        R4                  :X  GaI  [6        R(                  nUR(                  U:w  a1  [8        R:                  " SU R                  R<                   SU S35        [        R                  R/                  U R                  U R                  5      [        R                  R1                  5       [        R                  R/                  U R                  U R                  5      [        R                  R1                  5       [        R                  R/                  U R                  U R                  5      /n[        R                  R,                  " U6 U l        g [?        S5      eg )NT)
input_sizehidden_size
num_layersdropoutbidirectionalbatch_first   zfor z8, the argument `encoder_num_layers` is ignored. Exactly z MLP layers are used.PPrompt encoder type not recognized. Please use one of MLP (recommended) or LSTM.) super__init__	token_dimr
   output_sizeencoder_hidden_sizer   num_virtual_tokensnum_transformer_submodulestotal_virtual_tokensencoder_reparameterization_typeencoder_typetorchnn	Embedding	embeddinginference_moder   LSTMencoder_dropoutencoder_num_layers	lstm_head
SequentialLinearReLUmlp_headMLPr   warningswarnvalue
ValueError)selfconfiglstm_dropoutr   encoder_num_layers_defaultlayers	__class__s         T/home/james-whalen/.local/lib/python3.13/site-packages/peft/tuners/p_tuning/model.pyr   PromptEncoder.__init__G   st   ))..>>!55$*$=$=@a@a$a!"BB ++D,E,Et~~V$$$  $G$L$LL%55#66
!&# $ 0 0)("& $ "/ " !& 3 3HHOOD$4$4q$8$:J:JQ:NOHHMMOHHOOD$4$4q$8$:J:JK! ""&I&M&MM-@-S-S*,,0JJMMt00667 8##=">>SU
 HHOODOOT5E5EFHHMMOHHOOD$4$4d6F6FGHHMMOHHOOD$4$4d6F6FG !& 3 3V < !!sttK %    c                 "   U R                  U5      nU R                  [        R                  :X  a%  U R	                  U R                  U5      S   5      nU$ U R                  [        R                  :X  a  U R	                  U5      nU$ [        S5      e)Nr   r   )r   r   r   r!   r(   r$   r)   r-   )r.   indicesinput_embedsoutput_embedss       r4   forwardPromptEncoder.forwardy   s    ~~g. C H HH MM$..*Fq*IJM  "E"I"II MM,7M  oppr6   )	r   r   r   r
   r$   r(   r   r   r   )	__name__
__module____qualname____firstlineno____doc__r   r;   __static_attributes____classcell__)r3   s   @r4   r   r      s    ,\0ud	 	r6   r   )r*   r   r/   r   r   r   Moduler    r6   r4   <module>rF      s&   "   LjEHHOO jr6   