+
    9i'                     \    ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ]! ]4      t	 ! R R]4      t
R# )    )	getLogger)Fusion)helper	OnnxModelc                      a a ] tR t^t oV3R lV 3R lltV3R lR ltV3R lR ltV3R lR ltV3R	 lR
 ltRt	Vt
V ;t# )
FusionGeluc                    < V ^8  d   QhRS[ /# )   modelr   )format__classdict__s   "b/var/www/html/photoedit/myenv/lib/python3.14/site-packages/onnxruntime/transformers/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S[ RS[ /# )r   input_name_to_nodesoutput_name_to_node)dict)r   r   s   "r   r   r      s     H H$ HT Hr   c                    V P                  WV4      '       d   R # V P                  WV4      '       d   R # V P                  WV4       R # )N)fuse_1fuse_2fuse_3)r   erf_noder   r   s   &&&&r   fuseFusionGelu.fuse   s;    ;;x6IJJ;;x6IJJH3FGr   c                :   < V ^8  d   QhRS[ RS[ RS[R,          /# r   r   r   returnNr   bool)r   r   s   "r   r   r      s.     R RD Rt RX\_cXc R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                  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                  P                  VR^ V4      pVf   R# V P                  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                  P	                  V
R4      '       g   R# V
P                   ^ ,          pMlV P                  P                  VRW4      p
V
f   R# V P                  P	                  V
R4      '       g   R# WP                  9  d   R# VP                   ^ ,          pWqWVV
.pV P                  P                  W.W#4      '       g   R# V P                  P                  V4       \        P                  ! R	V.V.V P                  P                  R	4      R
7      pRVn        V P                  P!                  V4       V P"                  V P$                  VP&                  &   V P)                  R	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.
NAddMulDiv-?MbP?delta      ?r   inputsoutputsnamecom.microsoftT)outputlenop_typer   has_constant_inputmatch_parentfind_constant_inputinputis_safe_to_fuse_nodesnodes_to_removeextendr   	make_nodecreate_node_namedomainnodes_to_addappendthis_graph_namenode_name_to_graph_namer7   increase_counter)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   s   ( ??1%88&q'9:x=A!!4!4!= zz,,]A>>"*==&';';A'>?x=A!!4!4!= jj%%hq:MN;::))#vU)CqH1$**1-1E1Ea1HH!a0099*+?+?+BCH8}!Xa[%8%8E%A{H::003??&ooa0Ozz..}eWbH::003??^^3+2215OxPzz//-/B
 
 ##N3%%N+o5FTZZMhMhioMp

 ,
  ,8<8L8L$$Z__5f%r   c                :   < V ^8  d   QhRS[ RS[ RS[R,          /# r'   r)   )r   r   s   "r   r   r   m   s.     K KD Kt KX\_cXc K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                  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                  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                  P                  VR^ V4      pVf   R# Rp	V P                  P                  VRRR7      ^8w  dI   V P                  P                  VR	^V4      p	V	f   R# V P                  P	                  V	R
4      '       g   R# V P                  P                  V^ V4      p
V
f   R# V
P                   ^ ,          VP                  9  d   R# WWVV.pV	'       d   VP                  V	4       V P                  P                  WP                   ^ ,          .W#4      '       g   R# V P                  P                  V4       \        P                  ! RV
P                   ^ ,          .VP                   ^ ,          .V P                  P                  R4      R7      pRVn        V P"                  P                  V4       V P$                  V P&                  VP(                  &   V P+                  R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.
Nr,   r-   r3   r.   r/   r0   r1   Sqrtg       @r   r4   r8   T)r9   r:   r;   r   r<   r=   r>   
get_parentr?   rG   r@   rA   rB   r   rC   rD   rE   rF   rH   rI   r7   rJ   )r   r#   r   r   rK   rL   rM   mulrN   	sqrt_node	root_noderS   rT   s   &&&&         r   r!   FusionGelu.fuse_2m   s    ??1%88&q'9:x=A!!4!4!= zz,,]A>>"*==&';';A'>?x=A!!4!4!= zz,,]C@@"*==&';';A'>?x=A!!4!4!=qkjj%%hq:MN;	::))#vU)CqH

//VQ@STI ::00C@@JJ))#q2EF	Acii/sK!!),zz//ZZ]O-@
 
 ##N3%%I,,Q/03::a=/PTPZPZPkPklrPs

 ,
  ,8<8L8L$$Z__5f%r   c                :   < V ^8  d   QhRS[ RS[ RS[R,          /# r'   r)   )r   r   s   "r   r   r      s.     H HD Ht HX\_cXc H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                  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                  P	                  VR4      '       g   R# V P                  P                  VR^ V4      pVf   R# V P                  P                  VRRR7      pV^ 8  d   R# V P                  P                  Yx^8X  d   ^ M^V4      p	V	f   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	P                   ^ ,          8X  g,   V
P                  ^,          V	P                   ^ ,          8X  g   R# WqWVV
.pV P                  P                  VV
P                   ^ ,          .VV4      '       g   R# V P                  P                  V4       \        P                  ! RV	P                   ^ ,          .V
P                   ^ ,          .V P                  P                  R4      R	7      pR
Vn        V P                   P#                  V4       V P$                  V P&                  VP(                  &   V P+                  R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.
Nr,   r-   r3   g   `?r0   r1   r   r4   r8   T)r9   r:   r;   r   r<   r=   r>   rY   r?   r@   rA   rB   r   rC   rD   rE   rF   rG   rH   rI   r7   rJ   )r   r#   r   r   rK   rL   rQ   	first_mulir\   last_mulrS   rT   s   &&&&         r   r"   FusionGelu.fuse_3   s    ??1%88&q'9:x=A!!4!4!= zz,,]A>>"*==&';';A'>?x=A!!4!4!=A;zz,,Xs;;JJ++HeQ@ST	JJ**96HPU*Vq5JJ)))q&QaI\]	??1%88&q'9:x=A!!4!4!=A;q!Y%5%5a%88HNN1<MQZQaQabcQd<d#}Qzz//__Q 	
 
 ##N3%%I,,Q/08??1;M:NUYU_U_UpUpqwUx

 ,
  ,8<8L8L$$Z__5f%r    )__name__
__module____qualname____firstlineno__r   r$   r    r!   r"   __static_attributes____classdictcell____classcell__)r   r   s   @@r   r	   r	      sG     / /H HR RhK KZH H Hr   r	   N)loggingr   fusion_baser   onnxr   
onnx_modelr   re   loggerr	   rd   r   r   <module>rq      s+   
     	8	t tr   