Ë
    cQêjŸ  ã                   ó4  — U d dl Z d dlZd dlZej                  j	                  e«      Zej                  j                  ej                  j                  ed«      «      r6ej                  j                  ej                  j                  ed«      «       n5ej                  j                  ej                  j                  ed«      «       	 d dl
mZmZmZ dZdZedz  ed<    e j(                  e«      Z G d	„ d
e«      Zy# e$ rZeZdZdZdZeZY dZ[Œ2dZ[ww xY w)é    Nz ../tools/symbolic_shape_infer.pyz../toolsz..)ÚSymbolicShapeInferenceÚget_shape_from_type_protoÚsympyTÚ"_symbolic_shape_infer_import_errorFc                   óN   ‡ — e Zd Zdˆ fd„	Zd	deeef   defd„Zd„ Zd„ Z	d„ Z
ˆ xZS )
ÚSymbolicShapeInferenceHelperc                 óÄ   •— t         s+t        }|�dt        |«      v rdnd|›�}t        d|› �«      |‚t        ‰| �  ||||«       || _        d| _        d| _        i | _	        y )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	           €úp/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/onnxruntime/transformers/shape_infer_helper.pyr   z%SymbolicShapeInferenceHelper.__init__!   s   ø€ Ý.Ü4ˆCð �? w´#°c³(Ñ':ñ Dà>¸s¸gÐFð ô
 Ð PÐQVÐPWÐXÓYÐ_bÐbÜ‰Ñ˜ *Ð.?ÀÔIØˆŒØ*/ˆÔ!Ø"'ˆÔØ57ˆÕ"ó    Údynamic_axis_mappingÚmax_runsc                 ór  — |€J ‚| j                   r| j                  |k(  r| j                  S || _        | j                  | j                  «       d}| j
                  rJt        j                  d|› �«       | j                  «       | _        |dz  }|dkD  r||k\  rn| j
                  rŒJd| _         | j                  S )a©  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   Úinferz"SymbolicShapeInferenceHelper.infer0   s·   € ð $Ð/Ð/Ð/à×Ò ×!;Ñ!;Ð?SÒ!SØ×,Ñ,Ð,à%9ˆÔ"à×Ñ˜Ÿ™Ô%àˆØ�iŠiÜ�L‰LÐ+¨E¨7Ð3Ô4Ø(,×(8Ñ(8Ó(:ˆDÔ%Ø�Q‰JˆEØ˜!Š| ¨Ò 1Øð �i‹ið !ˆÔØ×(Ñ(Ð(r   c                 óŒ  — g }| j                  ||«      }|r­|D ]¨  }t        |t        «      r�|| j                  v r|j	                  | j                  |   «       Œ@|| j
                  v r|j	                  | j
                  |   «       Œm|j	                  t        j                  |d¬«      «       Œ”|€J ‚|j	                  |«       Œª |S )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_shapez-SymbolicShapeInferenceHelper._get_sympy_shapeN   sº   € àˆà—‘  cÓ*ˆÙØò 
,�Ü˜c¤3Ô'Ø˜d×8Ñ8Ñ8Ø#×*Ñ*¨4×+EÑ+EÀcÑ+JÕKØ × 3Ñ 3Ñ3Ø#×*Ñ*¨4×+>Ñ+>¸sÑ+CÕDà#×*Ñ*¬5¯<©<¸ÀTÔ+JÕKà˜?Ð*˜?Ø×&Ñ& sÕ+ð
,ð Ðr   c                 óD  — | j                   sJ ‚|| j                  vrt        dt        |«      z   «       y| j                  |   j                  }t        |«      }|�Et        |«      D ]7  \  }}t        |t        «      sŒ|| j                  v sŒ&| j                  |   ||<   Œ9 |S )z¬Get 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_protor3   Úir4   s         r   Úget_edge_shapez+SymbolicShapeInferenceHelper.get_edge_shapea   s¢   € ð ×(Ò(Ð(Ð(Ø�t—~‘~Ñ%ÜÐ1´C¸³IÑ=Ô>Øà—^‘^ DÑ)×.Ñ.ˆ
Ü)¨*Ó5ˆàÐÜ# EÓ*ò ?‘��3Ü˜c¤3Õ'¨C°4×3MÑ3MÒ,MØ#×9Ñ9¸#Ñ>�E˜!’Hð?ð ˆr   c                 óŠ   — | j                   sJ ‚| j                  |«      }| j                  |«      }|�|€t        d«      ‚||k(  S )a*  Compare 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_otherr3   Úshape_others        r   Úcompare_shapez*SymbolicShapeInferenceHelper.compare_shapey   sT   € ð ×(Ò(Ð(Ð(Ø×#Ñ# DÓ)ˆØ×)Ñ)¨*Ó5ˆØˆ=˜KÐ/ÜÐOÓPÐPØ˜Ñ#Ð#r   )r   iÿÿÿTF)éÈ   )Ú__name__Ú
__module__Ú__qualname__r   Údictr   Úintr(   r5   r>   rC   Ú__classcell__)r   s   @r   r   r       s2   ø„ õ8ñ)¨$¨s°C¨x©.ð )ÀCó )ò<ò&ö0$r   r   )ÚloggingÚosÚsysÚpathÚdirnameÚ__file__Ú	file_pathÚexistsÚjoinr-   Úsymbolic_shape_inferr   r   r   r
   r   r   Ú__annotations__ÚexcÚobjectÚ	getLoggerrE   r$   r   © r   r   ú<module>rZ      sõ   ðô Û 	Û 
ð �G‰G�O‰O˜HÓ%€	Ø‡7�7‡>�>�"—'‘'—,‘,˜yÐ*LÓMÔNØ‡H�H‡O�O�B—G‘G—L‘L ¨JÓ7Õ8à‡H�H‡O�O�B—G‘G—L‘L ¨DÓ1Ô2ð
-ß]Ñ]à&*Ð#Ø=AÐ&¨°dÑ(:ÓAð 
ˆ×	Ñ	˜8Ó	$€ôk$Ð#9õ k$øð ò -Ø#ÐØ $ÐØ€EØ&+Ð#Ø),Õ&ûð-ús   Ã
C> Ã>DÄ
DÄD