o
    Ni                     @   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 )IncOFTLinear
base_layeradapter_namec                    s   t  j||fi | d S )N)super__init__)selfr   r	   kwargs	__class__ G/home/ubuntu/.local/lib/python3.10/site-packages/peft/tuners/oft/inc.pyr       s   zIncOFTLinear.__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`.
            z2Merging OFT with INC layers is not yet implementedNotImplementedError)r   r   r   r   r   r   merge(   s   zIncOFTLinear.mergec                 C   r   )z_
            This method unmerges all merged adapter layers from the base weights.
            z4Unmerging OFT from INC layers is not yet implementedr   )r   r   r   r   unmerge7   s   zIncOFTLinear.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   