o
    ;Î®c6  ã                   @   sR   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                    ó   t ƒ  ||¡ d S ©N©ÚsuperÚ__init__©ÚselfÚonnx_quantizerÚ	onnx_node©Ú	__class__© úP/tmp/pip-target-vg8gfxp4/lib/python/onnxruntime/quantization/operators/gather.pyr      ó   zGatherQuant.__init__c                 C   s&   | j  | j¡s	dS | j  | jjd ¡S )NFé    )Ú	quantizerÚ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
J ‚| j |dg¡\}}}}|d u 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 ©NÚGatherr   )r   Úop_typer   Úquantize_activationr   ÚquantizeÚoutputr   r   r   ÚInputÚquantized_value_mapr   ÚappendÚ	new_nodes)r   r   Úquantized_input_namesÚzero_point_namesÚscale_namesÚnodesÚgather_new_outputÚ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                    r	   r
   r   r   r   r   r   r   5   r   zQDQGather.__init__c                 C   s’   | j }|jdks
J ‚| j |jd ¡s| jjr/| j |jd ¡ | j |jd |jd ¡ d S | j |jd ¡rG| j |jd |jd ¡ d S d S r   )	r   r    r   r   r   Úforce_quantize_no_input_checkÚquantize_activation_tensorr#   Úis_tensor_quantized)r   r   r   r   r   r"   8   s   ÿzQDQGather.quantize)r.   r/   r0   r   r"   r1   r   r   r   r   r2   4   s    r2   N)
Úquant_utilsr   r   r   Úbase_operatorr   Úqdq_base_operatorr   r   r2   r   r   r   r   Ú<module>   s    *