U
    U?h                     @   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                    s   t  || d S Nsuper__init__selfZonnx_quantizerZ	onnx_node	__class__ ^/var/www/html/venv/lib/python3.8/site-packages/onnxruntime/quantization/operators/direct_q8.pyr   	   s    zDirect8BitOp.__init__c                    s`  | j }| jjs| j|jd }|d k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  _n| j|jd st   d S | j|dg\}}}}|d krt  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_namesZ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                    s   t  || d S r	   r
   r   r   r   r   r   E   s    zQDQDirect8BitOp.__init__c                 C   s   | j jrH| j | jjd  | js| j | jjd | jjd | jj n>| j 	| jjd r| js| j | jjd | jjd | jj 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   <