o
    Ni&                     @  s   U d dl mZ d dlmZ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AnyOptionalN   )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   @/home/ubuntu/.local/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bool
state_dict!Optional[dict[str, torch.Tensor]]c                 C  sV   | j s| jr
td| jt vrtd| j dt| j }||| |||d}|jS )ax  
    Create PEFT layers and inject them into the model in-place.

    Currently the API does not support prompt learning methods and adaption prompt.

    This function is similar to [`get_peft_model`] but it does not return a [`PeftModel`] instance. Instead, it returns
    the original, mutated instance of the passed model.

    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.
        state_dict (`dict`, *optional*, defaults to `None`)
            If a `state_dict` is passed here, the adapters will be injected based on the entries of the state_dict.
            This can be useful when the exact `target_modules` of the PEFT method is unknown, for instance because the
            checkpoint was created without meta data. Note that the values from the `state_dict` are not used, only the
            keys are used to determine the correct layers that should be adapted.
    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   r   )is_prompt_learningis_adaption_prompt
ValueErrorr   r   keysr   )r   r   r   r   r   	tuner_cls
peft_modelr   r   r   inject_adapter_in_model/   s   

r%   )r   r   r   r   )r   FN)r   r   r   r   r   r   r   r   r   r   r   r   )
__future__r   typingr   r   r   torchutilsr   configr   tuners.tuners_utilsr	   r
   __annotations__r   r   r   r   r%   r   r   r   r   <module>   s    
