o
    ¢Äiï  ã                   @   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__©ÚselfZonnx_quantizerZ	onnx_node©Ú	__class__© úf/home/kim/smarthome/.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_checkZfind_quantized_valueÚinputZ	new_nodesr   Úoutputr   Z
scale_nameZzp_nameZ
value_typeZquantized_value_mapZq_nameZis_valid_quantize_weightr   ÚquantizeZquantize_activationr   ZInputÚappend)r   r   Zquantized_input_valueZquantized_output_valueZquantized_input_namesZzero_point_namesZ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   Zquantize_activation_tensorr   r   Zdisable_qdq_for_node_outputZquantize_output_same_as_inputr   ÚnameZis_tensor_quantized)r   r   r   r   r   H   s   (ÿ(ÿzQDQDirect8BitOp.quantizer   r   r   r   r   r$   D   s    r$   N)
Zquant_utilsr   r   r   Zbase_operatorr   Zqdq_base_operatorr   r   r$   r   r   r   r   Ú<module>   s
    <