§
     íNg
  ã                   óT   — 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dS )	é    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                 óL   •— t          ¦   «                              ||¦  «         d S ©N)ÚsuperÚ__init__)ÚselfÚonnx_quantizerÚ	onnx_nodeÚ	__class__s      €úh/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnxruntime/quantization/operators/attention.pyr   zAttentionQuant.__init__   s#   ø€ Ý‰Œ×Ò˜¨Ñ3Ô3Ð3Ð3Ð3ó    c                 ó@   — | j                              | j        ¦  «        S r   )Ú	quantizerÚshould_quantize_nodeÚnode)r   s    r   Úshould_quantizezAttentionQuant.should_quantize   s   € ØŒ~×2Ò2°4´9Ñ=Ô=Ð=r   c                 óì  •— | j         }|j        dk    sJ ‚|j        D ]/}|j        dk    r"t	          ¦   «                              ¦   «         c S Œ0| j                             |dg¦  «        \  }}}}| j                             |dgdd¬¦  «        \  }}}	}
| 	                    |¦  «         | 	                    |¦  «         | 	                    |	¦  «         | 	                    |
¦  «         |€ t	          ¦   «                              ¦   «         S |j        sdn	|j        d	z   }g }| 	                    |¦  «         | 	                    |j
        d
         g¦  «         | 	                    |¦  «         | 	                    t          |j
        ¦  «        dk    r|j
        d         ndg¦  «         | 	                    |¦  «         | 	                    t          |j
        ¦  «        dk    r|j
        d         ndg¦  «         i }|j        D ]$}|                     t          |¦  «        ¦  «         Œ%t          |d<   t          j        j        d||j        |fi |¤Ž}|                     |¦  «         | j        xj        |z  c_        dS )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ˆØŒ|˜{Ò*Ð*Ð*Ð*ð
 ”Nð 	*ð 	*ˆDØŒyÐ.Ò.Ð.Ý‘w”w×'Ò'Ñ)Ô)Ð)Ð)Ð)ð /ð ŒN×.Ò.¨t°a°SÑ9Ô9ñ	
Ø!ØØØð ŒN×*Ò*¨4°!°À4Ð^bÐ*ÑcÔcñ	
Ø(Ø#ØØà×$Ò$Ð%AÑBÔBÐBØ×ÒÐ 7Ñ8Ô8Ð8Ø×ÒÐ-Ñ.Ô.Ð.ØŠ\Ñ"Ô"Ð"à Ð(Ý‘7”7×#Ò#Ñ%Ô%Ð%à$(¤IÐG˜"˜"°4´9¸xÑ3GˆàˆØŠÐ+Ñ,Ô,Ð,ØŠt”z !”}oÑ&Ô&Ð&ØŠkÑ"Ô"Ð"ØŠ­¨D¬J©¬¸!Ò(;Ð(;t”z !”}}ÀÐDÑEÔEÐEØŠÐ&Ñ'Ô'Ð'ØŠ­¨D¬J©¬¸!Ò(;Ð(;t”z !”}}ÀÐDÑEÔEÐEàˆØœð 	9ð 	9ˆIØMŠMÕ,¨YÑ7Ô7Ñ8Ô8Ð8Ð8Ý$ˆˆxÑÝœ+Ô/°¸fÀdÄkÐSbÐmÐmÐflÐmÐmˆØŠ_Ñ%Ô%Ð%àŒÐ Ô  EÑ)Ð Ô Ð Ð r   )Ú__name__Ú
__module__Ú__qualname__r   r   r(   Ú__classcell__)r   s   @r   r
   r
      s`   ø€ € € € € ð4ð 4ð 4ð 4ð 4ð>ð >ð >ð6*ð 6*ð 6*ð 6*ð 6*ð 6*ð 6*ð 6*ð 6*r   r
   )	r/   r   Ú
onnx_protoÚquant_utilsr   r   Úbase_operatorr   r
   © r   r   ú<module>rJ      s„   ðØ €€€Ø &Ð &Ð &Ð &Ð &Ð &à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ðð
=*ð =*ð =*ð =*ð =*Ð&ñ =*ô =*ð =*ð =*ð =*r   