
    h]                        S SK r S SKrS SKr\R                  R	                  \5      r\R                  R                  \R                  R                  \S5      5      (       a6  \R                  R                  \R                  R                  \S5      5        O5\R                  R                  \R                  R                  \S5      5        S SK
JrJrJr  \ R                  " \5      r " S S\5      rg)    Nz ../tools/symbolic_shape_infer.pyz../toolsz..)SymbolicShapeInferenceget_shape_from_type_protosympyc                   ^   ^  \ rS rSrS
U 4S jjrSS\\\4   S\4S jjrS r	S r
S rS	rU =r$ )SymbolicShapeInferenceHelper   c                 \   > [         TU ]  X4XR5        Xl        SU l        SU l        0 U l        g )NF)super__init__model_all_shapes_inferred_is_inferred_dynamic_axis_mapping_)selfmodelverboseint_max
auto_mergeguess_output_rank	__class__s         e/var/www/fran/franai/venv/lib/python3.13/site-packages/onnxruntime/transformers/shape_infer_helper.pyr   %SymbolicShapeInferenceHelper.__init__   s0    .?I*/!"'57"    dynamic_axis_mappingmax_runsc                    Uc   eU R                   (       a  U R                  U:X  a  U R                  $ Xl        U R                  U R                  5        SnU R
                  (       aQ  [        R                  SU 35        U R                  5       U l        US-  nUS:  a  X2:  a  OU R
                  (       a  MQ  SU l         U R                  $ )ay  Run shape inference, and try replace dynamic axis from string to integer when mapping is provided.

Args:
    dynamic_axis_mapping (_type_): a dictionary with name of dynamic axis as key, like {"batch_size" : 4}
    max_runs (int, optional): limit maximum number of runs to avoid infinite loop. Defaults to 200.

Returns:
    bool: whether all shapes has been inferred or not.
r   zshape infer run    T)	r   r   r   _preprocessr   run_loggerdebug_infer_impl)r   r   r   counts       r   infer"SymbolicShapeInferenceHelper.infer   s     $///!;!;?S!S,,,%9"%iiLL+E734(,(8(8(:D%QJE!| 1 iii !(((r   c                    / nU R                  X5      nU(       a  U H  n[        U[        5      (       a  XPR                  ;   a   UR	                  U R                  U   5        MG  XPR
                  ;   a   UR	                  U R
                  U   5        Mv  UR	                  [        R                  " USS95        M  Uc   eUR	                  U5        M     U$ )zQOverride it to ensure shape inference by giving the actual value of dynamic axis.T)integer)
_get_shape
isinstancestrr   appendsymbolic_dims_r   Symbol)r   nodeidxsympy_shapeshapedims         r   _get_sympy_shape-SymbolicShapeInferenceHelper._get_sympy_shape<   s    *c3''888#**4+E+Ec+JK 3 33#**4+>+>s+CD#**5<<T+JK?*?&&s+  r   c                 b   U R                   (       d   eXR                  ;  a  [        S[        U5      -   5        gU R                  U   R                  n[        U5      nUbM  [        U5       H>  u  pE[        U[        5      (       d  M  XPR                  ;   d  M-  U R                  U   X4'   M@     U$ )zGet shape of an edge.

Args:
    edge (str): name of edge

Returns:
    Optional[List[int]]: the shape, or None if shape is unknown
zCannot retrieve the shape of N)	r   	known_vi_printr*   typer   	enumerater)   r   )r   edge
type_protor1   ir2   s         r   get_edge_shape+SymbolicShapeInferenceHelper.get_edge_shapeO   s     ((((~~%1CI=>^^D)..
)*5#E*c3''C3M3M,M#99#>EH + r   c                     U R                   (       d   eU R                  U5      nU R                  U5      nUb  Uc  [        S5      eX4:H  $ )zCompare shape of two edges.

Args:
    edge (str): name of edge
    edge_other (str): name of another edge

Raises:
    Exception: At least one shape is missed for edges to compare

Returns:
    bool: whether the shape is same or not
z1At least one shape is missed for edges to compare)r   r=   	Exception)r   r:   
edge_otherr1   shape_others        r   compare_shape*SymbolicShapeInferenceHelper.compare_shapeg   sR     ((((##D)))*5=K/OPP##r   )r   r   r   r   )r   iTF)   )__name__
__module____qualname____firstlineno__r   dictr*   intr$   r3   r=   rC   __static_attributes____classcell__)r   s   @r   r   r      s7    8)$sCx. )C )<&0$ $r   r   )loggingossyspathdirname__file__	file_pathexistsjoinr+   symbolic_shape_inferr   r   r   	getLoggerrF   r    r    r   r   <module>rZ      s     	 
 GGOOH%	77>>"'',,y*LMNNHHOOBGGLLJ78HHOOBGGLLD12 Y Y			8	$c$#9 c$r   