o
    
jv                     @   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__ \/home/kuhnn/.local/lib/python3.10/site-packages/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dksJ | j|jd s| jjr6| j|jd  | j|jd |jd |j	 d S | j
|jd rP| j|jd |jd |j	 d S d S )Nr   GatherElementsr   )r   r   r   r   r   force_quantize_no_input_checkquantize_activation_tensorquantize_output_same_as_inputr"   nameis_tensor_quantized)r   r   r   r   r   r!   8   s   ""zQDQGather.quantize)r-   r.   r/   r   r!   r0   r   r   r   r   r1   4   s    r1   N)
quant_utilsr   r   r   base_operatorr   qdq_base_operatorr   r   r1   r   r   r   r   <module>   s    *