o
    ™º¥gï  ã                   @   sP   d dl mZmZmZ ddlmZ ddlmZ G dd„ deƒZG dd„ deƒZ	d	S )
é   )ÚTENSOR_NAME_QUANT_SUFFIXÚQuantizedValueÚQuantizedValueTypeé   )ÚQuantOperatorBase)ÚQDQOperatorBasec                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚDirect8BitOpc                    ó   t ƒ  ||¡ d S ©N©ÚsuperÚ__init__©ÚselfÚonnx_quantizerÚ	onnx_node©Ú	__class__© úc/var/www/visachat/venv/lib/python3.10/site-packages/onnxruntime/quantization/operators/direct_q8.pyr   	   ó   zDirect8BitOp.__init__c                    sb  | j }| jjsR| j |jd ¡}|d u r| j j|g7  _d S t|jd |jd t |j	|j
|jƒ}|| jj|jd < |j|jd< |j|jd< | j j|g7  _d S | j |jd ¡sbtƒ  ¡  d S | j |dg¡\}}}}|d u rwtƒ  ¡ S t|jd |jd t |d |d tjƒ}|| jj|jd < |d |jd< |j|jd< | |¡ | j j|7  _d S ©Né    )ÚnodeÚ	quantizerÚforce_quantize_no_input_checkÚfind_quantized_valueÚinputÚ	new_nodesr   Úoutputr   Ú
scale_nameÚzp_nameÚ
value_typeÚquantized_value_mapÚq_nameÚis_valid_quantize_weightr   ÚquantizeÚquantize_activationr   ÚInputÚappend)r   r   Úquantized_input_valueÚquantized_output_valueÚquantized_input_namesÚzero_point_namesÚscale_namesÚnodesr   r   r   r&      sP   û
û
û
zDirect8BitOp.quantize©Ú__name__Ú
__module__Ú__qualname__r   r&   Ú__classcell__r   r   r   r   r      s    r   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚQDQDirect8BitOpc                    r	   r
   r   r   r   r   r   r   E   r   zQDQDirect8BitOp.__init__c                 C   s˜   | j jr'| j  | jjd ¡ | js%| j  | jjd | jjd | jj¡ d S d S | j  	| jjd ¡rH| jsJ| j  | jjd | jjd | jj¡ d S d S d S r   )
r   r   Úquantize_activation_tensorr   r   Údisable_qdq_for_node_outputÚquantize_output_same_as_inputr   ÚnameÚis_tensor_quantized)r   r   r   r   r&   H   s   (ÿ(ÿzQDQDirect8BitOp.quantizer0   r   r   r   r   r5   D   s    r5   N)
Úquant_utilsr   r   r   Úbase_operatorr   Úqdq_base_operatorr   r   r5   r   r   r   r   Ú<module>   s
    <