
    hV                     f    S SK Jr  S SKrS SKJr  S SKJrJr  S SK	J
r
  \" \5      r " S S\5      rg)    )	getLoggerN)Fusion)TensorProtohelper)	OnnxModelc                   <   ^  \ rS rSrS\4U 4S jjrS rS rSrU =r	$ )FusionReshape   modelc                 6   > [         TU ]  USS5        SU l        g )NReshapeF)super__init__prune_graph)selfr   	__class__s     a/var/www/fran/franai/venv/lib/python3.13/site-packages/onnxruntime/transformers/fusion_reshape.pyr   FusionReshape.__init__   s    	95!&    c                 2   [         R                  " U[         R                  S9nU R                  R	                  SS5      n[
        R                  " S/ U/[
        R                  " S[        R                  UR                  [        U5      SS9S9nXRR                  S'   U R                  R	                  S	S
5      Ul        U R                  R                  U/5        U R                   R#                  U5        U R$                  U R&                  UR                  '   g )N)dtypeConstantconstant_shapeconst_tensorT)name	data_typedimsvalsraw)inputsoutputsvalue   r   Reshape_Fuse)npasarrayint64r   create_node_namer   	make_nodemake_tensorr   INT64shapebytesinputr   nodes_to_removeextendnodes_to_addappendthis_graph_namenode_name_to_graph_name)r   r,   reshape_nodeconcat_nodeshape_valueconstant_shape_namenew_nodes          r   replace_reshape_node"FusionReshape.replace_reshape_node   s    jjbhh7"jj99*FVW##()$$#%++ &&;'	
 !41 JJ77	>R##[M2  *6:6J6J$$X]]3r   c                 "	   UR                   S   U;  a  g X1R                   S      nUR                  S:w  d2  [        UR                   5      S:  d  [        UR                   5      S:  a  g U R                  R	                  U/ SQ/ SQU5      nUc  g Uu  pgnU R                  R	                  U/ SQ/ SQU5      n	U	c  g U	u  pn/ nU R                  R                  UR                   S   5      nUS:X  a  UR                  S5        U R                  R                  UR                   S   5      nUS:X  a  UR                  S5        [        U5      S	:w  a  g / n/ nX/n[        UR                   5      S:X  a  U R                  R                  UR                   S	   5      c  U R                  R	                  U/ S
Q/ SQU5      nUc&  U R                  R	                  U/ SQ/ SQU5      nUc  g U R                  R	                  U/ S
Q/ SQU5      nUc&  U R                  R	                  U/ SQ/ SQU5      nUc  g UR                  US   US   /5        UR                  S5        O[        UR                   5      S	:  a|  U R                  R                  UR                   S	   5      nUc  g [        U[        R                  5      (       a   UR                  UR                  5       5        OUR                  U5        [        UR                   5      S:X  a  U R                  R                  UR                   S   5      cy  SU;   a  g U R                  R	                  U/ SQ/ SQU5      nUc&  U R                  R	                  U/ SQ/ SQU5      nUc  g UR                  US   /5        UR                  S5        O[        UR                   5      S:  a|  U R                  R                  UR                   S   5      nUc  g [        U[        R                  5      (       a   UR                  UR                  5       5        OUR                  U5        UR                   S   nSnU H  nUR                   S   U:w  d  M  SnM     U(       d  g U R                  XU5        SU l        g )Nr#   Concat      )	UnsqueezeGatherShape)r   r   r   )r#   r   r   r      )r@   MulrA   rB   )rC   r   r   r   )r@   rD   SqueezeSlicerB   )rC   r   r   r   r   )rC   r   r#   r   )rC   r   r#   r   r   )r@   DivrA   rB   )r>   r   r   r   )r@   rH   rE   rF   rB   )r>   r   r   r   r   TF)r.   op_typelenr   match_parent_pathget_constant_valuer2   r0   
isinstancer%   ndarraytolistr:   r   )r   r5   input_name_to_nodesoutput_name_to_noder6   path0unsqueeze_0gather_0shape_0path1unsqueeze_1gather_1shape_1r,   gather_valuepath2path3shape_nodesconcat_value
root_inputsame_shape_input
shape_nodes                         r   fuseFusionReshape.fuse*   s/   a (;;)*<*<Q*?@(*c+2C2C.Dq.HCP[PaPaLbefLf

,,,	
 =+0(

,,,	
 =+0(zz44X^^A5FG1LLOzz44X^^A5FG1LLOu:?({  !Q&4::+H+HIZIZ[\I]+^+fJJ007#	E }

44E#'	 =JJ007#	E }

44E#'	 =b	5956LL""#a'::889J9J19MNL#,

33\0023\*{  !Q&4::+H+HIZIZ[\I]+^+fU{JJ007#	E }

44E#'	 =b	{+LL""#a'::889J9J19MNL#,

33\0023\*!''*
%J"j0#(  &  !!%{C  r   )r   )
__name__
__module____qualname____firstlineno__r   r   r:   rb   __static_attributes____classcell__)r   s   @r   r	   r	      s!    'i 'K*C  C r   r	   )loggingr   numpyr%   fusion_baser   onnxr   r   
onnx_modelr   rd   loggerr	    r   r   <module>rq      s.       $  	8	] F ] r   