+
    9i(                    H    ^ RI Ht ^ RIt^RIHt ^RIHt  ! R R]4      tR# )    )annotationsN)	ONNXModel)Fusionc                  ^   a  ] tR t^tR V 3R lltR R ltR R ltR R ltR	 R
 ltRt	V ;t
# )
FusionGeluc                   V ^8  d   QhRR/# )   modelr    )formats   "j/var/www/html/photoedit/myenv/lib/python3.14/site-packages/onnxruntime/quantization/fusions/fusion_gelu.py__annotate__FusionGelu.__annotate__   s     / /i /    c                	*   < \         SV `  VR R4       R# )GeluErfN)super__init__)selfr
   	__class__s   &&r   r   FusionGelu.__init__   s    .r   c               $    V ^8  d   QhRRRRRR/# )r	   erf_nodeonnx.NodeProtoinput_name_to_nodesdict[str, list[onnx.NodeProto]]output_name_to_nodedict[str, onnx.NodeProto]r   )r   s   "r   r   r      s(     < < < =< 7	<r   c                    V P                  WV4      '       g1   V P                  WV4      '       g   V P                  WV4      '       d   V P                  P	                  R^4       R# R# )zg
Interface function that tries to fuse a node sequence containing an Erf node into a single
Gelu node.
com.microsoftN)fuse_1fuse_2fuse_3r
   set_opset_import)r   r   r   r   s   &&&&r   fuseFusionGelu.fuse   sT     KK7JKK{{8:MNN{{8:MNNJJ''; Or   c               (    V ^8  d   QhRRRRRRRR/# 	r	   r   r   r   r   r   r   returnboolr   )r   s   "r   r   r   #   s8     U U U =U 7	U
 
Ur   c                   VP                   ^ ,          V9  d   R# W!P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P                  V^4      '       g   R# VP                   ^ ,          V9  d   R# W%P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P	                  VR^ V4      pVf   R# V P                  VRRR7      ^8w  d   R# VP                  ^ ,          pVP                  ^ ,          VP                   ^ ,          8X  d   ^M^ p	WP                  V	,          8X  d{   W&P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          p
V P                  V
R4      '       g   R# V
P                   ^ ,          pMXV P	                  VRW4      p
V
f   R# V P                  V
R4      '       g   R# WP                  9  d   R# VP                   ^ ,          pWqWVV
.pV P                  W.W#4      '       g   R# V P                  P                  V4       \        P                  P                  R	V P                  4       V.V.R
7      pRVn        V P                  P!                  V4       R# )a  
This pattern is from PyTorch model
Fuse Gelu with Erf into one node:
Pattern 1:
               +-------Mul(0.5)---------------------+
               |                                    |
               |                                    v
            [root] --> Div -----> Erf  --> Add --> Mul -->
                      (B=1.4142...)       (1)

Pattern 2:
               +------------------------------------+
               |                                    |
               |                                    v
            [root] --> Div -----> Erf  --> Add --> Mul -->Mul -->
                      (B=1.4142...)       (1)            (0.5)

Note that constant input for Add and Mul could be first or second input: like either A=0.5 or B=0.5 is fine.
FAddMulDiv-?MbP?delta      ?r   nameinputsoutputsr!   Toutputlenop_typehas_constant_inputmatch_parentfind_constant_inputinputis_safe_to_fuse_nodesnodes_to_removeextendonnxhelper	make_nodecreate_unique_node_namedomainnodes_to_addappend)r   r   r   r   childrenadd_after_erfmul_after_erfdivsubgraph_inputanothermul_halfsubgraph_outputsubgraph_nodes
fused_nodes   &&&&          r   r"   FusionGelu.fuse_1#   sw   2 ??1%88&q'9:x=A!!4!4!= &&}a88"*==&';';A'>?x=A!!4!4!= %4GH;##Cu#=B1$**1-1E1Ea1HH!a0099*+?+?+BCH8}!Xa[%8%8E%A{H**8S99&ooa0O((w\H**8S99^^3+2215OxP)).:KM`vv##N3[[**557@P[jZk + 

 ,
  ,r   c               (    V ^8  d   QhRRRRRRRR/# r)   r   )r   s   "r   r   r   z   8     J J J =J 7	J
 
Jr   c                   VP                   ^ ,          V9  d   R# W!P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P                  V^4      '       g   R# VP                   ^ ,          V9  d   R# W%P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P                  VR4      '       g   R# VP                   ^ ,          V9  d   R# W&P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P	                  VR^ V4      pVf   R# Rp	V P                  VRRR	7      ^8w  d5   V P	                  VR
^V4      p	V	f   R# V P                  V	R4      '       g   R# VP                  ^ ,          p
WP                  9  d   R# WWVV.pV	'       d   VP                  V	4       V P                  WP                   ^ ,          .W#4      '       g   R# V P                  P                  V4       \        P                  P                  RV P                  4       V
.VP                   ^ ,          .R7      pRVn        V P                   P                  V4       R# )a  
This pattern is from Keras model
Fuse Gelu with Erf into one node:
               +------------------------------------------+
               |                                          |
               |                                          v
            [root] --> Div -----> Erf  --> Add --> Mul -->Mul
                      (B=1.4142...)       (A=1)   (A=0.5)

Note that constant input for Add and Mul could be first or second input: like either A=0.5 or B=0.5 is fine.
Fr-   r.   r4   r/   Nr0   r1   r2   Sqrtg       @r   r5   r!   T)r:   r;   r<   r=   r>   r?   r@   rJ   rA   rB   rC   rD   rE   rF   rG   rH   rI   )r   r   r   r   rK   rL   rM   mulrN   	sqrt_noderO   rS   rT   s   &&&&         r   r#   FusionGelu.fuse_2z   sd   " ??1%88&q'9:x=A!!4!4!= &&}a88"*==&';';A'>?x=A!!4!4!= &&}c::"*==&';';A'>?x=A!!4!4!=qk%4GH;	##Cu#=B))#vq:MNI **9c::1*sK!!),)).::a=/K^tt##N3[[**557@P[^[e[efg[hZi + 

 ,
  ,r   c               (    V ^8  d   QhRRRRRRRR/# r)   r   )r   s   "r   r   r      rW   r   c                D   VP                   ^ ,          V9  d   R# W!P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P                  V^4      '       g   R# VP                   ^ ,          V9  d   R# W%P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pV P                  VR4      '       g   R# V P	                  VR^ V4      pVf   R# V P                  VRRR7      pV^ 8  d   R# ^V,
          p	VP                  V	,          p
VP                   ^ ,          V9  d   R# W&P                   ^ ,          ,          p\        V4      ^8w  g   V^ ,          P                  R8w  d   R# V^ ,          pVP                  ^ ,          V
8X  g   VP                  ^,          V
8X  g   R# WqWVV.pV P                  VVP                   ^ ,          .VV4      '       g   R# V P                  P                  V4       \        P                  P                  RV P                  4       V
.VP                   ^ ,          .R	7      pR
Vn        V P                  P!                  V4       R# )a  
This pattern is from TensorFlow model
Fuse Gelu with Erf into one node:
               +----------------------------------------------+
               |                                              |
               |                                              v
            [root] --> Mul -----> Erf    -->   Add --> Mul -->Mul
                       (A=0.7071067690849304)  (B=1)  (B=0.5)

Note that constant input for Add and Mul could be first or second input: like either A=0.5 or B=0.5 is fine.
Fr-   r.   r4   g   `?r1   r2   r   r5   r!   Tr9   )r   r   r   r   rK   rL   rQ   	first_muliroot_input_indexrO   last_mulrS   rT   s   &&&&          r   r$   FusionGelu.fuse_3   sO   $ ??1%88&q'9:x=A!!4!4!= &&}a88"*==&';';A'>?x=A!!4!4!=A;&&x55%%hq:MN	$$Y0B%$Pq5q5")9:??1%88&q'9:x=A!!4!4!=A;q!^3x~~a7HN7Z#}Q))__Q 	
 
 ##N3[[**557@P[c[j[jkl[mZn + 

 ,
  ,r   r   )__name__
__module____qualname____firstlineno__r   r&   r"   r#   r$   __static_attributes____classcell__)r   s   @r   r   r      s,    / /<"UnJXJ Jr   r   )
__future__r   rD   
onnx_modelr   fusionr   r   r   r   r   <module>rm      s!    #  " B Br   