+
    9iϐ                         ^ RI t ^ RIt^ RIHtHt ^ RIHt ^ RIH	t	H
t
 ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIHt ] P*                  ! ]4      t ! R	 R
]4      t ! R R]4      t ! R R]4      tR# )    N)AttentionMaskFusionAttention)Fusion)"FusionSimplifiedLayerNormalization&FusionSkipSimplifiedLayerNormalization)NumpyHelper)	NodeProtoTensorProtohelper	OnnxModel)BertOnnxModelc                   x   a a ] tR t^t oRtV3R lV 3R lltV3R lR ltV3R lR ltR tR	 t	R
 t
RtVtV ;t# )FusionT5Attentionz5
Fuse T5 Attention subgraph into one Attention node.
c                2   < V ^8  d   QhRS[ RS[RS[RS[/# )   modelhidden_size	num_headsattention_mask)r   intr   )format__classdict__s   "d/var/www/html/photoedit/myenv/lib/python3.14/site-packages/onnxruntime/transformers/onnx_model_t5.py__annotate__FusionT5Attention.__annotate__   s3        	
 &    c           	     B   < \         SV `  VVVVR R.R7       ^V n        R# )FSoftmax)use_multi_head_attentionsearch_op_typesN)super__init__	static_kv)selfr   r   r   r   	__class__s   &&&&&r   r#   FusionT5Attention.__init__   s4     	%*&K 	 	
 r   c                   < V ^8  d   QhRS[ R,          RS[RS[RS[RS[RS[RS[ R	S[ R
S[ R,          RS[RS[R,          /# )r   
mask_indexNq_matmulk_matmulv_matmulr   r   inputoutput	attn_biasscalereturn)strr	   r   float)r   r   s   "r   r   r   )   s     o o$Jo o 	o
 o o o o o :o o 
T	or   c                   V^ 8  g   Q hV^ 8  d+   We,          ^ 8w  d   \         P                  RV RV 24       R# V P                  P                  VP                  ^,          4      pV P                  P                  VP                  ^,          4      pV P                  P                  VP                  ^,          4      pVe	   Ve   Vf0   Vf   TMVf   TMTp\        VP                  ^,           R24       R# \        P                  ! V4      p\        P                  ! V4      p\        P                  ! V4      pVP                  VP                  8X  g   Q hVP                  ^ ,          pVP                  ^ ,          pVP                  ^ ,          pVTu;8X  d	   V8X  g   Q h Q hV^ 8  d$   VV8w  d   \         P                  RV RV R24       \        P                  ! VP                  R,          4      p\        P                  ! VVV3^R	7      p^V,          pV P                  P                  R
4      p\        P                  ! VR,           \         P"                  VV.VP%                  4       RR7      pV P                  P'                  VV P(                  4       VVR,           R.pV'       d   VP+                  V4       MVP+                  R4       V	'       d#   VP+                  R4       VP+                  V	4       V'       d!   VR,          R8X  d   VP-                  4        K(  \        P.                  ! R
VV.VR7      pRVn        VP2                  P5                  \        P6                  ! RV4      .4       V
e2   VP2                  P5                  \        P6                  ! RV
4      .4       V P8                  eE   VP2                  P5                  \        P6                  ! R\;        V P8                  4      4      .4       V# )a\  Create an Attention node.
Args:
    mask_index (str): mask input
    q_matmul (NodeProto): MatMul node in fully connection for Q
    k_matmul (NodeProto): MatMul node in fully connection for K
    v_matmul (NodeProto): MatMul node in fully connection for V
    num_heads (int): number of attention heads. If a model is pruned, it is the number of heads after pruning.
    hidden_size (int): hidden dimension. If a model is pruned, it is the hidden dimension after pruning.
    input (str): input name
    output (str): output name
Returns:
    Union[NodeProto, None]: the node created or None if failed.
input hidden size # is not a multiple of num of heads Nzl is not an initializer. Please set do_constant_folding=True in torch.onnx.export to unblock attention fusionzInput hidden size (z3) is not same as weight matrix dimension of q,k,v (z:). Please provide a correct input hidden size or pass in 0:   NN)axis	Attention_qkv_weightTname	data_typedimsvalsraw inputsoutputsr<   com.microsoftr   r0   mask_filter_value)loggerdebugr   get_initializerr-   printr   to_arrayshapewarningnpprodstackcreate_node_namer   make_tensorr
   FLOATtobytesadd_initializerthis_graph_nameappendpop	make_nodedomain	attributeextendmake_attributerF   r3   )r%   r)   r*   r+   r,   r   r   r-   r.   r/   r0   q_weightk_weightv_weightmatmulqwkwvw
qw_in_size
kw_in_size
vw_in_sizeqw_out_size
qkv_weightqkv_weight_dimattention_node_nameweightattention_inputsattention_nodes   &&&&&&&&&&&                 r   make_attention_node%FusionT5Attention.make_attention_node)   sp   4 1}}? 7A=LL-k]:]^g]hij::--hnnQ.?@::--hnnQ.?@::--hnnQ.?@x/83C!)!1X8CSxYaF<<?# $g g !!(+!!(+!!(+ xx288###XXa[
XXa[
XXa[
Z5:55555?{j8NN%k]2efpeq rJ J
 ggbhhrl+XXr2rl3
["jj99+F##$}4!''n-##%
 	

""64+?+?@ -/

 ##J/##B'##B'##I.#3B#72#=  "))#H$	
 !0  '')>)>{I)V(WX$$++V-B-B7E-R,ST!!-$$++V-B-BCVX]^b^t^tXu-v,wxr   c                   < V ^8  d   QhRS[ RS[ RS[ RS[ R,          RS[ R,          RS[ R,          RS[ R,          R	S[ R
S[ R,          RS[ R,          RS[RS[RS[R,          /# )r   querykeyvaluer)   Nr/   past_key
past_valuer.   present_keypresent_valuer   r   r1   )r2   r   r	   )r   r   s   "r   r   r      s     D DD D 	D
 $JD :D *D $JD D 4ZD TzD D D 
T	Dr   c                   V^ 8  d    V^ 8  d   V'       d   V'       d	   V'       g   Q hW,          ^ 8w  d   \         P                  RV RV 24       R# V P                  P                  R4      pVVVR.pV'       d   VP	                  V4       MVP	                  R4       V'       d   VP	                  V4       MVP	                  R4       V'       d-   V'       g   Q hVP	                  V4       VP	                  V4       V'       d!   VR,          R8X  d   VP                  4        K(  V.pV	'       d-   V
'       g   Q hVP	                  V	4       VP	                  V
4       \        RV: RV: RV: 24       \        P                  ! RVVVR	7      pR
Vn	        VP                  P                  \        P                  ! RV4      .4       VP                  P                  \        P                  ! RR4      .4       V P                  eE   VP                  P                  \        P                  ! R\        V P                  4      4      .4       V P                  R4       V# )r   r5   r6   NMultiHeadAttentionrA   zattention_inputs=z, attention_outputs=z, attention_node_name=rB   rE   r   r0         ?rF   rG   )rH   rI   r   rR   rX   rY   rK   r   rZ   r[   r\   r]   r^   rF   r3   increase_counter)r%   rs   rt   ru   r)   r/   rv   rw   r.   rx   ry   r   r   rl   rn   attention_outputsro   s   &&&&&&&&&&&&&    r   create_mha_node!FusionT5Attention.create_mha_node   s	    1}qUsuLL#)LL-k]:]^g]hij"jj99:NO	
 ##J/##B'##I.##B':##H-##J/#3B#72#=  "#H  =$$[1$$]3"!##8&7%99P<O;QRS)) #%$	
 !0  '')>)>{I)V(WX  '')>)>w)L(MN!!-$$++V-B-BCVX]^b^t^tXu-v,wx23r   c                ^    V P                  WV4      '       d   R # V P                  WV4       R # N)fuse_t5_encoderfuse_t5_decoder)r%   nodeinput_name_to_nodesoutput_name_to_nodes   &&&&r   fuseFusionT5Attention.fuse   s*    ;NOOT8KLr   c                \	  a  VP                   R 8X  g   Q hV P                  P                  V. RO. ROVR7      pVf   R# Vw  rVpV P                  P                  V. RO. ROV4      pVf   R# VR,          p	V P                  P                  V. RO. ROV4      p
V
f   R# V
w  rkpV P                  P                  V. RO. ROV4      pVf   R# Vw  rnpV P                  P                  V. RO. ROV4      pVRJ pVe   V^,          pMWV P                  P                  V. RO. ROV4      pVf)   V P                  P                  V. RO. ROV4      pVf   R# V^,          pV P                  P	                  V4      w  ppVf   R# VR8w  d   \        V4      V n        V P                  P                  VR,          . RO. ROV4      o V P                  P                  VR,          . RO. ROV4      pS e   \        ;QJ dA    V 3R lV P                  P                  4       P                   4       F  '       g   K   RM6	  RM2! V 3R lV P                  P                  4       P                   4       4      '       d`   Ve\   S R,          P                  ^ ,          VR,          P                  ^ ,          8X  d%   \        S ^,          P                  4      ^8X  d   RpM3V P                  P                  VR,          P                  ^ ,          4      pRpV P                  P                  VRR.^^ .4      pVf*   V'       d"   V P                  P                  V. RO. RO4      pVf   R# VR,          P                  ^ ,          pV P                  P                  V. RO. RO4      pVf   R# Vw   ppV P                  P                  V. RO. RO4      pVf   R# Vw  pppVP                  ^ ,          V	P                  ^ ,          8w  d   R# V P                  V4      w  ppV P                  VVVVVVV	P                  ^ ,          VP                  ^ ,          VR	R
7
      pVf   R# V P                   P#                  V4       V P$                  V P&                  VP(                  &   V P*                  P#                  V4       RV n        R# )r   edgesr   NFAddc              3   p   <"   T F+  qP                   SR,          P                  ^ ,          8H  x  K-  	  R# 5i)r7   NrG   )r<   r-   ).0r-   mask_nodes_2s   & r   	<genexpr>4FusionT5Attention.fuse_t5_encoder.<locals>.<genexpr>F  s*     bIaJJ,r"2"8"8";;Ias   36TrA   RelativePositionBiasr|   )r   r   r-   r.   r/   r0   MatMul	TransposeReshaper   r   r   r   Concat	UnsqueezeGatherShaper7   r   r   r   rG   r   r   r   r7   r   r   r   r   r   r   r   r   r   MulSubCastr   r   r7   r7   r   r7   r   r   )r   Slicer   r   r   r   )r7   r7   r   r   r7   r   r   r   r   r   r   r   r   r7   r7   r   r   r7   r   r   )ConstantOfShaper   r   r   r   r   r   r   r   r   )r   r   r7   r   r   )r   r   r   )op_typer   match_child_pathmatch_parent_pathget_constant_inputr3   rF   anygraphr-   lenr   process_maskr.   get_num_heads_and_hidden_sizerp   nodes_to_addrX   rW   node_name_to_graph_namer<   nodes_to_removeprune_graph)!r%   softmax_noder   r   	qkv_nodes
matmul_qkv_reshape_qkvqkv_shape_nodesinput_shape_nodev_nodes	reshape_vmatmul_vqk_nodesadd_qk	matmul_qk
mask_nodesis_pattern_for_one_graph_inputmul_nodemul_valmask_nodes_3r)   res_pos_bias	rpb_nodesk_nodesmatmul_kq_nodes	reshape_qmatmul_qq_num_headsq_hidden_sizenew_noder   s!   &&&&                            @r   r   !FusionT5Attention.fuse_t5_encoder   s|   ##y000JJ//.* 3	 0 
	 %."
{**666	
 "*2.**...	
 ?!(h :://(	
 '9ZZ11C	

 *4t);&!!!}H 55H"#	J !!ZZ99T)'	
 % !!}HZZ228<
7?f%*7^D" zz33rNI	
 zz33rNI	
 $bIYIYI[IaIabbIYIYI[IaIabbb(R &&q)\"-=-C-CA-FFLO))*a/J,,99*R.:N:Nq:QRJJJ00*+F
	
 !?

448I
  }++A.**...

 ? 1h **...

 ?!(9h >>! 0 6 6q 99%)%G%G	%R"]++!%"((+%%a(" , 
   *6:6J6J$$X]]3##K0r   c                D   VP                   R 8X  g   Q hV P                  P                  V. RO. ROVR7      pVf   R# Vw  rVpV P                  P                  V. RO. RO4      pVf   R# VR,          p	Rp
RpRpV P                  P                  V. RO. RO4      pVf   V P                  P                  V. RO. RO4      pVen   Vw  rpVP                  ^ ,          p
VP
                  ^ ,          pRV9  d   R# VP                  ^ ,          V	P                  ^ ,          8w  d	   ^V n        M^ V n        MVP                  ^,          pW9   d   R# RV9  d   R# ^V n        MaVw  ppppVP                  ^ ,          pW9   d   R# RV9  d   R# VP
                  ^ ,          pRV9  d   R# VP                  ^ ,          p
^ V n        V P                  P                  V. RO. RO4      pVf   R# Vw  pppRpRpV P                  ^8X  d   V P                  P                  V. R O. R!O4      pVe   V^,          pM0V P                  P                  V. R"O. R#O4      pVf   R# V^,          pV P                  P                  V4      w  ppVR$8w  d   VV n        V P                  P                  VR,          P                  ^ ,          4      pM`V P                  P                  VRR	.^^ .3RR
.^^ .3.V4      w  p pV^ 8  d   \        P                  R4       R# VP                  ^,          pRpRpRpV P                  ^8X  Ed   V P                  P                  V. RO. RO4      pVe   Vw  p p!pV!P                  ^ ,          pVV!P
                  ^ ,          ,          p"V" FA  p#V P                  P                  V#P
                  ^ ,          4      p$V$f   K5  V$P                  p M	  Vf   R# RV9  d   R# EMHV P                  P                  VR.^.4      pVf   R# V^ ,          p V P                  ^ ,          pVV9   d   R# RV9  d   R# EMV P                  P                  V. R%O. R&O3. R'O. R(O3.V4      w  p%ppRp&Rp"VEe   V^,          VR),          p!p'V!P                  ^ ,          pV%^ 8X  d/   VV'P                  ^ ,          ,          p&V&P                  ^ ,          pMV'P                  ^ ,          pVV9   d   R# RV9  d   R# V%^ 8X  dc   VV'P
                  ^ ,          ,          p"V" FA  p#V P                  P                  V#P
                  ^ ,          4      p$V$f   K5  V$P                  p M	  MV'P
                  ^ ,          pVf   R# RV9  d   R# MV P                  P                  V. RO. RO4      pVf   R# Vw  pp!pV!P                  ^ ,          pVV!P
                  ^ ,          ,          p"V" FA  p#V P                  P                  V#P
                  ^ ,          4      p$V$f   K5  V$P                  p M	  Vf   R# RV9  d   R# V P                  P                  V. RO. RO4      p(V(f   R# V(w  p)p*p+V+P                  ^ ,          V	P                  ^ ,          8w  d   R# V P!                  V*4      w  p,p-V P                  ^8X  d   Ve	   TpTp
RpRpV'       d   V
'       d   V,^ 8  d   V-^ 8  g   R# V P#                  V+P
                  ^ ,          VV
VVVVVP
                  ^ ,          VVV,V-R7      p.V.'       Ed   V P$                  P'                  V.4       V P(                  V P*                  V.P                  &   V'       g	   V'       d   VV3 F  p/V/'       d"   V P                  P                  V/4      '       g   \-        RV/: R24        R# V/V9   g   Q hV/R,           VV/,          P
                  ^ &   V P                  P/                  V/V/R,           4       K  	  V P0                  P'                  V4       RV n        R# R# )*r   r   r   Nry   past_value_crosspast_value_selfpresent_value_selfr   r   r   zGSkip MultiHeadAttention fusion since attention bias pattern not matchedpresent_key_crosspast_key_crosspast_key_selfpresent_key_self)rs   rt   ru   r)   r/   rv   rw   r.   rx   ry   r   r   zgraph_output=z does not exist in graph output_copyFr   r   r   r   rG   )r   r   r   r   )r7   r7   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r7   r   r7   r   )r   r   r   r   r   )r7   r   r7   r   r   )r   r   r   r   r-   r.   r$   r   rF   r   r   match_parent_pathsrH   rI   find_graph_outputr<   r   r   r   rX   rW   r   rK   replace_input_of_all_nodesr   r   )0r%   r   r   r   r   r   _transpose_qkvr   r   r   ru   rw   ry   r   transpose_vr   r   concat_vr   r   r   r   r)   r   r   r   r   matched_path_indexrt   rv   rx   r   transpose_k	reshape_kpresent_key_transpose_nodespresent_key_transpose_nodepresent_key_candidateidxpast_key_transpose_nodeconcat_kr   transpose_qr   r   r   r   r   graph_outputs0   &&&&                                            r   r   !FusionT5Attention.fuse_t5_decoder  s    ##y000JJ//.* 3	 0 
	 2;/
K**666

 "*2.
**..8

 ?jj222G
 "3:0!* + 2 21 5"-7>>!$(8(>(>q(AA%&DN%&DN'--a0
4%Z7!"(/%HaA!*J0 
2$OOA.M#=8OOA&EDN:://(

 '69
>>Q55G"J
 %%a=!ZZ99T)

 %%a=66x@JAw& )0&,,99*R.:N:Nq:QRJ'+zz'D'DW%1v.34q!f= $($1 "A%fg!<<?L>>Qjj222G
 ",3)Yooa(.A)BRBRSTBU.V+2M.,0JJ,H,HIcIjIjklIm,n),8&;&@&@	 3N
 &&k9 : **66 MC
 ?%aj&,,Q/22#83 4 #jj;;A<PNP_` $OC! '+#*.'"&-aj'"+)ooa(!8.A(..QRBS.T+6<<Q?H'~~a0H22"(2!82EhooVWFX2Y/6Q204

0L0LMgMnMnopMq0r-0<*?*D*DK!	 7R #+//!"4K&%[8 9 **666
 ?")9aooa(.A)BRBRSTBU.V+2M.,0JJ,H,HIcIjIjklIm,n),8&;&@&@	 3N
 &%[8**...

 ?+2(Y>>! 0 6 6q 99%)%G%G	%R"]>>Q8#7CEHJ+/ma6G''//!$!"!%%a(#'!% ( 
 8$$X.:>:N:ND((7 m%0-$@L(TZZ-I-I,-W-W/NOP'+>>>>BNQXBX'5<<Q?JJ99,W^H^_ %A   ''4$D r   )rF   r   r$   )__name__
__module____qualname____firstlineno____doc__r#   rp   r   r   r   r   __static_attributes____classdictcell____classcell__r&   r   s   @@r   r   r      sG      "o obD DLMiVI% I%r   r   c                   D   a a ] tR tRt oV3R lV 3R lltR tRtVtV ;t# )FusionRelativePositionBiasBlocki  c                    < V ^8  d   QhRS[ /# )r   r   r   )r   r   s   "r   r   ,FusionRelativePositionBiasBlock.__annotate__  s     E Ei Er   c                ,   < \         SV `  VR R.4       R# )r   r   N)r"   r#   )r%   r   r&   s   &&r   r#   (FusionRelativePositionBiasBlock.__init__  s     6Dr   c                   V P                   P                  V. RO. ROV4      pVf)   V P                   P                  V. RO. ROV4      pVf   R# V^,          pVR,          pV^,          pV^,          pWP                  9   d   R# V P                   P                  V. RO. ROV4      p	V	f   R# V P                   P                  V	R,          P                  ^,          4      p
V	R,          pV P                   P                  V. RO. ROV4      pRpVf+   V P                   P                  V. RO. ROV4      pRpVf   R# VR,          p\        \        P                  ! \        P                  ! V
4      ^ V'       d   ^M^,          ,          4      4      pV^8w  d   \        P                  RV R24       V P                   P                  RRV'       d   RMR	,           R
7      pV P                   P                  VP                  ^ ,          4      pVf   R# \        P                  ! V4      p\        P                  ! V4      p\         P"                  ! VR,           \$        P&                  \        P(                  ! V4      ^ ,          \        P(                  ! V4      ^,          .VP+                  4       RR7      pV P                   P-                  VV P.                  4       VP0                  VP                  ^,          VP                  ^,          .pVR,           pVVP                  ^ &   \         P2                  ! RVV.VR7      pRVn        VP6                  P9                  \         P:                  ! RV4      .4       VP6                  P9                  \         P:                  ! RV4      .4       V P.                  V P<                  VP0                  &   V P>                  PA                  V4       RV n!        R# )r   NFTzmax_distance is z], which is different from the default value 128. Please double check the model configuration.r   RelPosBias_encoderdecodername_prefix_bias_table_weightr;   _rel_pos_biasrB   rE   max_distanceis_bidirectional)r   r   r   r   r   r   Where)r   r7   r   r   r   r   r7   )r   r   r   r   r   r   r   r  )r   r7   r   r   r   r   r7   r7   rG   )	Minr   r   r   r   r   DivLogr  )	r   r7   r   r   r   r   r   r   r   )r   Negr  r   r   r   r   Range)r   r   r   r7   r   r   r   r   )r   Absr   r   r  r   )"r   r   r   get_constant_valuer-   r   rO   roundexprH   rN   rR   rJ   r   rL   	transposer   rS   r
   rT   rM   rU   rV   rW   r<   rZ   r[   r\   r]   r^   r   r   rX   r   )r%   r   r   r   compute_bias_nodesgatherwhereslice	unsqueezecompute_buckets_nodeslog_maxdivrange_nodesr  
range_noder  	node_nametable_weight_itable_weighttable_weight_t
bias_tablerC   bias_outputrpb_nodes   &&&&                    r   r   $FusionRelativePositionBiasBlock.fuse  sq   !ZZ99P!	
 %!%!=!=[(#	" ")#A&"2&"1%&q)	 ,,, $

 < <Z'	!
 !( **//0Eb0I0O0OPQ0RS#B'jj22[$	
 !**66A?TgK  $" _
 288BFF7OrCSaYZ7[$\]^3NN"<. 1? ?
 JJ//"N^dm0n 0 
	 33FLLOD!"++N;l3''11!''((<(+RXXl-CA-FG'')

 	

"":t/C/CDP //:#3#3A#6
8H8H8KL  /1$A##" M	
 *!!6#8#8#V"WX!!6#8#89KM]#^"_`6:6J6J$$X]]3  *r   )r   )	r   r   r   r   r#   r   r   r   r   r   s   @@r   r   r     s     E ER  R r   r   c                   v   a a ] tR tRt oRV3R lV 3R llltR tR tRR ltR tR t	R	 t
R
 tR tRtVtV ;t# )T5OnnxModeli6  c                &   < V ^8  d   QhRS[ RS[ /# )r   r   r   )r   )r   r   s   "r   r   T5OnnxModel.__annotate__7  s     @ @ @s @r   c                  < \         SV `  WV4       \        V 4      V n        \	        V P
                  P                  P                  4      ^8X  d"   ^ RIH	p VP                  V P                  n        \        W P                  V P                  V P                  4      V n        \!        V 4      V n        \%        V 4      V n        \)        V 4      V n        R# )r7   )AttentionMaskFormatN)r"   r#   r   r   r   r   r   r-   fusion_optionsr1  NoMaskmask_formatr   r   r   attention_fusionr   layer_norm_fusionr   skip_layer_norm_fusionr   
rpb_fusion)r%   r   r   r   r1  r&   s   &&&& r   r#   T5OnnxModel.__init__7  s    ;7+D1 tzz%%&!+:.A.H.HD+ 1$8H8H$..Z^ZmZm n!CD!I&LT&R#9$?r   c                :    V P                   P                  4        R # r   )r5  applyr%   s   &r   fuse_attentionT5OnnxModel.fuse_attentionF  s    ##%r   c                :    V P                   P                  4        R # r   )r6  r;  r<  s   &r   fuse_layer_normT5OnnxModel.fuse_layer_normI  s    $$&r   c                :    V P                   P                  4        R # r   )r7  r;  )r%   shape_infers   &&r   fuse_skip_layer_norm T5OnnxModel.fuse_skip_layer_normL  s    ##))+r   c                x   V P                  4        EF  pVP                  R 8X  g   K  V P                  V. RO. RO4      pVEem   V P                  P                  P
                   Uu. uF  q3P                  NK  	  ppVR,          P
                  ^,          V9   Ed   V P                  RRR7      p\        P                  ! RVR,          P
                  ^,          .VR,           .VR7      p\        P                  ! R\        P                  ^.^.R	7      pV P                  V4       \        P                  ! RVR,           R.VR
,           .V P                  RRR7      ^ R7      pV P                  V4       V P                  V4       VR
,           VP
                  ^&   VR
,           VP
                  ^&    R# 	  R# u upi )r   r   r   NAdded_Shape_r  _OutputrB   Constant_Index_1)r<   r=   r>   r?   _Output_Gather_1Added_Gather_)rC   rD   r<   r8   )
r   r   r   r   r   r   r   r   SimplifiedLayerNormalizationr   )
r7   r   r   r   r7   r   r   r   r   r   rG   )nodesr   r   r   r   r-   r<   rR   r   rZ   rS   r
   INT64rV   add_node)	r%   r   rM  r-   graph_input_namesr$  
shape_node	indices_1r  s	   &        r   adjust_rel_pos_bis_length_input+T5OnnxModel.adjust_rel_pos_bis_length_inputO  s    JJLD||55.. 3" $AEAQAQAWAW(XAWAW%(XRyq)->>$($9$9'~$9$^	%+%5%5#$)"IOOA$6#7%.%:$;!*	&
 %+$6$6!3&1&7&7"#"#	%	 ,,Y7!'!1!1$$-	$9;M#N%.1C%C$D!%!6!6x_!6!]!"" j1f-(14F(F

1(14F(F

1g !( )Ys   &F7c                   . pV P                  4        F  pVP                  R 8X  g   K  V P                  V. RO. RO4      pVf   K3  V P                  VR.^ .4      pVf   KN  V^ ,          pVP                  ^ ,          VP                  ^ &   VP	                  V4       VP                  V4       V P                  V4       K  	  R# )r   Nr   )r   r   r   r   r   LessOrEqualTiler   r   r   r   )r7   r   r7   r   r   r   r   r7   r   r   r   rM  r   r   r.   r]   rX   remove_nodesr%   r   r   extended_mask_nodesr   r*  s   &     r   !remove_extended_mask_decoder_init-T5OnnxModel.remove_extended_mask_decoder_init  s    JJLD||u$&*&<&< 6'#" '. 224:P9QTUSVW	$$Q<%)[[^"&&':;&&t,!!/2? !r   c                   . pV P                  4        F  pVP                  R 8X  g   K  V P                  V. RO. RO4      pVf   K3  V P                  VRR.^ ^ .4      pVf   KP  V^ ,          pVP                  ^ ,          VP                  ^ &   VP	                  V4       VP                  V4       V P                  V4       K  	  R# )r   Nr   r   )r   r   r   r   r   r   rV  rW  r   r   r   r   )r7   r   r7   r   r   r7   r   r   r7   r7   r   r   rX  rZ  s   &     r   remove_extended_mask_decoder(T5OnnxModel.remove_extended_mask_decoder  s    JJLD||u$&*&<&< 9!'#$ '. 224'CY9Z]^`a\bc	$$Q<%)[[^"&&':;&&t,!!/2A !r   c                Z    V P                  4        V P                  P                  4        R # r   )adjust_reshape_and_expandr8  r;  r<  s   &r   
preprocessT5OnnxModel.preprocess  s    &&(r   c                    V P                  4        V P                  4        V P                  4        V P                  4        R # r   )r\  r_  rS  r   r<  s   &r   postprocessT5OnnxModel.postprocess  s2    ..0))+,,.r   )r5  r   r6  r8  r7  r   )T)r   r   r   r   r#   r=  r@  rD  rS  r\  r_  rc  rf  r   r   r   r   s   @@r   r-  r-  6  sA     @ @&',6r!3F"3H  r   r-  )loggingnumpyrO   fusion_attentionr   r   fusion_baser   fusion_simplified_layernormr   r   fusion_utilsr   onnxr	   r
   r   
onnx_modelr   onnx_model_bertr   	getLoggerr   rH   r   r   r-   r   r   <module>rs     sa   
   ;  r $ / /   )			8	$G
% G
%TV f V rc- cr   