U
    “±Ëh6  ã                   @   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__© úM/tmp/pip-unpacked-wheel-socb9apf/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 ¡ n,| j 	|jd ¡rˆ| j |jd |jd ¡ d S r   )
r   r   r   r   r   r   Zforce_quantize_no_input_checkZquantize_activation_tensorr   Z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   *