+
    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)NumpyHelper	OnnxModelc                   \   a a ] tR t^t oV3R lV 3R lltV 3R ltR tR tR tRt	Vt
V ;t# )FusionConstantFoldc                    < V ^8  d   QhRS[ /# )   modelr   )format__classdict__s   "k/var/www/html/photoedit/myenv/lib/python3.14/site-packages/onnxruntime/transformers/fusion_constant_fold.py__annotate__FusionConstantFold.__annotate__   s      i     c                :   < \         SV `  VR R.4       ^ V n        R# ) 	TransposeN)super__init__count)selfr   	__class__s   &&r   r   FusionConstantFold.__init__   s    [M2
r   c                   < \         SV `  4        V P                  ^ 8  d%   \        P	                  RV P                   24       R# R# )r   zConstant Folded: N)r   applyr   loggerinfo)r   r   s   &r   r   FusionConstantFold.apply   s4    ::>KK+DJJ<89 r   c                N    V P                  WV4       V P                  WV4       R# )zH
Apply multiple fusions on Transpose nodes that can be constant folded.
N)fuse_1fuse_2)r   nodeinput_name_to_nodesoutput_name_to_nodes   &&&&r   fuseFusionConstantFold.fuse   s"     	D/BCD/BCr   c                   \        VP                  4      ^8w  g   \        VP                  4      ^8w  d   \        P	                  R4       R# V P
                  P                  VP                  ^ ,          4      pVf   \        P	                  R4       R# RpW!P                  ^ ,          ,           F2  pVP                  R8X  d   \        VP                  4      ^8X  d   K0  Rp M	  V'       d   \        P	                  R4       R# W!P                  ^ ,          ,           F+  pVP                  R8X  d   K  VP                  R	8X  d   K)  Rp M	  V'       d   \        P	                  R
4       R# \        P                  ! V4      p\        VP                  4      ^8w  d   \        P	                  R4       R# VP                  pVP                  p	V P                  V4       V P                  VV	VP                  ^,          VP                  ^ ,          .VP                  R7       W!P                  ^ ,          ,           F  p\!        \        VP                  4      4       F  p
VP                  V
,          VP                  ^ ,          8X  g   K.  VP                  ^ ,          VP                  V
&   VP                  R8X  g   Ka  V
^ 8X  g
   V
^8X  g   Kq  V
^ 8X  d   RMRp\#        VP$                  4       F0  w  rVP                  V8X  g   K  ^ VP$                  V,          n        K2  	  K  	  K  	  V P(                  P+                  V4       V ;P,                  ^,          un        R# )z
Constant fold any initializer data representing a MatMul's
weights that are stored in a Transpose op

Ex: Transpose --> Gemm or Transpose --> MatMul
:fuse_constant_fold: node has more than one input or outputNz8fuse_constant_fold: failed to identify initializer inputFr   TzAfuse_constant_fold: other non-Transpose nodes use the initializerGemmMatMulzOfuse_constant_fold: other non-Gemm and non-MatMul nodes use the transposed dataz7fuse_constant_fold: shape of initializer data is not 2D)name	data_typedimsvalstransAtransB)leninputoutputr   debugr   get_initializerop_typer   to_arrayshaper-   r.   remove_initializeradd_initializerTrange	enumerate	attributeinodes_to_removeappendr   )r   r$   r%   r&   protoskip
child_nodeweightr-   dtyperA   keyjattr_keys   &&&&          r   r"   FusionConstantFold.fuse_1    s    tzz?a3t{{#3q#8LLUV 

**4::a=9=LLST -jjm<<J&&+5#djj/Q:N = LL\] .kk!n==J&&&0J4F4F(4R > LLjk %%e,v||!LLRS zz&,,q/6<<?3	 	 	
 .kk!n==J3z//01##A&$++a.8*.**Q-J$$Q'!))V3a16*+q&hh+4Z5I5I+JKA'}}3<=
 4 4Q 7 9 ,K 2 > 	##D)

a
r   c                   \        VP                  4      ^8w  g   \        VP                  4      ^8w  d   \        P	                  R4       R# V P
                  P                  VR^ 4      pVf   \        P	                  R4       R# \        VP                  4      ^8w  g   \        VP                  4      ^8w  d   \        P	                  R4       R# VP                  ^ ,          P                  pVP                  ^ ,          P                  pWV8w  d   \        P	                  R4       R# VP                  ^ ,          pW!P                  ^ ,          ,          pV FH  p	\        V	P                  4       F,  w  rWP                  ^ ,          8X  g   K  WyP                  V
&   K.  	  KJ  	  V P                  P                  V4       V P                  P                  V4       V ;P                  ^,          un        R# )z
Constant fold any Transpose --> Transpose ops since the root input
is the final result

Ex: root_input --> Transpose --> Transpose --> next_node to root_input --> next_node
r*   Nr   z<fuse_constant_fold: failed to identify parent Transpose nodezAfuse_constant_fold: parent node has more than one input or outputz@fuse_constant_fold: Transpose node permutations aren't identical)r3   r4   r5   r   r6   r   match_parentr@   intsr?   rB   rC   r   )r   r$   r%   r&   parent_node	node_permparent_node_perm
root_inputoutput_nodesoutput_noderA   input_s   &&&&        r   r#   FusionConstantFold.fuse_2h   sp    tzz?a3t{{#3q#8LLUV jj--dKCLLWX{  !Q&#k.@.@*AQ*FLL\]NN1%**	&00388(LL[\ !&&q)
*;;q>:'K&{'8'89	[[^++5%%a( : ( 	##D)##K0

a
r   )r   )__name__
__module____qualname____firstlineno__r   r   r'   r"   r#   __static_attributes____classdictcell____classcell__)r   r   s   @@r   r	   r	      s+      :
DFP( (r   r	   N)loggingr   fusion_baser   fusion_utilsr   
onnx_modelr   rX   r   r	    r   r   <module>rd      s+      $  	8	A Ar   