o
    ¢Äià  ã                   @   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   úb/home/kim/smarthome/.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   Z_quantÚ Údomainr   )ÚnodeÚop_typeÚ	quantizerÚforce_quantize_no_input_checkZ	new_nodesZ_get_quantization_paramsÚoutputZquantize_activationÚsuperÚquantizer   Únamer   r   ZInputZquantized_value_mapÚ	attributeÚupdater   r   ÚinputÚonnxÚhelperZ	make_node)r   r   Z
data_foundZoutput_scale_nameZoutput_zp_nameÚ_Zq_input_namesZzero_point_namesZscale_namesÚnodesZqlinear_outputZqlinear_output_nameZq_outputÚkwargsr   Zqlwhere_inputsZqlwhere_node©Ú	__class__r   r   r      sf   úû
û
÷
ÿÿzQLinearWhere.quantize)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   r#   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   Zis_tensor_quantizedr   Zquantize_activation_tensorZdisable_qdq_for_node_outputr   )r   r   r   r   r   r   r   F   s,   
þÿþý
úzQDQWhere.quantizeN)r%   r&   r'   r   r   r   r   r   r)   E   s    r)   )r   Zquant_utilsr   r   r   r   r   Zbase_operatorr	   Zqdq_base_operatorr
   r   r)   r   r   r   r   Ú<module>   s    =