
    g                     l    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e      Z G d	 d
e
      Zy)    N   )TENSOR_NAME_QUANT_SUFFIXQuantizedValueQuantizedValueTypeattribute_to_kwarg	ms_domain   )QuantOperatorBase)QDQOperatorBasec                   $     e Zd Zd Z fdZ xZS )QLinearWherec                      y)NT )selfs    ]/var/www/openai/venv/lib/python3.12/site-packages/onnxruntime/quantization/operators/where.pyshould_quantizezQLinearWhere.should_quantize	   s        c           	          | j                   }|j                  dk(  sJ | j                  j                  s!| j                  xj                  |gz  c_        y | j                  j                  |j                  d         \  }}}}}| j                  j                  |ddg      \  }}}}	|r|t        | %         S |j                  d   t        z   }
|j                  r|j                  dz   nd}t        |j                  d   |
||t        j                        }|| j                  j                  |j                  d   <   i }|j                   D ]  }|j#                  t%        |              t&        |d<   |j(                  d   |d   |d   |d   |d   |d   |d   ||g	}t+        j,                  j.                  d||
g|fi |}| j                  xj                  |	z  c_        | j                  xj                  |gz  c_        y )	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__s                    r   r"   zQLinearWhere.quantize   s   yy||w&&&~~;;NN$$.$ NN33DKKNC	
 NN..taV<	
]27#%%Q*BB6:iidii(2R!KKN$$
 >F**4;;q>:IMM,Y78 ($x JJqM!NQ!NQ

 {{,,N^,<>Q
U[
 	  E)   \N2 r   )__name__
__module____qualname__r   r"   __classcell__)r:   s   @r   r   r      s    63 63r   r   c                       e Zd Zd Zy)QDQWherec                 4   | j                   }|j                  dk(  sJ | j                  j                  r| j                  j	                  |j
                  d         s(| j                  j                  |j
                  d          | j                  j	                  |j
                  d         s(| j                  j                  |j
                  d          | j                  s-|j                  D ]  }| j                  j                  |        y y | j                  j	                  |j
                  d         rc| j                  j	                  |j
                  d         r:| j                  s-|j                  D ]  }| j                  j                  |        y y y y )Nr   r	   r   )	r   r   r   r   is_tensor_quantizedr(   quantize_activation_tensordisable_qdq_for_node_outputr   )r   r   r   s      r   r"   zQDQWhere.quantizeF   s/   yy||w&&&>>77>>55djjmD99$**Q-H>>55djjmD99$**Q-H33"kkFNN==fE * 4 NN..tzz!}=224::a=A44++99&A & 5 B >r   N)r;   r<   r=   r"   r   r   r   r@   r@   E   s    Br   r@   )r)   quant_utilsr   r   r   r   r   base_operatorr
   qdq_base_operatorr   r   r@   r   r   r   <module>rH      s0     u u , .:3$ :3zB Br   