o
    8wi                     @  s   U d dl mZ d dlmZmZ d dlZddlmZ er'ddlm	Z	 ddl
mZ i Zded	< i Zd
ed< i Zd
ed< i Zded< d ddZ	d!d"ddZdS )#    )annotations)TYPE_CHECKINGAnyN   )PeftType)
PeftConfig)	BaseTunerz dict[PeftType, type[PeftConfig]]PEFT_TYPE_TO_CONFIG_MAPPINGzdict[PeftType, type[BaseTuner]]PEFT_TYPE_TO_TUNER_MAPPING PEFT_TYPE_TO_MIXED_MODEL_MAPPINGzdict[PeftType, str]PEFT_TYPE_TO_PREFIX_MAPPINGconfig_dictdict[str, Any]returnr   c                 C  s   t | d  di | S )z
    Returns a Peft config object from a dictionary.

    Args:
        config_dict (`Dict[str, Any]`): Dictionary containing the configuration parameters.
    	peft_typeN )r	   )r   r   r   I/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/peft/mapping.pyget_peft_config$   s   r   defaultFpeft_configmodeltorch.nn.Moduleadapter_namestrlow_cpu_mem_usageboolc                 C  sT   | j s| jr
td| jt vrtd| j dt| j }||| ||d}|jS )a  
    A simple API to create and inject adapter in-place into a model. Currently the API does not support prompt learning
    methods and adaption prompt. Make sure to have the correct `target_names` set in the `peft_config` object. The API
    calls `get_peft_model` under the hood but would be restricted only to non-prompt learning methods.

    Args:
        peft_config (`PeftConfig`):
            Configuration object containing the parameters of the Peft model.
        model (`torch.nn.Module`):
            The input model where the adapter will be injected.
        adapter_name (`str`, `optional`, defaults to `"default"`):
            The name of the adapter to be injected, if not provided, the default adapter name is used ("default").
        low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
            Create empty adapter weights on meta device. Useful to speed up the loading process.
    zN`create_and_replace` does not support prompt learning and adaption prompt yet.z+`inject_adapter_in_model` does not support z" yet. Please use `get_peft_model`.)r   r   )is_prompt_learningis_adaption_prompt
ValueErrorr   r
   keysr   )r   r   r   r   	tuner_cls
peft_modelr   r   r   inject_adapter_in_model/   s   
r"   )r   r   r   r   )r   F)
r   r   r   r   r   r   r   r   r   r   )
__future__r   typingr   r   torchutilsr   configr   tuners.tuners_utilsr   r	   __annotations__r
   r   r   r   r"   r   r   r   r   <module>   s   
