Ë
    ÝÍ:j
  ã                   óL   — d dl Z d dl mZ ddlmZmZ ddlmZ 	  G d„ de«      Zy)	é    N)Úonnx_pbé   )Úattribute_to_kwargÚ	ms_domainé   )ÚQuantOperatorBasec                   ó.   ‡ — e Zd Zˆ fd„Zd„ Zˆ fd„Zˆ xZS )ÚAttentionQuantc                 ó&   •— t         ‰| �  ||«       y ©N)ÚsuperÚ__init__)ÚselfÚonnx_quantizerÚ	onnx_nodeÚ	__class__s      €ú�/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/onnxruntime/quantization/operators/attention.pyr   zAttentionQuant.__init__   s   ø€ Ü‰Ñ˜¨Õ3ó    c                 óL   — | j                   j                  | j                  «      S r   )Ú	quantizerÚshould_quantize_nodeÚnode)r   s    r   Úshould_quantizezAttentionQuant.should_quantize   s   € Ø�~‰~×2Ñ2°4·9±9Ó=Ð=r   c                 óÂ  •— | j                   }|j                  dk(  sJ ‚|j                  D ]!  }|j                  dk(  sŒt        ‰| �  «       c S  | j                  j                  |dg«      \  }}}}| j                  j                  |dgdd¬«      \  }}}	}
|j                  |«       |j                  |«       |j                  |	«       |j                  |
«       |€t        ‰| �  «       S |j                  sdn|j                  d	z   }g }|j                  |«       |j                  |j                  d
   g«       |j                  |«       |j                  t        |j                  «      dkD  r|j                  d   ndg«       |j                  |«       |j                  t        |j                  «      dkD  r|j                  d   ndg«       i }|j                  D ]  }|j                  t        |«      «       Œ t        |d<   t        j                   j"                  d||j$                  |fi |¤Ž}|j'                  |«       | j                  xj(                  |z  c_        y)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(   zAttentionQuant.quantize   s  ø€ ð �y‰yˆØ�|‰|˜{Ò*Ð*Ð*ð
 —N‘Nò 	*ˆDØ�y‰yÐ.Ó.Ü‘wÑ'Ó)Ò)ð	*ð �N‰N×.Ñ.¨t°a°SÓ9ñ	
Ø!ØØØð �N‰N×*Ñ*¨4°!°À4Ð^bÐ*Ócñ	
Ø(Ø#ØØà×$Ñ$Ð%AÔBØ×ÑÐ 7Ô8Ø×ÑÐ-Ô.Ø�‰�\Ô"à Ð(Ü‘7Ñ#Ó%Ð%à$(§I¢I™"°4·9±9¸xÑ3GˆàˆØ�‰Ð+Ô,Ø�‰�t—z‘z !‘}�oÔ&Ø�‰�kÔ"Ø�‰¬¨D¯J©J«¸!Ò(;�t—z‘z !’}ÀÐDÔEØ�‰Ð&Ô'Ø�‰¬¨D¯J©J«¸!Ò(;�t—z‘z !’}ÀÐDÔEàˆØŸ™ò 	9ˆIØ�M‰MÔ,¨YÓ7Õ8ð	9ä$ˆˆxÑÜŸ+™+×/Ñ/°¸fÀdÇkÁkÐSbÑmÐflÑmˆØ�‰�_Ô%à�‰× Ò  EÑ)Ö r   )Ú__name__Ú
__module__Ú__qualname__r   r   r(   Ú__classcell__)r   s   @r   r
   r
      s   ø„ ô4ò>÷6*ð 6*r   r
   )	r/   r   Ú
onnx_protoÚquant_utilsr   r   Úbase_operatorr   r
   © r   r   ú<module>rJ      s#   ðÛ Ý &ç 7Ý ,ðô
=*Ð&õ =*r   