+
    9ip                    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tV ;t# )FusionLayerNormalizationc                   V ^8  d   QhRR/# )   modelr    )formats   "o/var/www/html/photoedit/myenv/lib/python3.14/site-packages/onnxruntime/quantization/fusions/fusion_layernorm.py__annotate__%FusionLayerNormalization.__annotate__   s     D Di D    c                	*   < \         SV `  VR R4       R# )LayerNormalization
ReduceMeanN)super__init__)selfr
   	__class__s   &&r   r   !FusionLayerNormalization.__init__   s     4lCr   c               $    V ^8  d   QhRRRRRR/# )r	   reduce_mean_nodezonnx.NodeProtoinput_name_to_nodeszdict[str, list[onnx.NodeProto]]output_name_to_nodezdict[str, onnx.NodeProto]r   )r   s   "r   r   r      s-     @1 @1(@1 =@1 7	@1r   c           	     ^   V P                   P                  W4      p\        V4      ^ 8X  g   \        V4      ^8  d   R# VP                  ^ ,          pV^ ,          P                  R8w  g    V^ ,          P                  ^ ,          V8w  d   R# \        V4      ^8X  d:   V^,          P                  R8w  g    V^,          P                  ^ ,          V8w  d   R# RpV F  pV P                  VRVRR7      pVf   K   M	  Vf   R# V P                  V. RO. RO3. RO. RO3. RO. RO3. RO. RO3.V4      w  rp
V^ 8  d   R# V	R,          pW9  d   R# V	^,          pV P                  V4      w  rVe   V^ 8:  g   VR	8  d   R# V	^,          pVP                  R8X  d   V P                  VR
4      ^8w  d   R# VP                  R8X  d,   VP                  ^ ,          VP                  ^,          8w  d   R# W&P                  ^ ,          ,          ^ ,          pVP                  R8w  d   R# VVP                  ^ ,          ,          ^ ,          pVP                  R8w  d   R# V.pVP                  V4       VP                  V	RR 4       VP                  VVV.4       V P                  VVP                  VV4      '       g   R# VP                  ^V P                  VP                  ^ ,          V4      ,
          ,          pV P                  V^4      '       g   R# VP                  ^V P                  VP                  ^ ,          V4      ,
          ,          pV P                  V^4      '       g   R# V P                  P                  V4       \        P                   P#                  RV P%                  4       VP                  ^ ,          VV.VP                  ^ ,          .R7      pVP&                  P                  \        P                   P)                  R\+        V4      4      .4       V P,                  P/                  V4       R# )aT  
Interface function that tries to fuse a node sequence containing a ReduceMean node into a single
LayerNormalization node.

      +----------------------+
      |                      |
      |                      v
  [Root] --> ReduceMean -->  Sub  --> Pow --> ReduceMean --> Add --> Sqrt --> Div --> Mul --> Add
             (axis=2 or -1)  |      (Y=2)   (axis=2 or -1)  (E-6 or E-12 or 0) ^
                             |                                                 |
                             +-------------------------------------------------+

 Or, using Mul instead of Pow:

      +----------------------+
      |                      |
      |                      v
  [Root] --> ReduceMean -->  Sub  --> Mul --> ReduceMean --> Add --> Sqrt --> Div --> Mul --> Add
             (axis=2 or -1)  |     (in0=in1)   (axis=2 or -1)  (E-6 or E-12 or 0) ^
                             |                                                 |
                             +-------------------------------------------------+

 It also handles cases of duplicated sub nodes exported from older version of PyTorch:

      +----------------------+
      |                      v
      |           +-------> Sub-----------------------------------------------+
      |           |                                                           |
      |           |                                                           v
  [Root] --> ReduceMean -->  Sub  --> (Pow or Mul) --> ReduceMean --> Add --> Sqrt --> Div  --> Mul --> Add
      |                      ^
      |                      |
      +----------------------+
NSubDivF)	recursiveAddPowMulg-C6?g       @r   )nameinputsoutputsepsilon)Sqrtr!   r   r"   r   )   r   r   r   r   )r(   r!   r   r"   Castr   )r)   r   r   r   r   r   )r(   r!   r   r#   r   )r(   r!   r   r#   r*   r   )r
   get_childrenleninputop_typefind_first_child_by_typematch_parent_pathsget_constant_inputfind_constant_inputoutputextendis_safe_to_fuse_nodesinput_indexis_constant_with_specified_ranknodes_to_removeonnxhelper	make_nodecreate_unique_node_name	attributemake_attributefloatnodes_to_addappend)r   r   r   r   children
root_inputdiv_nodechildpath_idparent_nodes_sub_nodesecond_add_nodei
add_weightpow_or_mul_nodemul_nodelast_add_nodesubgraph_nodesweight_input
bias_inputnormalize_nodes   &&&&                  r   fuseFusionLayerNormalization.fuse   s   P ::**+;Qx=AX!2%++A.
A;%'8A;+<+<Q+?:+Mx=A{""e+x{/@/@/Cz/QE44UECVbg4hH#  #'#:#:<oNDFXY<oNDFXY	  	$
 q Q;##&q///@qJ4G&q/""e+0H0HZ]0^bc0c$$-/2G2G2JoNcNcdeNf2f&q'9:1=u$+HOOA,>?B  E)*+h'l3B/0}hAB))  	
 
 ~~a$*:*:8??1;Mx*X&XY33L!DD"((T-=-=hooa>PR_-`)`a
33JBB##N3.. --/$**1-|ZH"))!,-	 / 
 	  '')C)CIuU_O`)a(bc  0r   r   )__name__
__module____qualname____firstlineno__r   rU   __static_attributes____classcell__)r   s   @r   r   r      s    D D@1 @1r   r   )
__future__r   r:   
onnx_modelr   fusionr   r   r   r   r   <module>r`      s!    #  " D1v D1r   