o
    ²3Ihà  ã                   @   s`   d dl Z ddlmZmZ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 )é    Né   )ÚTENSOR_NAME_QUANT_SUFFIXÚQuantizedValueÚQuantizedValueTypeÚattribute_to_kwargÚ	ms_domainé   )ÚQuantOperatorBase)ÚQDQOperatorBasec                       s$   e Zd Zdd„ Z‡ fdd„Z‡  ZS )ÚQLinearWherec                 C   s   dS )NT© )Úselfr   r   úh/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/onnxruntime/quantization/operators/where.pyÚshould_quantize	   s   zQLinearWhere.should_quantizec              	      sf  | j }|jdks
J ‚| jjs| j j|g7  _d S | j |jd ¡\}}}}}| j |ddg¡\}}}}	|r:|d u r?tƒ  	¡ S |jd t
 }
|jrN|jd nd}t|jd |
||tjƒ}|| jj|jd < i }|jD ]	}| t|ƒ¡ qjt|d< |jd |d |d |d |d |d |d ||g	}tjjd||
g|fi |¤Ž}| j j|	7  _| j j|g7  _d S )	NÚWherer   r   r   Ú_quantÚ Údomainr   )ÚnodeÚop_typeÚ	quantizerÚforce_quantize_no_input_checkÚ	new_nodesÚ_get_quantization_paramsÚoutputÚquantize_activationÚsuperÚquantizer   Únamer   r   ÚInputÚquantized_value_mapÚ	attributeÚupdater   r   ÚinputÚonnxÚhelperÚ	make_node)r   r   Ú
data_foundÚoutput_scale_nameÚoutput_zp_nameÚ_Úq_input_namesÚzero_point_namesÚscale_namesÚnodesÚqlinear_outputÚqlinear_output_nameÚq_outputÚkwargsr!   Úqlwhere_inputsÚqlwhere_node©Ú	__class__r   r   r      sf   úû
û
÷
ÿÿzQLinearWhere.quantize)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   r5   r   r      s    r   c                   @   s   e Zd Zdd„ ZdS )ÚQDQWherec                 C   sÜ   | j }|jdks
J ‚| jjrE| j |jd ¡s | j |jd ¡ | j |jd ¡s2| j |jd ¡ | jsA|jD ]
}| j |¡ q8d S d S | j |jd ¡rf| j |jd ¡rh| jsj|jD ]}| j |¡ q]d S d S d S d S )Nr   r   r   )	r   r   r   r   Úis_tensor_quantizedr#   Úquantize_activation_tensorÚdisable_qdq_for_node_outputr   )r   r   r   r   r   r   r   F   s,   
þÿþý
úzQDQWhere.quantizeN)r7   r8   r9   r   r   r   r   r   r;   E   s    r;   )r$   Úquant_utilsr   r   r   r   r   Úbase_operatorr	   Úqdq_base_operatorr
   r   r;   r   r   r   r   Ú<module>   s    =