
    bi                    h    d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZ e G d de	             Zy)	    )annotations)	dataclassfield)OptionalUnion)
PeftConfig)PeftTypec                  ~    e Zd ZU dZ eeddi      Zded<    edddi	      Zd
ed<    edddi	      Z	ded<   d Z
y)TrainableTokensConfiga  
    Configuration for the `TrainableTokens` method.

    Allows for training new tokens (and re-training existing ones) without training the full embedding matrix. By
    marking a few select tokens (identified by their indices) trainable and leaving the rest untouched, this method can
    be used to add new tokens or changing the embedding of existing tokens while saving on memory. Both storage as well
    as working memory usage are reduced in contrast to training the embedding matrix fully.

    Note that training with FSDP/DeepSpeed might not yet be fully supported.

    Args:
        token_indices (`list[int]`):
            List of integers, signifying the indices of the tokens you want to be trainable. To find the index of a
            token with a tokenizer, you can tokenize the string and look at the returned `input_ids`. The closer the
            amount of indices is to the total amount of tokens, the less efficient this method gets.
        target_modules (`Optional[Union[list[str], str]]`):
            List of module names or regex expression of the module names to replace with our `TrainableTokensLayer`. If
            not defined, it will attempt to get the model's input embedding layer if the model has a
            `get_input_embeddings` method (transformer models usually do), if that fails the default is 'embed_tokens'.
            Other example targets are `embedding`, `encoder.embeddings` or `decoder.embeddings`.
        init_weights (`bool`):
            By default the new token weights are initialized to be the same as the respective token embeddings. This
            makes TrainableTokens a no-op when not trained. If set to `False` the weights will be random values. Do not
            change this setting unless you know exactly what you're doing.
    helpa)  List of integers, signifying the indices of the tokens you want to be trainable. To find the index of a token with a tokenizer, you can tokenize the string and look at the returned `input_ids`. The closer the amount of indices is to the total amount of tokens, the less efficient this method gets.)default_factorymetadataz	list[int]token_indicesNa  List of module names or regex expression of the module names to replace with our `TrainableTokensLayer`. If not defined, it will default to the model's input embedding layer if the model has a `get_input_embeddings` method (transformer models usually do), if that fails the default is 'embed_tokens'. Other example targets could be `embedding`, `encoder.embeddings` or `decoder.embeddings`.)defaultr   zOptional[Union[list[str], str]]target_modulesTa  By default the new token weights are initialized to be the same as the respective token embeddings. This makes TrainableTokens a no-op when not trained. If set to `False` the weights will be random values. Do not change this setting unless you know exactly what you're doing. boolinit_weightsc                .    t         j                  | _        y )N)r	   TRAINABLE_TOKENS	peft_type)selfs    ^/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/peft/tuners/trainable_tokens/config.py__post_init__z#TrainableTokensConfig.__post_init__W   s    !22    )__name__
__module____qualname____doc__r   listr   __annotations__r   r   r    r   r   r   r      sw    4  %?

 M9 
 7<(
7N3  a
	L$ 	3r   r   N)
__future__r   dataclassesr   r   typingr   r   peft.configr   
peft.utilsr	   r   r!   r   r   <module>r'      s1    # ( " "  ?3J ?3 ?3r   