
    h
                     L    S SK r S SK Jr  SSKJrJr  SSKJr    " S S\5      rg)	    N)onnx_pb   )attribute_to_kwarg	ms_domain   )QuantOperatorBasec                   :   ^  \ rS rSrU 4S jrS rU 4S jrSrU =r$ )AttentionQuant   c                 $   > [         TU ]  X5        g N)super__init__)selfonnx_quantizer	onnx_node	__class__s      f/var/www/fran/franai/venv/lib/python3.13/site-packages/onnxruntime/quantization/operators/attention.pyr   AttentionQuant.__init__   s    3    c                 L    U R                   R                  U R                  5      $ r   )	quantizershould_quantize_nodenode)r   s    r   should_quantizeAttentionQuant.should_quantize   s    ~~22499==r   c                   > U R                   nUR                  S:X  d   eUR                   H#  nUR                  S:X  d  M  [        TU ]  5       s  $    U R                  R                  US/5      u  nnnnU R                  R                  US/SSS9u  nnn	n
UR                  U5        UR                  U5        UR                  U	5        UR                  U
5        Uc  [        TU ]  5       $ UR                  (       d  SOUR                  S	-   n/ nUR                  U5        UR                  UR                  S
   /5        UR                  U5        UR                  [        UR                  5      S:  a  UR                  S   OS/5        UR                  U5        UR                  [        UR                  5      S:  a  UR                  S   OS/5        0 nUR                   H  nUR                  [        U5      5        M     [        US'   [        R                   R"                  " SXR$                  U40 UD6nUR'                  U5        U R                  =R(                  U-  sl        g)z
parameter node: Attention node.
parameter new_nodes_list: List of new nodes created before processing this node.
return: a list of nodes in topological order that represents quantized Attention node.
	Attentionqkv_hidden_sizesr   r   T)reduce_rangeop_level_per_channelN _quantr         domain
QAttention)r   op_type	attributenamer   quantizer   quantize_activationquantize_weightextendinputlenupdater   r   onnxhelper	make_nodeoutputappend	new_nodes)r   r   attrquantized_input_nameszero_point_namesscale_namesnodesquantized_input_names_weightzero_point_names_weightscale_names_weightnodes_weightqattention_nameinputskwargsr)   qattention_noder   s                   r   r+   AttentionQuant.quantize   s    yy||{***
 NNDyy..w')) # NN..taS9	
! NN**4!4^b*c	
(#$$%AB 78-.\" (7#%%$(II"499x3G+,tzz!}o&k"DJJ!(;tzz!}DE&'DJJ!(;tzz!}DEIMM,Y78 ($x++//fkkSbmflm_%  E) r    )	__name__
__module____qualname____firstlineno__r   r   r+   __static_attributes____classcell__)r   s   @r   r
   r
      s    4>6* 6*r   r
   )	r2   r   
onnx_protoquant_utilsr   r   base_operatorr   r
   rF   r   r   <module>rP      s#     & 7 ,
=*& =*r   