o
    NÆÏi“  ã                   @   sh   d dl mZ d dlZd dlmZ d dlmZ ddlmZ eƒ r'G dd„ deƒZ	d	ej
jd
efdd„ZdS )é    )ÚOptionalN)Úis_inc_available)ÚBaseTunerLayeré   )ÚLinearc                       sT   e Zd Zdejjdef‡ fdd„Zddede	e
e  d	dfd
d„Zddd„Z‡  ZS )ÚIncLoraLinearÚ
base_layerÚadapter_namec                    s   t ƒ j||fi |¤Ž d S )N)ÚsuperÚ__init__)Úselfr   r	   Úkwargs©Ú	__class__© úH/home/ubuntu/.local/lib/python3.10/site-packages/peft/tuners/lora/inc.pyr       s   zIncLoraLinear.__init__FNÚ
safe_mergeÚadapter_namesÚreturnc                 C   ó   t dƒ‚)a†  
            Merge the active adapter weights into the base weights

            Args:
                safe_merge (`bool`, *optional*):
                    If True, the merge operation will be performed in a copy of the original weights and check for NaNs
                    before merging the weights. This is useful if you want to check if the merge operation will produce
                    NaNs. Defaults to `False`.
                adapter_names (`list[str]`, *optional*):
                    The list of adapter names that should be merged. If None, all active adapters will be merged.
                    Defaults to `None`.
            z3Merging LoRA with INC layers is not yet implemented©ÚNotImplementedError)r   r   r   r   r   r   Úmerge(   s   zIncLoraLinear.mergec                 C   r   )z_
            This method unmerges all merged adapter layers from the base weights.
            z5Unmerging LoRA from INC layers is not yet implementedr   )r   r   r   r   Úunmerge7   s   zIncLoraLinear.unmerge)FN)r   N)Ú__name__Ú
__module__Ú__qualname__ÚtorchÚnnÚModuleÚstrr   Úboolr   Úlistr   r   Ú__classcell__r   r   r   r   r      s    þý r   Útargetr	   c                 K   sN   d }t | tƒr|  ¡ }n| }tƒ r%ddlm} t ||ƒr%t| |fi |¤Ž}|S )Nr   )ÚPatchedLinear)Ú
isinstancer   Úget_base_layerr   ÚIneural_compressor.torch.algorithms.fp8_quant._quant_common.helper_modulesr%   r   )r$   r	   r   Ú
new_moduleÚtarget_base_layerr%   r   r   r   Údispatch_inc>   s   


r+   )Útypingr   r   Úpeft.import_utilsr   Úpeft.tuners.tuners_utilsr   Úlayerr   r   r   r   r    r+   r   r   r   r   Ú<module>   s   