
    zbj                     @   % 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  SrSr\S-  \S'   \ R(                  " \5      r " S	 S
\5      rg! \ a  r\rSrSrSr\r SrCN3SrCff = f)    Nz ../tools/symbolic_shape_infer.pyz../toolsz..)SymbolicShapeInferenceget_shape_from_type_protosympyT"_symbolic_shape_infer_import_errorFc                   ^   ^  \ 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                    > [         (       d/  [        nUb  S[        U5      ;   a  SOSU< 3n[        SU 35      Ue[        TU ]  X4XR5        Xl        SU l        SU l        0 U l	        g )Nr   z1missing 'sympy' (install with: pip install sympy)z'failed to import symbolic_shape_infer: u0   SymbolicShapeInferenceHelper is unavailable — F)
_symbolic_shape_infer_availabler   strImportErrorsuper__init__model_all_shapes_inferred_is_inferred_dynamic_axis_mapping_)	selfmodelverboseint_max
auto_mergeguess_output_rankerrcause	__class__s	           ڧ/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/stt/lib/python3.13/site-packages/onnxruntime/transformers/shape_infer_helper.pyr   %SymbolicShapeInferenceHelper.__init__!   s|    ..4C ?w#c(': D>sgF 
  PQVPWXY_bb.?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.infer0   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
isinstancer   r   appendsymbolic_dims_r   Symbol)r   nodeidxsympy_shapeshapedims         r   _get_sympy_shape-SymbolicShapeInferenceHelper._get_sympy_shapeN   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_protor6   ir7   s         r   get_edge_shape+SymbolicShapeInferenceHelper.get_edge_shapea   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   rB   	Exception)r   r?   
edge_otherr6   shape_others        r   compare_shape*SymbolicShapeInferenceHelper.compare_shapey   sR     ((((##D)))*5=K/OPP##r   )r   r   r   r   )r   iTF)   )__name__
__module____qualname____firstlineno__r   dictr   intr*   r8   rB   rH   __static_attributes____classcell__)r   s   @r   r   r       s7    8)$sCx. )C )<&0$ $r   r   )loggingossyspathdirname__file__	file_pathexistsjoinr0   symbolic_shape_inferr   r   r   r   r   r   __annotations__excobject	getLoggerrK   r&   r    r   r   <module>rb      s     	 
 GGOOH%	77>>"'',,y*LMNNHHOOBGGLLJ78HHOOBGGLLD12
-]]&*#=A&d(:A 
		8	$k$#9 k$  -# $E&+#),&-s   D D	
DD