o
    
j                     @   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__ _/home/kuhnn/.local/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
    <