U
    U?hR                     @   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                       s0   e Zd Z fddZdd Z fddZ  ZS )GatherQuantc                    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/gather.pyr      s    zGatherQuant.__init__c                 C   s&   | j | jsdS | j | jjd S )NF    )	quantizerZshould_quantize_nodenodeis_valid_quantize_weightinput)r   r   r   r   should_quantize   s    zGatherQuant.should_quantizec                    s   | j }|jdkst| j|dg\}}}}|d kr>t  S |jd t }t	|jd ||d |d t
j}|| jj|jd < ||jd< |d |jd< || | j j|7  _d S NZGatherr   )r   op_typeAssertionErrorr   Zquantize_activationr   quantizeoutputr   r   r   ZInputZquantized_value_mapr   appendZ	new_nodes)r   r   Zquantized_input_namesZzero_point_namesZscale_namesZnodesZgather_new_outputZq_outputr   r   r   r      s.    


zGatherQuant.quantize)__name__
__module____qualname__r   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 )	QDQGatherc                    s   t  || d S r	   r
   r   r   r   r   r   5   s    zQDQGather.__init__c                 C   s   | j }|jdkst| j|jd s.| jjr`| j|jd  | j|j	d |jd |j
 n0| j|jd r| j|j	d |jd |j
 d S r   )r   r   r   r   r   r   Zforce_quantize_no_input_checkZquantize_activation_tensorZquantize_output_same_as_inputr   nameZis_tensor_quantized)r   r   r   r   r   r   8   s     zQDQGather.quantize)r   r    r!   r   r   r"   r   r   r   r   r#   4   s   r#   N)
Zquant_utilsr   r   r   Zbase_operatorr   Zqdq_base_operatorr   r   r#   r   r   r   r   <module>   s   *