o
    piE                     @   s8   d dl mZ ddlmZ ddlmZ G dd deZdS )	    )
functional   )Layer   )ConvertibleQuantedLayerc                       sF   e Zd ZdZdef fddZdd Zdd Zd	d
 Zdd Z	  Z
S )QuantedLinearz
    The computational logic of QuantizedLinear is the same as Linear.
    The only difference is that its inputs are all fake quantized.
    layerc                    sf   t    |j| _|j| _|j| _d | _d | _|jd ur#|j|| _|jd ur1|j|| _d S d S N)	super__init__weightbiasnameweight_quanteractivation_quanterZ	_instanceZ
activation)selfr   Zq_config	__class__ a/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddle/nn/quant/qat/linear.pyr      s   


zQuantedLinear.__init__c                 C   s@   |}| j }| jd ur| |}| jd ur| | j }| ||S r	   )r   r   r   _linear_forward)r   inputZquant_inputZquant_weightr   r   r   forward+   s   


zQuantedLinear.forwardc                 C   s   t j||| j| jd}|S )N)xr   r   r   )FZlinearr   r   )r   r   r   outr   r   r   r   4   s   zQuantedLinear._linear_forwardc                 C      dgS )N)r   r   r   r   r   r   r   weights_to_quanters8      z!QuantedLinear.weights_to_quantersc                 C   r   )Nr   r   r   r   r   r   activation_quanters;   r   z!QuantedLinear.activation_quanters)__name__
__module____qualname____doc__r   r   r   r   r   r    __classcell__r   r   r   r   r      s    	r   N)Z	paddle.nnr   r   Zlayer.layersr   formatr   r   r   r   r   r   <module>   s   