+
    G-jÞ
 ã                   óÊ   € ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
HtHtHtHtHtHtHtHtHt ^ RIHtHt ^ RIHt ]P2                  ! ]4      t ! R R	4      tR# )
é    N)Údeque)ÚPath)Úconvert_float_to_float16)	ÚAttributeProtoÚ
GraphProtoÚ
ModelProtoÚ	NodeProtoÚTensorProtoÚValueInfoProtoÚhelperÚnumpy_helperÚ
save_model)Úload_external_data_for_tensorÚuses_external_data)ÚSymbolicShapeInferenceHelperc                   óz  a € ] tR t^t o R tR tR t/ R3R ltR`R ltR`R lt	R t
R	 tR
 tR tR tR tR tR tR tR tR tRaR ltRaR ltRaR ltRaR lt]R 4       tR t]R 4       tR tR tR tRbR lt RaR lt!RaR  lt". 3R! lt#RR. R3R" lt$R# t%R$ t&RcR% lt'RdR& lt(RR. 3V 3R' lR( llt)RdR) lt*R* t+R+ t,ReR, lt-R- t.ReR. lt/RaR/ lt0R0 t1RaV 3R1 lR2 llt2RaV 3R3 lR4 llt3]V 3R5 lR6 l4       t4R7 t5R8 t6RfR9 lt7RfR: lt8RaR; lt9R< t:R= t;RaR> lt<R`R? lt=]R@ 4       t>RA t?RB t@RC tARdRD ltBRgRE ltCRF tD]R`RG l4       tERgRH ltF]RhRI l4       tGRhRJ ltHRK tIRL tJR`RM ltK]RiV 3RN lRO ll4       tL]RjV 3RP lRQ ll4       tMRR tNV 3RS lRT ltOV 3RU lRV ltPRW tQRX tRV 3RY lRZ ltSV 3R[ lR\ ltTV 3R] lR^ ltUR_tVV tWR# )kÚ	OnnxModelc                ó(   € V P                  V4       R # ©N)Ú
initialize©ÚselfÚmodels   &&Út/Volumes/fast/ai/experiments/nudenet-smoke/.venv/lib/python3.14/site-packages/onnxruntime/transformers/onnx_model.pyÚ__init__ÚOnnxModel.__init__    s   € Ø�‰˜Öó    c                óf   € Wn         / V n        R V n        RV n        R V n        R V n        R V n        R # ©NT)r   Ú_node_name_suffixÚshape_infer_helperÚenable_shape_inferÚ
all_graphsÚ_dtype_dictÚ_shape_dictr   s   &&r   r   ÚOnnxModel.initialize#   s8   € Ø!&Œ
Ø13ˆÔØ@DˆÔØ(,ˆÔØ37ˆŒð
 37ˆÔØ37ˆÖr   c                ó   € R V n         R# )FN)r"   ©r   s   &r   Údisable_shape_inferenceÚ!OnnxModel.disable_shape_inference0   s
   € Ø"'ˆÖr   Fc                ój  € V P                   '       db   V P                  e	   V'       d   \        V P                  4      V n         V P                  P	                  V4      '       d   V P                  #  R # R #   \
         d2    RT n         \        R\        P                  ! 4       ^ ,          4        R # i ; i)NFzfailed in shape inference)	r"   r!   r   r   ÚinferÚ	ExceptionÚprintÚsysÚexc_info)r   Údynamic_axis_mappingÚupdates   &&&r   Úinfer_runtime_shapeÚOnnxModel.infer_runtime_shape3   s–   € Ø×"×"Ð"Ø×&Ñ&Ò.·&Ü*FÀtÇzÁzÓ*R�Ô'ðFØ×*Ñ*×0Ñ0Ð1E×FÒFØ×2Ñ2Ð2ð Gó øô	 ô FØ*/�Ô'ÜÐ1´3·<²<³>À!Õ3DÕEáð	Fús   Á A6 Á%A6 Á68B2Â1B2c                ó  € / pV'       g   V P                  4       MV P                  P                  P                  pV FD  pVP                   F1  pV'       g   K  WR9  d   V.W%&   K  W%,          P                  V4       K3  	  KF  	  V# r   )Únodesr   ÚgraphÚnodeÚinputÚappend)r   Úexclude_subgraphsÚinput_name_to_nodesÚnodes_to_searchr8   Ú
input_names   &&    r   r<   ÚOnnxModel.input_name_to_nodesA   sn   € Ø Ðß.?˜$Ÿ*™*œ,ÀTÇZÁZ×EUÑEU×EZÑEZˆÛ#ˆDØ"Ÿjœj�
ß‘:Ø!Ô<Ø;?¸&Ð+Ó7à+Õ7×>Ñ>¸tÖDó )ñ $ð #Ð"r   c                óÎ   € / pV'       g   V P                  4       MV P                  P                  P                  pV F$  pVP                   F  pV'       g   K  WBV&   K  	  K&  	  V# r   )r6   r   r7   r8   Úoutput)r   r;   Úoutput_name_to_noder=   r8   Úoutput_names   &&    r   rB   ÚOnnxModel.output_name_to_nodeM   sT   € Ø Ðß.?˜$Ÿ*™*œ,ÀTÇZÁZ×EUÑEU×EZÑEZˆÛ#ˆDØ#Ÿ{œ{�ß‘;Ø7;¨Ó4ó  +ñ $ð #Ð"r   c                óF   € \        V P                  P                  4      .pV# r   )Úlistr   Ú	functions)r   Úall_functionss   & r   rG   ÚOnnxModel.functionsV   s   € Ü˜dŸj™j×2Ñ2Ó3Ð4ˆØÐr   c                ó€   € . pV P                  4        F'  pVP                   F  pVP                  V4       K  	  K)  	  V# r   )Úgraphsr8   r:   )r   Ú	all_nodesr7   r8   s   &   r   r6   ÚOnnxModel.nodesZ   s;   € Øˆ	Ø—[‘[–]ˆEØŸ
œ
�Ø× Ñ  Ö&ó #ñ #ð Ðr   c                ó.   € V P                   P                  # r   )r   r7   r(   s   &r   r7   ÚOnnxModel.grapha   s   € Ø�z‰z×ÑÐr   c                óà  € V P                   e   V P                   # . V n         V P                  P                  .pV'       Ed#   VP                  ^ 4      pV P                   P	                  V4       VP
                   Fã  pVP                   FÐ  pVP                  \        P                  P                  8X  d>   \        VP                  \        4      '       g   Q hVP	                  VP                  4       VP                  \        P                  P                  8X  g   K”  VP                   F,  p\        V\        4      '       g   Q hVP	                  V4       K.  	  KÒ  	  Kå  	  EK+  V P                   # r   )r#   r   r7   Úpopr:   r8   Ú	attributeÚtyper   ÚAttributeTypeÚGRAPHÚ
isinstanceÚgr   ÚGRAPHSrK   )r   Úgraph_queuer7   r8   ÚattrrW   s   &     r   rK   ÚOnnxModel.graphsd   s  € Ø�?‰?Ò&Ø—?‘?Ð"ØˆŒØ—z‘z×'Ñ'Ð(ˆßˆkØ—O‘O AÓ&ˆEØ�O‰O×"Ñ" 5Ô)ØŸ
œ
�Ø ŸNœN�DØ—y‘y¤N×$@Ñ$@×$FÑ$FÔFÜ)¨$¯&©&´*×=Ò=Ð=Ð=Ø#×*Ñ*¨4¯6©6Ô2Ø—y‘y¤N×$@Ñ$@×$GÑ$GÖGØ!%§¤˜AÜ#-¨a´×#<Ò#<Ð<Ð#<Ø'×.Ñ.¨qÖ1ó "-ó +ô #ð �‰Ðr   c                ó”   € . pV P                  4        F1  pVP                   F  pVP                  VP                  4       K   	  K3  	  V# r   )rK   r9   r:   Úname)r   Úinput_namesr7   r9   s   &   r   Úget_graphs_input_namesÚ OnnxModel.get_graphs_input_namesw   s?   € ØˆØ—[‘[–]ˆEØŸœ�Ø×"Ñ" 5§:¡:Ö.ó %ñ #ð Ðr   c                ó”   € . pV P                  4        F1  pVP                   F  pVP                  VP                  4       K   	  K3  	  V# r   )rK   rA   r:   r]   )r   Úoutput_namesr7   rA   s   &   r   Úget_graphs_output_namesÚ!OnnxModel.get_graphs_output_names~   s?   € ØˆØ—[‘[–]ˆEØŸ,œ,�Ø×#Ñ# F§K¡KÖ0ó 'ñ #ð Ðr   c                ó\   € V P                  4        F  pWP                  9   g   K  Vu # 	  R # r   )rK   r8   ©r   r8   r7   s   && r   Úget_graph_by_nodeÚOnnxModel.get_graph_by_node…   s&   € Ø—[‘[–]ˆEØ—z‘zÖ!Ø’ñ #ñ r   c                ó\   € V P                  4        F  pWP                  8X  g   K  Vu # 	  R # r   )rK   r]   )r   Ú
graph_namer7   s   && r   Úget_graph_by_nameÚOnnxModel.get_graph_by_name‹   s&   € Ø—[‘[–]ˆEØŸZ™ZÖ'Ø’ñ #ñ r   c                ó¦   € \        VP                  4       F$  w  r4VP                   F  pWR9   g   K  Vu u # 	  K&  	  \        VP                  4      # r   )Ú	enumerater8   r9   Úlen)r   r7   ÚoutputsÚidxr8   r9   s   &&&   r   Úget_topological_insert_idÚ#OnnxModel.get_topological_insert_id‘   s@   € Ü" 5§:¡:Ö.‰IˆCØŸœ�ØÖ#Ø”Jó $ñ /ô �5—:‘:‹Ðr   c                ó¼   € V P                  4        F1  pWP                  9   g   K  VP                  P                  V4        R # 	  \        P	                  RV4       R # )NzFailed to remove node %s)rK   r8   ÚremoveÚloggerÚwarningrf   s   && r   Úremove_nodeÚOnnxModel.remove_node˜   sB   € Ø—[‘[–]ˆEØ—z‘zÖ!Ø—
‘
×!Ñ! $Ô'Úñ #ô 	�‰Ð1°4Ö8r   c                ó:   € V F  pV P                  V4       K  	  R # r   )rx   )r   Únodes_to_remover8   s   && r   Úremove_nodesÚOnnxModel.remove_nodesŸ   s   € Û#ˆDØ×Ñ˜TÖ"ó $r   Nc                óH  € Ve%   W P                   P                  P                  8X  d3   V P                   P                  P                  P	                  V.4       R # V P                  V4      pV P                  W1P                  4      pVP                  P                  WA4       R # r   )	r   r7   r]   r8   Úextendrk   rr   rA   Úinsert)r   r8   rj   r7   Ú
insert_idxs   &&&  r   Úadd_nodeÚOnnxModel.add_node£   ss   € ØÒ ¯z©z×/?Ñ/?×/DÑ/DÔ!DØ�J‰J×Ñ×!Ñ!×(Ñ(¨$¨Ö0à×*Ñ*¨:Ó6ˆEØ×7Ñ7¸¿{¹{ÓKˆJØ�J‰J×Ñ˜jÖ/r   c                óÈ   € Vf2   V P                   P                  P                  P                  V4       R # V F&  pW#P                  ,          pV P                  W44       K(  	  R # r   )r   r7   r8   r   r]   r‚   )r   Únodes_to_addÚnode_name_to_graph_namer8   rj   s   &&&  r   Ú	add_nodesÚOnnxModel.add_nodes«   sH   € Ø"Ò*Ø�J‰J×Ñ×!Ñ!×(Ñ(¨Ö6ã$�Ø4·Y±YÕ?�
Ø—‘˜dÖ/ó %r   c                ó  € Ve%   W P                   P                  P                  8X  d3   V P                   P                  P                  P	                  V.4       R # V P                  V4      pVP                  P	                  V.4       R # r   )r   r7   r]   Úinitializerr   rk   )r   Útensorrj   r7   s   &&& r   Úadd_initializerÚOnnxModel.add_initializer³   sc   € ØÒ ¯z©z×/?Ñ/?×/DÑ/DÔ!DØ�J‰J×Ñ×(Ñ(×/Ñ/°°Ö9à×*Ñ*¨:Ó6ˆEØ×Ñ×$Ñ$ f XÖ.r   c                ó  € Ve%   W P                   P                  P                  8X  d3   V P                   P                  P                  P	                  V.4       R # V P                  V4      pVP                  P	                  V.4       R # r   )r   r7   r]   r9   r   rk   )r   r9   rj   r7   s   &&& r   Ú	add_inputÚOnnxModel.add_inputº   sa   € ØÒ ¯z©z×/?Ñ/?×/DÑ/DÔ!DØ�J‰J×Ñ×"Ñ"×)Ñ)¨5¨'Ö2à×*Ñ*¨:Ó6ˆEØ�K‰K×Ñ ˜wÖ'r   c                óü   € \        V\        4      '       d   \        V\        4      '       g   Q h\        \        V P                  4      4       F+  pV P                  V,          V8X  g   K  W P                  V&   K-  	  R # r   )rV   ÚstrÚrangero   r9   )r8   Úold_input_nameÚnew_input_nameÚjs   &&& r   Úreplace_node_inputÚOnnxModel.replace_node_inputÁ   sS   € ä˜.¬#×.Ò.´:¸nÌc×3RÒ3RÐRÐRÜ”s˜4Ÿ:™:“Ö'ˆAØ�z‰z˜!�} Ö.Ø .—
‘
˜1“ó (r   c                ó`   € V P                  4        F  p\        P                  W1V4       K  	  R # r   )r6   r   r—   )r   r”   r•   r8   s   &&& r   Úreplace_input_of_all_nodesÚ$OnnxModel.replace_input_of_all_nodesÈ   s"   € Ø—J‘J–LˆDÜ×(Ñ(¨¸~ÖNó !r   c                óü   € \        V\        4      '       d   \        V\        4      '       g   Q h\        \        V P                  4      4       F+  pV P                  V,          V8X  g   K  W P                  V&   K-  	  R # r   )rV   r’   r“   ro   rA   )r8   Úold_output_nameÚnew_output_namer–   s   &&& r   Úreplace_node_outputÚOnnxModel.replace_node_outputÌ   sU   € ä˜/¬3×/Ò/´J¸ÔPS×4TÒ4TÐTÐTÜ”s˜4Ÿ;™;Ó'Ö(ˆAØ�{‰{˜1�~ Ö0Ø!0—‘˜A“ó )r   c                ó€   € V P                   P                  P                   F  p\        P	                  W1V4       K  	  R # r   )r   r7   r8   r   rŸ   )r   r�   rž   r8   s   &&& r   Úreplace_output_of_all_nodesÚ%OnnxModel.replace_output_of_all_nodesÓ   s.   € ð —J‘J×$Ñ$×)Ô)ˆDÜ×)Ñ)¨$ÀÖQó *r   c                óˆ   € V P                  4        F-  pVP                   F  pVP                  V8X  g   K  Vu u # 	  K/  	  R # r   )rK   rŠ   r]   )r   r]   r7   r‹   s   &&  r   Úget_initializerÚOnnxModel.get_initializerÝ   s8   € Ø—[‘[–]ˆEØ×+Ô+�Ø—;‘; $Ö&Ø!”Mó ,ñ #ñ r   c                ó€   € . pV P                  4        F'  pVP                  V8X  g   K  VP                  V4       K)  	  V# r   )r6   Úop_typer:   )r   r¨   r6   r8   s   &&  r   Úget_nodes_by_op_typeÚOnnxModel.get_nodes_by_op_typeä   s6   € ØˆØ—J‘J–LˆDØ�|‰|˜wÖ&Ø—‘˜TÖ"ñ !ð ˆr   c                ó*  € Vf   V P                  4       p. pVeG   V\        VP                  4      8  d+   VP                  V,          pWR9   d   \        W%,          4      pV# VP                   F"  pWR9   g   K  VP	                  W%,          4       K$  	  V# r   )r<   ro   rA   rF   r   )r   r8   r<   Úoutput_indexÚchildrenrA   s   &&&&  r   Úget_childrenÚOnnxModel.get_childrenë   s‰   € ØÒ&Ø"&×":Ñ":Ó"<ÐàˆØÒ#Øœc $§+¡+Ó.Ô.ØŸ™ \Õ2�ØÔ0Ü#Ð$7Õ$?Ó@�Hð ˆð	 Ÿ+œ+�ØÖ0Ø—O‘OÐ$7Õ$?Ö@ñ &ð ˆr   c                ó–   € Vf   V P                  4       p. pVP                   F"  pWB9   g   K  VP                  W$,          4       K$  	  V# r   )rB   r9   r:   )r   r8   rB   Úparentsr9   s   &&&  r   Úget_parentsÚOnnxModel.get_parentsü   sG   € ØÒ&Ø"&×":Ñ":Ó"<ÐàˆØ—Z”ZˆEØÖ+Ø—‘Ð2Õ9Ö:ñ  ð ˆr   c                ó¨   € Vf   V P                  4       p\        VP                  4      V8:  d   R # VP                  V,          pWC9  d   R # W4,          # r   )rB   ro   r9   )r   r8   ÚirB   r9   s   &&&& r   Ú
get_parentÚOnnxModel.get_parent  sI   € ØÒ&Ø"&×":Ñ":Ó"<Ðäˆt�z‰z‹?˜aÔÙà—
‘
˜1•ˆØÔ+Ùà"Õ)Ð)r   c                óä   € \        VP                  4       FV  w  rVWc9   g   K  W6,          pVP                  V8X  d   Wt9  d   Wu3u # \        P	                  RV RVP                   24       KX  	  R# )aÏ  
Find parent node based on constraints on op_type.

Args:
    node (str): current node name.
    parent_op_type (str): constraint of parent node op_type.
    output_name_to_node (dict): dictionary with output name as key, and node as value.
    exclude (list): list of nodes that are excluded (not allowed to match as parent).

Returns:
    parent: The matched parent node. None if not found.
    index: The input index of matched parent node. None if not found.
zTo find first z
, current ©NN)rn   r9   r¨   rv   Údebug)r   r8   Úparent_op_typerB   Úexcluderµ   r9   Úparents   &&&&&   r   Úmatch_first_parentÚOnnxModel.match_first_parent  sg   € ô " $§*¡*Ö-‰HˆAØÖ+Ø,Õ3�Ø—>‘> ^Ô3¸Ô8MØ!˜9Ò$ä—L‘L >°.Ð1AÀÈFÏNÉNÐK[Ð!\Ö]ñ .ð Ðr   c                óö  € Vf   Q hVe
   V^ 8¼  g   Q hVf   V P                  4       pVf,   V P                  WWE4      w  rxVe   VP                  V4       V# V\        VP                  4      8¼  d1   \
        P                  RV R\        VP                  4       24       R# V P                  WV4      pVe   VP                  V8X  d	   Wu9  d   V# Ve&   \
        P                  RV RVP                   24       R# )aÂ  
Find parent node based on constraints on op_type and index.
When input_index is None, we will find the first parent node based on constraints,
and return_indice will be appended the corresponding input index.

Args:
    node (str): current node name.
    parent_op_type (str): constraint of parent node op_type.
    input_index (int or None): only check the parent given input index of current node.
    output_name_to_node (dict): dictionary with output name as key, and node as value.
    exclude (list): list of nodes that are excluded (not allowed to match as parent).
    return_indice (list): a list to append the input index when input_index is None.

Returns:
    parent: The matched parent node.
Nzinput_index z >= node inputs zExpect z, Got )	rB   r¾   r:   ro   r9   rv   rº   r¶   r¨   )	r   r8   r»   Úinput_indexrB   r¼   Úreturn_indicer½   Úindexs	   &&&&&&&  r   Úmatch_parentÚOnnxModel.match_parent*  sö   € ð2 ÒÐÐØÒ" k°QÔ&6Ð6Ð6àÒ&Ø"&×":Ñ":Ó"<ÐàÒØ ×3Ñ3°DÐJ]Óg‰MˆFØÒ(Ø×$Ñ$ UÔ+ØˆMàœ#˜dŸj™j›/Ô)Ü�L‰L˜<¨ }Ð4DÄSÈÏÉÃ_ÐDUÐVÔWÙà—‘ Ð4GÓHˆØÒ &§.¡.°NÔ"BÀvÔG\ØˆMàÒÜ�L‰L˜7 >Ð"2°&¸¿¹Ð8HÐIÔJár   c                óÌ   € \        V4       FT  w  rE\        V\        \        34      '       g   Q h. pV P	                  W^ ,          V^,          W64      pV'       g   KP  WGV3u # 	  R# )r   )éÿÿÿÿNN)rn   rV   rF   ÚtupleÚmatch_parent_path)r   r8   ÚpathsrB   rµ   ÚpathrÂ   Úmatcheds   &&&&    r   Úmatch_parent_pathsÚOnnxModel.match_parent_paths\  sd   € Ü  Ö'‰GˆAÜ˜d¤T¬5 M×2Ò2Ð2Ð2ØˆMØ×,Ñ,¨T¸µ7¸DÀ½GÐEXÓhˆGß‰wØ =Ð0Ò0ñ (ð Ðr   c                ó8  € . . . rep\        V4       Fƒ  w  rx\        V\        \        34      '       g   Q h. p	V P	                  W^ ,          V^,          W94      p
V
'       g   KP  VP                  V4       VP                  V
4       VP                  V	4       K…  	  WEV3# ©r   )rn   rV   rF   rÈ   rÉ   r:   )r   r8   rÊ   rB   Úmatch_iÚmatchesÚreturn_indicesrµ   rË   rÂ   rÌ   s   &&&&       r   Úmatch_parent_paths_allÚ OnnxModel.match_parent_paths_alle  s�   € Ø+-¨r°2˜.ˆÜ  Ö'‰GˆAÜ˜d¤T¬5 M×2Ò2Ð2Ð2ØˆMØ×,Ñ,¨T¸µ7¸DÀ½GÐEXÓhˆGß‰wØ—‘˜qÔ!Ø—‘˜wÔ'Ø×%Ñ% mÖ4ñ (ð  Ð/Ð/r   c           
     óª  € Ve   \        V4      \        V4      8X  g   Q hVf   V P                  4       pTp. p\        V4       FŒ  w  r‰T P                  TT	Ve	   W8,          MRV. VR7      p
V
fN   Ve*   \        P                  RV RW8,           RV	 2RR7        R# \        P                  RV RV	 2RR7        R# VP                  V
4       T
pKŽ  	  V# )aâ  
Find a sequence of input edges based on constraints on parent op_type and index.
When input_index is None, we will find the first parent node based on constraints,
and return_indice will be appended the corresponding input index.

Args:
    node (str): current node name.
    parent_op_types (str): constraint of parent node op_type of each input edge.
    parent_input_index (list): constraint of input index of each input edge. None means no constraint.
    output_name_to_node (dict): dictionary with output name as key, and node as value.
    return_indice (list): a list to append the input index
                          When there is no constraint on input index of an edge.

Returns:
    parents: a list of matched parent node.
N)r¼   rÂ   zFailed to match index=z parent_input_index=ú	 op_type=T©Ú
stack_info)ro   rB   rn   rÄ   rv   rº   r:   )r   r8   Úparent_op_typesÚparent_input_indexrB   rÂ   Úcurrent_nodeÚmatched_parentsrµ   r¨   Úmatched_parents   &&&&&&     r   rÉ   ÚOnnxModel.match_parent_pathq  s
  € ð0 Ò)ÜÐ)Ó*¬c°/Ó.BÔBÐBÐBàÒ&Ø"&×":Ñ":Ó"<ÐàˆØˆÜ# OÖ4‰JˆAØ!×.Ñ.ØØØ);Ò)GÐ"Ö%ÈTØ#ØØ+ð /ó ˆNð Ò%Ø%Ò1Ü—L‘LØ0°°Ð3GÐHZÕH]ÐG^Ð^gÐhoÐgpÐqØ#'ð !ô ò ô —L‘LÐ#9¸!¸¸IÀgÀYÐ!OÐ\`�LÔaÚà×"Ñ" >Ô2Ø)ŠLñ) 5ð, Ðr   c                ó  € V P                  W4      p\        V4      p\        V4      ^ 8”  d[   VP                  4       pVP                  V8X  d   V# V'       g   K=  V P                  Ws4      pV F  pVP                  V4       K  	  Kj  R# ©r   N)r®   r   ro   rQ   r¨   Ú
appendleft)	r   r8   Ú
child_typer<   Ú	recursiver­   ÚdqrÜ   Úchilds	   &&&&&    r   Úfind_first_child_by_typeÚ"OnnxModel.find_first_child_by_type©  su   € Ø×$Ñ$ TÓ?ˆÜ�8‹_ˆÜ�"‹g˜ŒkØŸ6™6›8ˆLØ×#Ñ# zÔ1Ø#Ð#ç‰yØ×,Ñ,¨\ÓO�Û%�EØ—M‘M %Ö(ó &ñ r   c                óT   <€ V ^8„  d   QhRS[ S[S[S[3,          ,          R,          /# )é   ÚedgesN)rF   rÈ   Úint)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚOnnxModel.__annotate__¸  s)   ø€ ÷ = ñ = ñ ‘E™#™s˜(•OÕ$ tÕ+ñ	= r   c                ó0  € Ve‡   \        V4      \        V4      8X  g   Q hV Fe  p\        V\        4      '       dM   \        V4      ^8X  d=   \        V^ ,          \        4      '       d    \        V^,          \        4      '       d   Ke  Q h	  Vf   V P	                  4       pTp. p\        V4       Fä  w  ršRpVf   V P                  WtR7      pM V P                  WtW9,          ^ ,          R7      pV Fi  pVP                  V
8X  g   K  WÕ9  g   K  VeF   VP                  W9,          ^,          ,          VP                  W9,          ^ ,          ,          8w  d   Kg  Tp M	  Vf!   \        P                  RV	 RV
 2RR7        R# VP                  V4       TpKæ  	  V# )af  
Find a sequence of input edges based on constraints on parent op_type and index.
Note that we use greedy approach and only consider the first matched child, so it has chance to miss matching.

Args:
    node (str): current node name.
    child_op_types (str): constraint of child node op_type of each input edge.
    edges (list): each edge is represented by two integers: output index of parent node, input index of child node.
                 None means no constraint.
    exclude(list): list of nodes that are excluded (not allowed to match as child).

Returns:
    children: a list of matched children node.
N)r<   )r<   r¬   zFailed to match child r×   TrØ   )ro   rV   rÈ   rì   r<   rn   r®   r¨   r9   rA   rv   rº   r:   )r   r8   Úchild_op_typesrë   r<   r¼   ÚedgerÜ   Úmatched_childrenrµ   r¨   Úmatched_childÚchildren_nodesræ   s   &&&&&&        r   Úmatch_child_pathÚOnnxModel.match_child_path¸  s…  € ð, ÒÜ�u“:¤ ^Ó!4Ô4Ð4Ð4Û�ä˜t¤U×+Ò+´°D³	¸Q´Ä:ÈdÐSTÍgÔWZ×C[ÒC[Ô`jÐkoÐpqÕkrÔtw×`xÔ`xðØxñ ð
 Ò&Ø"&×":Ñ":Ó"<ÐàˆØÐÜ# NÖ3‰JˆAØ ˆMàŠ}Ø!%×!2Ñ!2°<Ð!2Ó!i‘à!%×!2Ñ!2Ø ÐX]ÕX`ÐabÕXcð "3ó "�ó (�Ø—=‘= GÖ+°Ö0DØÒ(¨U¯[©[¸½À!½Õ-EÈ×I\ÑI\Ð]bÕ]eÐfgÕ]hÕIiÔ-iÙ ð %*�MÙñ (ð Ò$Ü—‘Ð5°a°S¸	À'ÀÐKÐX\�Ô]Úà×#Ñ# MÔ2Ø(ŠLñ3 4ð6  Ðr   c                ó:  € Vf   V P                  4       pV P                  W4      p\        V4      p\        V4      ^ 8”  d[   VP	                  4       pVP
                  V8X  d   V# V'       g   K=  V P                  Ws4      pV F  pVP                  V4       K  	  Kj  R # r   )rB   r²   r   ro   rQ   r¨   râ   )	r   r8   Úparent_typerB   rä   r±   rå   rÜ   r½   s	   &&&&&    r   Úfind_first_parent_by_typeÚ#OnnxModel.find_first_parent_by_type÷  sŠ   € ØÒ&Ø"&×":Ñ":Ó"<Ðà×"Ñ" 4Ó=ˆÜ�7‹^ˆÜ�"‹g˜ŒkØŸ6™6›8ˆLØ×#Ñ# {Ô2Ø#Ð#ç‰yØ×*Ñ*¨<ÓM�Û%�FØ—M‘M &Ö)ó &ñ r   c                óP  € V P                  R 4       Fe  pVP                  ^ ,          V8X  g   K  VP                   F8  pVP                  R8X  g   K  \        P
                  ! VP                  4      u u # 	  Kg  	  V P                  V4      pVe   \        P
                  ! V4      # R# )ÚConstantÚvalueN)r©   rA   rR   r]   r   Úto_arrayÚtr¥   )r   rC   r8   ÚattrŠ   s   &&   r   Úget_constant_valueÚOnnxModel.get_constant_value	  s‚   € Ø×-Ñ-¨jÖ9ˆDØ�{‰{˜1�~ Ö,ØŸ>œ>�CØ—x‘x 7Ö*Ü+×4Ò4°S·U±UÓ;Ô;ó *ñ :ð ×*Ñ*¨;Ó7ˆØÒ"Ü×(Ò(¨Ó5Ð5ár   c                óv   € \        VP                  4       F  w  r#V P                  V4      pVf   K  W$3u # 	  R# )Nr¹   )rn   r9   r  )r   r8   rµ   r9   rÿ   s   &&   r   Úget_constant_inputÚOnnxModel.get_constant_input  s<   € Ü! $§*¡*Ö-‰HˆAØ×+Ñ+¨EÓ2ˆEØÔ Ø�x’ñ .ð
 Ðr   c                ó†   € V P                  V4      w  rEVe*   VP                  ^8X  d   \        WR,
          4      V8  d   V# R# )NrÇ   )r  ÚsizeÚabs)r   r8   Úexpected_valueÚdeltarµ   rÿ   s   &&&&  r   Úfind_constant_inputÚOnnxModel.find_constant_input  s>   € Ø×*Ñ*¨4Ó0‰ˆØÒ §¡¨q¤´S¸Õ9OÓ5PÐSXÔ5XØˆHàˆ	r   c           	     óö   € V P                  V4      pVf   \        P                  V RV R24       R# \        VP                  4      V8w  d-   \        P                  V RV RV RVP                   24       R# R# )NÚ z is not initializer.Fz shall have z dimensions. Got shape T)r  rv   rº   ro   Úshape)r   rC   Ú
dimensionsÚdescriptionrÿ   s   &&&& r   Ú$is_constant_with_specified_dimensionÚ.OnnxModel.is_constant_with_specified_dimension&  sw   € Ø×'Ñ'¨Ó4ˆØŠ=Ü�L‰L˜K˜=¨¨+¨Ð6JÐKÔLÙäˆu�{‰{Ó˜zÔ)Ü�L‰L˜K˜=¨¨+¨°lÀ:À,ÐNeÐfk×fqÑfqÐerÐsÔtÙár   c                ó,   € V P                  WV4      ^ 8¬  # rÐ   )r  )r   r8   r  r  s   &&&&r   Úhas_constant_inputÚOnnxModel.has_constant_input2  s   € Ø×'Ñ'¨¸eÓDÈÑIÐIr   c                óz  € Vf   V P                  4       pW1P                  ^ ,          ,          p. p\        V4      p\        V4      ^ 8”  dq   VP	                  4       pWr9   d   K(  Wu9  g   K0  VP                  V4       VP                   F-  pWƒ9   g   K  W8,          pV F  p	VP                  V	4       K  	  K/  	  K€  V# r   )r<   rA   r   ro   rQ   r:   râ   )
r   Ú	root_nodeÚ
stop_nodesr<   r­   Úunique_nodesrå   rÜ   rA   ræ   s
   &&&&      r   Úget_children_subgraph_nodesÚ%OnnxModel.get_children_subgraph_nodes5  s§   € ØÒ&Ø"&×":Ñ":Ó"<Ðà&×'7Ñ'7¸Õ':Õ;ˆàˆä�8‹_ˆÜ�"‹g˜ŒkØŸ6™6›8ˆLØÔ)ÙàÖ/Ø×#Ñ# LÔ1à*×1Ô1�FØÖ4Ø#6Õ#>˜Û%-˜EØŸM™M¨%Ö0ó &.ó 2ð Ðr   c                ó6  € . pVP                   P                   F|  pVP                  R4      '       d   VP                  VP                  4       K7  VP                  R4      '       d   VP                  VP
                  4       Kk  VP                  R4       K~  	  V# )zConvert tensor shape to listÚ	dim_valueÚ	dim_paramÚ?)r  ÚdimÚHasFieldr:   r   r!  )r   Útensor_typeÚ
shape_listÚds   &&  r   Útensor_shape_to_listÚOnnxModel.tensor_shape_to_listN  su   € àˆ
Ø×"Ñ"×&Ô&ˆAØ�z‰z˜+×&Ò&Ø×!Ñ! !§+¡+Ö.Ø—‘˜K×(Ò(Ø×!Ñ! !§+¡+Ö.à×!Ñ! #Ö&ñ 'ð Ðr   c                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# ©rê   r]   Úsymbolic_shape_helperN©r’   r   )rí   rî   s   "€r   rï   rð   Z  s"   ø€ ÷ ñ ™cð Ñ:VÐY]Õ:]ñ r   c                ó4  € V P                   Ef   / V n         \        P                  ! V P                  P                  P
                  V P                  P                  P                  V P                  P                  P                  4       F:  pVP                  P                  P                  V P                   VP                  &   K<  	  V P                  P                  P                   FC  pVP                  V P                   9  g   K   VP                  V P                   VP                  &   KE  	  WP                   9   d   V P                   V,          # VeD   WP                  9   d4   VP                  V,          pVP                  P                  P                  # R# )zXTry get data type given a name (could be initializer, input or output of graph or node).N)r$   Ú	itertoolsÚchainr   r7   Ú
value_infor9   rA   rS   r%  Ú	elem_typer]   rŠ   Ú	data_typeÚ	known_vi_)r   r]   r,  r1  rŠ   s   &&&  r   Ú	get_dtypeÚOnnxModel.get_dtypeZ  s/  € ð ×ÑÓ#Ø!ˆDÔÜ'ŸošoØ—
‘
× Ñ ×+Ñ+Ø—
‘
× Ñ ×&Ñ&Ø—
‘
× Ñ ×'Ñ'ö�
ð
 5?·O±O×4OÑ4O×4YÑ4Y�× Ñ  §¡Ó1ñð  $Ÿz™z×/Ñ/×;Ô;�Ø×#Ñ#¨4×+;Ñ+;Ö;Ø9D×9NÑ9N�D×$Ñ$ [×%5Ñ%5Ó6ñ  <ð ×#Ñ#Ô#Ø×#Ñ# DÕ)Ð)à Ò,°×9XÑ9XÔ1XØ.×8Ñ8¸Õ>ˆJØ—?‘?×.Ñ.×8Ñ8Ð8ár   c                ó4   <€ V ^8„  d   QhRS[ RS[R,          /# r+  r-  )rí   rî   s   "€r   rï   rð   s  s"   ø€ ÷ ñ ™cð Ñ:VÐY]Õ:]ñ r   c                óJ  € V P                   Efª   / V n         \        P                  ! V P                  P                  P
                  V P                  P                  P                  V P                  P                  P                  4       FÅ  pVP                  P                  P                  R4      '       g   K0  . pVP                  P                  P                  P                   FM  pVP                  '       d   VP                  VP                  4       K2  VP                  VP                  4       KO  	  W@P                   VP                   &   KÇ  	  V P                  P                  P"                   FC  pVP                   V P                   9  g   K   VP$                  V P                   VP                   &   KE  	  WP                   9   d   V P                   V,          # VeD   WP&                  9   d4   VP&                  V,          pVP                  P                  P(                  # R# )zTTry get shape given a name (could be initializer, input or output of graph or node).Nr  )r%   r/  r0  r   r7   r1  r9   rA   rS   r%  r$  r  r#  r!  r:   r   r]   rŠ   Údimsr4  r2  )r   r]   r,  r1  r  r#  rŠ   s   &&&    r   Ú	get_shapeÚOnnxModel.get_shapes  s‰  € ð ×ÑÓ#Ø!ˆDÔÜ'ŸošoØ—
‘
× Ñ ×+Ñ+Ø—
‘
× Ñ ×&Ñ&Ø—
‘
× Ñ ×'Ñ'ö�
ð
 —?‘?×.Ñ.×7Ñ7¸×@Ô@Ø�EØ)Ÿ™×:Ñ:×@Ñ@×DÔD˜ØŸ=Ÿ=˜=Ø!ŸL™L¨¯©Ö7à!ŸL™L¨¯©Ö7ñ	  Eð
 9>×$Ñ$ Z§_¡_Ó5ñð  $Ÿz™z×/Ñ/×;Ô;�Ø×#Ñ#¨4×+;Ñ+;Ö;Ø9D×9IÑ9I�D×$Ñ$ [×%5Ñ%5Ó6ñ  <ð ×#Ñ#Ô#Ø×#Ñ# DÕ)Ð)à Ò,°×9XÑ9XÔ1XØ.×8Ñ8¸Õ>ˆJØ—?‘?×.Ñ.×8Ñ8Ð8ár   c                ó&   <€ V ^8„  d   QhRS[ RS[/# )rê   r8   Úattribute_name)r	   r’   )rí   rî   s   "€r   rï   rð   ”  s   ø€ ÷ ñ ¡ð ¹Cñ r   c                ó‚   € V P                    F.  pVP                  V8X  g   K  \        P                  ! V4      pVu # 	  R # r   )rR   r]   r   Úget_attribute_value)r8   r=  rZ   rÿ   s   &&  r   Úget_node_attributeÚOnnxModel.get_node_attribute“  s6   € à—N”NˆDØ�y‰y˜NÖ*Ü×2Ò2°4Ó8�Ø’ñ #ñ r   c                ó�  € V P                  4       p^ pV P                  4        Fp  pVP                  R8X  g   K  V P                  V^ VR7      pV'       g   K4  VP                  R8X  g   KG  VP                  ^ ,          VP                  ^ &   V^,          pKr  	  V^ 8”  d)   \
        P                  RV4       V P                  4        R# R# )aV  Remove Cast node that are followed by another Cast node like  --> Cast --> Cast -->
Note that this shall be used carefully since it might introduce semantic change.
For example, float -> int -> float could get different value than the original float value.
So, it is recommended to used only in post-processing of mixed precision conversion.
ÚCast)rB   zRemoved %d cascaded Cast nodesN)rB   r6   r¨   r¶   r9   rv   ÚinfoÚprune_graph)r   rB   Úremoved_countr8   r½   s   &    r   Úremove_cascaded_cast_nodesÚ$OnnxModel.remove_cascaded_cast_nodes›  s¢   € ð #×6Ñ6Ó8ÐØˆØ—J‘J–LˆDØ�|‰|˜vÖ%ØŸ™¨¨qÐFY˜ÓZ�ß‘6˜fŸn™n°Ö6Ø$*§L¡L°¥O�D—J‘J˜q‘MØ! QÕ&’Mñ !ð ˜1ÔÜ�K‰KÐ8¸-ÔHØ×ÑÖñ r   c                óˆ  € V P                  RR7      pV P                  '       d   Vf   \        P                  R4       . pV P	                  4        F  pVP
                  R8X  g   K  V P                  VP                  ^ ,          V4      pV P                  VP                  ^ ,          V4      pV'       g   Kf  WE8X  g   Kn  VP                  V4       K�  	  V'       Edg   \        V P                  4       4      p\        V P                  4       4      pV EF  p\        \        VP                  4      V,          4      '       d™   \        \        VP                  4      V,          4      '       gl   \        V P                  4       VP                  ^ ,          ,          4      ^8X  d6   V P!                  VP                  ^ ,          VP                  ^ ,          4       M6KÇ  V P#                  VP                  ^ ,          VP                  ^ ,          4       V P%                  V4       EK  	  \        P'                  R\        V4      4       R# R# )zKRemove cast nodes that are not needed: input and output has same data type.T)r2   NzFshape inference failed which might impact useless cast node detection.rC  z4Removed %d Cast nodes with output type same as input)r3   r"   rv   rw   r6   r¨   r5  r9   rA   r:   Úsetr_   rc   Úboolro   r<   r¢   rš   rx   rD  )r   Úshape_inferr{   r8   Úinput_dtypeÚoutput_dtypeÚgraph_input_namesÚgraph_output_namess   &       r   Úremove_useless_cast_nodesÚ#OnnxModel.remove_useless_cast_nodes®  s¤  € à×.Ñ.°dÐ.Ó;ˆØ×"×"Ð" {Ò':Ü�N‰NÐcÔdàˆØ—J‘J–LˆDØ�|‰|˜vÖ%Ø"Ÿn™n¨T¯Z©Z¸­]¸KÓH�Ø#Ÿ~™~¨d¯k©k¸!­n¸kÓJ�ß‘; ;Ö#>Ø#×*Ñ*¨4Ö0ñ !÷ ˆ?Ü # D×$?Ñ$?Ó$AÓ BÐÜ!$ T×%AÑ%AÓ%CÓ!DÐÜ'�Üœ˜DŸK™KÓ(Ð+=Õ=×>Ò>Ü ¤ T§Z¡Z£Ð3DÕ!D×EÒEÌ3Ø×0Ñ0Ó2°4·:±:¸aµ=ÕAóLàôLð ×8Ñ8¸¿¹ÀA½ÈÏÉÐTUÍÕWá à×3Ñ3°D·K±KÀµNÀDÇJÁJÈqÅMÔRØ× Ñ  ×&ñ (ô �K‰KØFÜ�OÓ$öñ r   c                óV   € \         P                  R 4       V P                  RVR7       R# )zbThe function convert_model_float32_to_float16 is deprecated. Use convert_float_to_float16 instead!T)Úuse_symbolic_shape_inferÚkeep_io_typesN)rv   rw   r   )r   Úcast_input_outputs   &&r   Ú convert_model_float32_to_float16Ú*OnnxModel.convert_model_float32_to_float16Ð  s'   € Ü�‰Øpô	
ð 	×%Ñ%¸tÐSdÐ%Öer   c                ó  € RV9  d   RVR&   V P                   pV'       EdÂ   \        V4      p VP                  VRRR7      pVEe�   / pVP                  P                   EF  p\        VP                  R4      '       g   K"  \        VP                  P                  R4      '       g   KJ  VP                  P                  P                  \        P                  8w  g   K  VP                  '       g   K“  \        4       pVP                  V4       \        VP                  P                  R4      '       d&   VP                  P                  P                  R4       W†VP                  &   EK
  	  VP                  P                   F"  pVP                  V9   g   K  WgP                   K$  	  VP                  4        F(  pVP                  P                  P!                  V4       K*  	  R
V/p	T	P)                  R U
u/ uF  p
W¢9   g   K  W¢V
,          bK  	  up
4       \+        V3/ V	B pV P-                  V4       V P/                  4        V P1                  4        R#   \"         d    \$        P'                  R	4        L•i ; iu up
i )aõ  Convert a model to half (default) or mixed precision.
   To use mixed precision, user need specify which graph inputs, outputs, operator type
   or list of nodes shall keep in float32.

   Note that the conversion might not proceed without type information for the whole graph.

   By default, we use symbolic shape inference to get type information. The benefit of symbolic shape inference
   is that it could handle fused operators in com.microsoft domain. Those operators cannot be handled in onnx shape
   inference so symbolic shape inference is recommended for optimized model.

   When symbolic shape inference is used (even if it failed), ONNX shape inference will be disabled.

   Note that onnx shape inference will fail for model larger than 2GB. For large model, you have to enable
   symbolic shape inference. If your model is not optimized, you can also use model path to call
   convert_float_to_float16 in float16.py (see https://github.com/microsoft/onnxruntime/pull/15067) to
   avoid the 2GB limit.

Args:
    use_symbolic_shape_infer (bool, optional): use symbolic shape inference instead of onnx shape inference.
                                               Defaults to True.
    keep_io_types (Union[bool, List[str]], optional): boolean or a list of float32 input/output names.
                                                      If True, model inputs/outputs should be left as float32.
                                                      Defaults to True.
    op_block_list (List[str], optional): List of operator types to leave as float32.
                                         Defaults to None, which will use `float16.DEFAULT_OP_BLOCK_LIST`.
    node_block_list (List[str], optional): List of node names to leave as float32. Defaults to None.
    force_fp16_initializers(bool): force converting all float initializers to float16.
                                   Default to false.
    min_positive_val (float, optional): minimal positive value. Defaults to 1e-7.
    max_finite_val (float, optional): maximal finite value. Defaults to 1e4.
    force_fp16_inputs(Dict[str, List[int]]): Force the conversion of the inputs of some operators to float16, even if
                                             this script's preference it to keep them in float32.
rU  TF)Ú
auto_mergeÚguess_output_rankNr%  r2  r  ziFailed to run symbolic shape inference. Please file an issue in https://github.com/microsoft/onnxruntime.Údisable_shape_infer)rU  Úmin_positive_valÚmax_finite_valÚop_block_listÚnode_block_listÚforce_fp16_initializersÚforce_fp16_inputsÚ#use_bfloat16_as_blocked_nodes_dtype)r   r   Úinfer_shapesr7   r1  ÚhasattrrS   r%  r2  r
   Ú	UNDEFINEDr]   r   ÚCopyFromÚ
ClearFieldÚvaluesr:   r-   rv   rw   r2   r   r   rG  rQ  )r   rT  Úkwargsr   r!   Úmodel_with_shapeÚname_viÚviÚvi_copyÚ
parametersÚkeyÚ
fp16_models   &&,         r   r   Ú"OnnxModel.convert_float_to_float16Ö  s  € ðD  &Ô(Ø&*ˆF�?Ñ#à—
‘
ˆß#Ð#ô ">¸eÓ!DÐðØ#5×#BÑ#BÀ5ÐUYÐmrÐ#BÓ#sÐ ð
 $Ó/Ø �GØ.×4Ñ4×?Õ?˜ä# B§G¡G¨]×;Ô;Ü '¨¯©×(;Ñ(;¸[× IÔ IØ "§¡× 3Ñ 3× =Ñ =Ä×AVÑAVÖ VØ "§§¢ä&4Ó&6˜GØ#×,Ñ,¨RÔ0Ü& w§|¡|×'?Ñ'?À×IÒIØ '§¡× 8Ñ 8× CÑ CÀGÔ LØ/6 B§G¡GÔ,ñ @ð $Ÿk™k×4Ô4˜ØŸ7™7 gÖ-Ø '¯©Ò 0ñ 5ð &Ÿn™nÖ.˜ØŸ™×.Ñ.×5Ñ5°bÖ9ñ /ð ,Ð-EÐFˆ
Ø×Ññ	óñ	�Cð ‘=ô !�˜C•[Ò ñ	ñô	
ô" .¨eÑB°zÑBˆ
Ø�‰˜
Ô#à×'Ñ'Ô)à×&Ñ&Ö(øô9 ô Ü—‘Øöðüòs>   ®AI Â#I Â)0I ÃI Ã2B I ÆAI Ç6I<ÈI<É I9É8I9c                ó.  € V'       d$   VP                  R4      '       d   TMVR,           pM	VR,           p^ pW0P                  9   d   V P                  V,          ^,           pMƒV P                  4        Fo  pVP                  '       g   K  VP                  P	                  V4      '       g   K:   \        VP                  \        V4      R 4      p\        V^,           V4      pKq  	  W@P                  V&   V\        V4      ,           #   \         d     K¡  i ; i)a:  Create a unique node name that starts with a prefix (default is operator type).
   The name will not be duplicated with any name that generated or existed in current graphs.
Args:
    op_type (str): operator type
    name_prefix (str, optional): prefix of node name. Defaults to None.

Returns:
    str: node name
Ú_N)
Úendswithr    r6   r]   Ú
startswithrì   ro   ÚmaxÚ
ValueErrorr’   )r   r¨   Úname_prefixÚprefixÚsuffixr8   rÃ   s   &&&    r   Úcreate_node_nameÚOnnxModel.create_node_name7  sã   € ÷ Ø$/×$8Ñ$8¸×$=Ò$=‘[ÀKÐRUÕDU‰Fà˜s•]ˆFàˆØ×+Ñ+Ô+Ø×+Ñ+¨FÕ3°aÕ7‰Fð Ÿ
™
ž�Ø—9—9’9 §¡×!5Ñ!5°f×!=Ô!=ð!Ü # D§I¡I¬c°&«k¨mÐ$<Ó =˜Ü!$ U¨Q¥Y°Ó!7šñ	 %ð *0×Ñ˜vÑ&àœ˜F›Õ#Ð#øô &ô !Ú ð!ús   Â-4DÄDÄDc                ó~   € V P                   P                  P                   F  pVP                  V8X  g   K  Vu # 	  R # r   )r   r7   r9   r]   )r   r>   r9   s   && r   Úfind_graph_inputÚOnnxModel.find_graph_inputZ  s2   € Ø—Z‘Z×%Ñ%×+Ô+ˆEØ�z‰z˜ZÖ'Ø’ñ ,ñ r   c                ó~   € V P                   P                  P                   F  pVP                  V8X  g   K  Vu # 	  R # r   )r   r7   rA   r]   )r   rC   rA   s   && r   Úfind_graph_outputÚOnnxModel.find_graph_output`  s2   € Ø—j‘j×&Ñ&×-Ô-ˆFØ�{‰{˜kÖ)Ø’ñ .ñ r   c                óT  € Vf   V P                  4       p. pV P                  W4      p\        V4      p\        V4      ^ 8”  df   VP	                  4       pWr9   d   K(  Wt9  g   K0  VP                  V4       VP                   F"  pWƒ9   g   K  VP                  W8,          4       K$  	  Ku  V# r   )rB   r²   r   ro   rQ   r:   r9   râ   )	r   r8   r  rB   r  r±   rå   rÜ   r9   s	   &&&&     r   Úget_parent_subgraph_nodesÚ#OnnxModel.get_parent_subgraph_nodesf  s–   € ØÒ&Ø"&×":Ñ":Ó"<Ðàˆà×"Ñ" 4Ó=ˆÜ�7‹^ˆÜ�"‹g˜ŒkØŸ6™6›8ˆLØÔ)ÙàÖ/Ø×#Ñ# LÔ1à)×/Ô/�EØÖ3ØŸ™Ð&9Õ&@ÖAó 0ð Ðr   c                ód  € . pVP                    F5  pV P                  V4      '       g   K  WC9  g   K$  VP                  V4       K7  	  V'       da   V P                  V. 4      pV FH  pVP                    F5  pV P                  V4      '       g   K  WC9  g   K$  VP                  V4       K7  	  KJ  	  V# )z0
Find graph inputs that linked to current node.
)r9   r  r:   r…  )r   rÜ   rä   Úgraph_inputsr9   Úparent_nodesr8   s   &&&    r   Úget_graph_inputsÚOnnxModel.get_graph_inputs|  s˜   € ð ˆØ!×'Ô'ˆEØ×$Ñ$ U×+Ô+°Ö0IØ×#Ñ# EÖ*ñ (÷ Ø×9Ñ9¸,ÈÓKˆLÛ$�Ø!ŸZœZ�EØ×,Ñ,¨U×3Ô3¸Ö8QØ$×+Ñ+¨EÖ2ó (ñ %ð Ðr   c                óV   € \        VP                  4       F  w  r#W08X  g   K  Vu # 	  R# )é   rÇ   )rn   r9   )Únode_outputÚ
child_noderÃ   r9   s   &&  r   rÁ   ÚOnnxModel.input_index�  s+   € ä% j×&6Ñ&6Ö7‰LˆEØÖ#Ø’ñ 8ð ˆ	r   c                ó`  € V P                  4       p. pV P                  4       pV FA  pVP                  R 8X  g   K  VP                  ^ ,          V9  g   K0  VP	                  V4       KC  	  V P                  V4       \        V4      ^ 8”  d$   \        P                  R\        V4       24       R# R# )rþ   zRemoved unused constant nodes: N)	r<   r6   r¨   rA   r:   r|   ro   rv   rº   )r   r<   Úunused_nodesr6   r8   s   &    r   Úremove_unused_constantÚ OnnxModel.remove_unused_constant”  s“   € Ø"×6Ñ6Ó8Ðð ˆØ—
‘
“ˆÛˆDØ�|‰|˜zÖ)¨d¯k©k¸!­nÐDWÖ.WØ×#Ñ# DÖ)ñ ð 	×Ñ˜,Ô'äˆ|Ó˜qÔ Ü�L‰LÐ:¼3¸|Ó;LÐ:MÐNÖOñ !r   c                óö   € \        4       pVP                   F^  pVP                  \        P                  8X  g   K$  VP
                  P                  pV F  pVP                  VP                  4       K   	  K`  	  V# )z4
Get inputs to all nodes in all subgraphs of a node
)	rJ  rR   rS   r   rU   rW   r8   r2   r9   )r   r8   Úsubgraph_nodes_inputsrZ   Úchild_nodesr�  s   &&    r   Ú_get_subgraph_inputs_of_nodeÚ&OnnxModel._get_subgraph_inputs_of_node£  s_   € ô
 !$£ÐØ—N”NˆDØ�y‰yœN×0Ñ0Ö0Ø"Ÿf™fŸk™k�Û"-�JØ)×0Ñ0°×1AÑ1AÖBó #.ñ #ð
 %Ð$r   c                óâ   a€ \        \        V3R lV P                  P                  P                  4      4      p\        4       pV F%  pV P                  V4      pVP                  V4       K'  	  W#3# )zp
Get input names to all nodes in all subgraphs where subgraphs are
graph attributes of a node in the main graph
c                 ó"   <€ V P                   S9   # r   )r¨   )r8   Úops_with_graph_attrss   &€r   Ú<lambda>Ú:OnnxModel._get_subgraph_nodes_and_inputs.<locals>.<lambda>µ  s   ø€ °$·,±,ÐBVÒ2Vr   )rF   Úfilterr   r7   r8   rJ  r˜  r2   )r   rœ  Úsubgraph_nodesr–  Úparent_nodeÚsubgraph_inputs_of_parent_nodes   &f    r   Ú_get_subgraph_nodes_and_inputsÚ(OnnxModel._get_subgraph_nodes_and_inputs°  sg   ø€ ô
 œfÔ%VÐX\×XbÑXb×XhÑXh×XmÑXmÓnÓoˆÜ #£ÐÛ)ˆKØ-1×-NÑ-NÈ{Ó-[Ð*Ø!×(Ñ(Ð)GÖHñ *ð Ð4Ð4r   c                ó8	  € Vf:   V P                   P                  P                   Uu. uF  q3P                  NK  	  upMTpV P	                  RR7      pV P                  4       pR p\        V P                  4       4      ^8”  d™   V P                  0 RmR7      w  r‰\        V4      ^ 8X  d   \        P                  R4       R# V P                   P                  P                   F7  p
W¨9   d   K  V
P                   F  pW99   g   K  W59  g   K  WC.,          pK  	  K9  	  / p\        4       pV F"  pW69   g   K  VP                  Wc,          4       K$  	  \        V4      ^ 8”  d}   VP                  4       p
V! V
4      pV'       g   K2  WÛ9  g   K:  W«V&   V
P                   F<  p\        V4      ^ 8”  g   K  Wæ9   g   K  Wë9  g   K%  VP!                  Wn,          4       K>  	  KŒ  . p^ pV P                   P                  P                   Fb  p
V! V
4      pVP#                  V4      pV'       d6   VP$                  V
P$                  8X  d   VV
8X  d   VP                  V
4       KY  V^,          pKd  	  RV n        V P                   P                  P)                  R4       V P                   P                  P                  P+                  V4       . pVe„   V P                   P                  P                   F'  pVP                  V9  g   K  VP                  V4       K)  	  V F2  pV P                   P                  P                  P-                  V4       K4  	  . pV'       d‹   V P	                  4       pV P                   P                  P                   Uu. uF  pVP                  V9  g   K  VNK  	  ppV F2  pV P                   P                  P                  P-                  V4       K4  	  V'       g   V'       g   V^ 8”  d�   . pV'       d   VP                  \        V4       R24       V'       d   VP                  \        V4       R	24       V^ 8”  d   VP                  V R
24       \        P/                  RRP1                  V4      4       V P3                  4        R# u upi u upi )aŸ  
Prune graph to keep only required outputs. It removes unnecessary nodes that are not linked
(directly or indirectly) to any required output.

There is also an option to remove graph inputs that are not used to generate any required output.

Args:
    outputs (list): a list of graph outputs to retain. If it is None, all graph outputs will be kept.
    allow_remove_graph_inputs (bool): allow remove graph inputs.
NT)r;   c                 óÔ   € V P                   ^ ,          '       d   V P                   ^ ,          # \        \        V P                    Uu. uF  q'       g   K  VNK  	  up4      R4      # u upi rá   )rA   ÚnextÚiter)r8   Úos   & r   Úget_first_outputÚ/OnnxModel.prune_graph.<locals>.get_first_outputÍ  sI   € Ø�{‰{˜1�~Œ~Ø—{‘{ 1•~Ð%Üœ¨¯ªÓ:© A»Ÿa˜a©Ñ:Ó;¸TÓBÐBùÒ:s   Á	A%ÁA%)rœ  z)Skip prune_graph since graph has subgraphr8   z inputsz outputsz nodesz
Removed %sz, >   ÚIfÚLoopÚScan)r   r7   rA   r]   r<   rB   ro   rK   r£  rv   rº   r8   r   r:   rQ   r9   râ   Úgetr¨   r#   rh  r   ru   rD  ÚjoinÚupdate_graph)r   rp   Úallow_remove_graph_inputsrA   Úkeep_outputsÚ"input_name_to_nodes_for_main_graphrB   rª  r   r–  r8   Úoutput_to_noderå   Úfirst_outputr]   Únodes_to_keepÚnum_nodes_removedÚ	kept_nodeÚoutput_to_removeÚinput_to_remover<   r9   Úremoveds   &&&                    r   rE  ÚOnnxModel.prune_graph¼  sË  € ð OVÊo°$·*±*×2BÑ2B×2IÒ2IÓJÑ2I¨ŸœÑ2IÒJÐcjˆà-1×-EÑ-EÐX\Ð-EÓ-]Ð*Ø"×6Ñ6Ó8Ðò	Cô
 ˆt�{‰{‹}Ó Ô!à48×4WÑ4WÚ%;ð 5Xó 5Ñ1ˆNô �>Ó" aÔ'ä—‘ÐHÔIÙð Ÿ
™
×(Ñ(×-Ô-�ð Ô)Ùð #Ÿkœk�FØÖ6¸6Ö;kØ$¨Õ0šó *ñ .ð ˆô ‹WˆÛ"ˆFØÖ,Ø—	‘	Ð-Õ5Ö6ñ #ô �"‹g˜ŒkØ—6‘6“8ˆDÙ+¨DÓ1ˆLß‰| Ö!CØ/3˜|Ñ,Ø ŸJœJ�DÜ˜4“y 1–}¨$Ö*EÈDÖLfØŸ™Ð&9Õ&?Ö@ó 'ð
 ˆØÐØ—J‘J×$Ñ$×)Ô)ˆDÙ+¨DÓ1ˆLØ&×*Ñ*¨<Ó8ˆI÷ ˜Y×.Ñ.°$·,±,Ô>À9ÐPTÔCTØ×$Ñ$ TÖ*à! QÕ&Ò!ñ *ð ð 	Œð 	�
‰
×Ñ×#Ñ# FÔ+Ø�
‰
×Ñ×Ñ×$Ñ$ ]Ô3ð ÐØÒØŸ*™*×*Ñ*×1Ô1�Ø—;‘; gÖ-Ø$×+Ñ+¨FÖ3ñ 2ó +�Ø—
‘
× Ñ ×'Ñ'×.Ñ.¨vÖ6ñ +ð ˆß$Ø"&×":Ñ":Ó"<ÐØ26·*±*×2BÑ2B×2HÒ2HÓrÑ2H¨ÈEÏJÉJÐ^qÑLqŸu˜uÑ2HˆOÐrÛ'�Ø—
‘
× Ñ ×&Ñ&×-Ñ-¨dÖ3ñ (÷ ×.Ð2CÀaÔ2GØˆGßØ—‘¤# oÓ"6Ð!7°wÐ?Ô@ßØ—‘¤#Ð&6Ó"7Ð!8¸ÐAÔBØ  1Ô$Ø—‘Ð"3Ð!4°FÐ;Ô<Ü�K‰K˜ d§i¡i°Ó&8Ô9à×ÑÖùòC Kùòf ss   §RÎRÎRc                óÚ  € V P                   P                  p\        4       pVP                   Fd  pVP                  R9   d#   V P                  V4      pVP                  V4       VP                  R8w  g   KI  VP                  VP                  4       Kf  	  V'       d   \        P                  RV 24       . pV'       d\   VP                   F'  pVP                  V9  g   K  VP                  V4       K)  	  V F  pVP                  P                  V4       K   	  V Uu. uF  qˆP                  NK  	  p	p\        P                  R\        V4       RV	 24       . p
. pVP                   Fc  pVP                  V9  d5   V P                  VP                  4      '       g   V
P                  V4       KH  VP                  VP                  4       Ke  	  V
 F  pVP                  P                  V4       K   	  V
 Uu. uF  qÌP                  NK  	  p	p\        P                  R\        V
4       RV	 24       V'       d   \        P                  RV 24       V P!                  4        R# u upi u upi )	r­  rþ   zremaining input names: zremove z unused inputs: z unused initializers: zremaining initializers:N)r­  r®  r¬  )r   r7   rJ  r8   r¨   r˜  r2   r9   rv   rº   r]   r:   ru   ro   rŠ   r‚  r“  )r   Úverboser²  r7   Úremaining_input_namesr8   Úsubgraph_inputs_of_nodeÚinputs_to_remover9   Únames_to_removeÚweights_to_removeÚweights_to_keeprŠ   s   &&&          r   r±  ÚOnnxModel.update_graph+  s  € Ø—
‘
× Ñ ˆä #£ÐØ—J”JˆDØ�|‰|Ð5Ô5à*.×*KÑ*KÈDÓ*QÐ'Ø%×,Ñ,Ð-DÔEà�|‰|˜zÖ)Ø%×,Ñ,¨T¯Z©ZÖ8ñ ÷ Ü�L‰LÐ2Ð3HÐ2IÐJÔKð Ðß$ØŸœ�Ø—:‘:Ð%:Ö:Ø$×+Ñ+¨EÖ2ñ %ó *�Ø—‘×"Ñ" 5Ö)ñ *ñ 4DÓDÑ3C¨%Ÿ:œ:Ñ3CˆÐDÜ�‰�wœsÐ#3Ó4Ð5Ð5EÀoÐEVÐWÔXð ÐØˆØ ×,Ô,ˆKØ×ÑÐ'<Ô<ÀT×E[ÑE[Ð\g×\lÑ\l×EmÒEmØ!×(Ñ(¨Ö5à×&Ñ& {×'7Ñ'7Ö8ñ	 -ó
 -ˆKØ×Ñ×$Ñ$ [Ö1ñ -ñ @QÓQÑ?P°×+Ô+Ñ?PˆÐQÜ�‰�wœsÐ#4Ó5Ð6Ð6LÈ_ÐL]Ð^Ô_ßÜ�L‰LÐ2°?Ð2CÐDÔEà×#Ñ#Ö%ùò' Eùò Rs   ÄI#Ç7I(c                óÀ   € V FW  pVP                    FD  pWb9   d   K  Wc9   g   K  W6,           F%  pWq9  g   K  \        P                  R VV4          R# 	  KF  	  KY  	  R# )z<it is not safe to remove nodes since output %s is used by %sFT)rA   rv   rº   )r   r{   r³  r<   rB   Únode_to_removerº  Úimpacted_nodes   &&&&&   r   Úis_safe_to_fuse_nodesÚOnnxModel.is_safe_to_fuse_nodesX  sb   € Û-ˆNØ$2×$9Ô$9Ð Ø#Ô3Ùà#Ö:Ø)<×)NÐ)N˜Ø(Ö?Ü"ŸL™LØ ^Ø 0Ø -ôô
 $)ó *Oó %:ñ .ñ r   c                ób  € \        4       p\        4       p. pV P                   Uu. uF  qUP                  NK  	  ppV P                   Uu. uF  qwP                  NK  	  ppWh,           p	V'       d   V	P	                  4        V	 F  p
VP                  V
4       K  	  RpV'       g   V P                  M\        V P                  R R7      pRp\        V4      \        V4      8w  EdD   \        V4      V8X  d   EM1\        V4      p\        V4       EF  w  rïWã9   d   K  \        R VP                   4       4      pV^ 8X  dS   VP                  V4       VP                  V4       VP                   F  pV'       g   K  VP                  V4       K   	  Kƒ  RpVP                   F#  p
V
'       g   K  W¢9  g   K  RpVP                  pK%  	  V'       gT   VP                  V4       VP                  V4       VP                   F  pV'       g   K  VP                  V4       K   	  EK  EK  	  EK]  \        V4      \        V P                  4      8w  d1   \        R\        V4       R\        V P                  4       R	V 24      hV P                  R
4       V P                  P                  V4       R# u upi u upi )r�  c                 ó   € V P                   # r   )r]   )Úxs   &r   r�  Ú2OnnxModel.graph_topological_sort.<locals>.<lambda>z  s   € Ð_`×_eÒ_er   ©rp  Nc              3   ó8   "  € T F  q'       g   K  ^x € K  	  R# 5i)r�  N© )Ú.0rt  s   & r   Ú	<genexpr>Ú3OnnxModel.graph_topological_sort.<locals>.<genexpr>„  s   é € Ð!=©Z¨»1§!¢!«Zùs   ‚	�
FTz)Graph is not a DAG: len(sorted_node_set)=z, len(graph.node)=z, failed at node r8   rÇ   )rJ  rŠ   r]   r9   ÚsortÚaddr8   Úsortedro   rn   Úsumr:   rA   ÚRuntimeErrorrh  r   )r7   Úis_deterministicÚdeps_setÚsorted_node_setÚsorted_nodesÚinitÚinitializer_namesr9   rO  r^   r>   Úsorted_node_set_lenÚgraph_nodesÚlast_node_nameÚnode_idxr8   Úinput_countrA   Úfaileds   &&                 r   Úgraph_topological_sortÚ OnnxModel.graph_topological_sorti  sC  € ä“5ˆÜ›%ˆØˆà38×3DÒ3DÓEÑ3D¨4ŸYœYÑ3DÐÐEØ5:·[²[ÓA±[¨EŸZœZ±[ÐÐAØ'Õ;ˆçØ×ÑÔã%ˆJØ�L‰L˜Ö$ñ &ð !Ðß(8�e—j’j¼fÀUÇZÁZÑUeÔ>fˆàˆÜ�/Ó"¤c¨+Ó&6Õ6Ü�?Ó#Ð':Ô:ÙÜ"% oÓ"6ÐÜ"+¨K×"8‘�ØÔ.ÙÜ!Ñ!=¨T¯ZªZÓ!=Ó=�Ø !Ô#Ø ×'Ñ'¨Ô-Ø#×'Ñ'¨Ô1Ø"&§+¤+˜ß!™6Ø$ŸL™L¨Ö0ñ #.ñ Ø�Ø"&§*¤*�Jß!‘z jÖ&@Ø!%˜Ø)-¯©šñ #-÷ Ø ×'Ñ'¨Ô-Ø#×'Ñ'¨Ô1Ø"&§+¤+˜ß!™6Ø$ŸL™L¨Ö0ô #.ò ô/ #9ô2 ˆÓ¤3 u§z¡z£?Ô2ÜØ;¼CÀÓ<PÐ;QÐQcÔdgÐhm×hrÑhrÓdsÐctð  uFð  GUð  FVð  Wóð ð 	×Ñ˜Ô Ø�
‰
×Ñ˜,Ö'ùòc FùÚAs   ¥J'Á	J,c                ó  €  \         P                  V P                  P                  V4       R#   \         dH   pT'       d9   \
        P                  R 4       \         P                  T P                  RRRR7       ThRp?ii ; i)zaFailed to sort graph in topological order. Dumping model to _topo_sort_failed.onnx for debugging.z_topo_sort_failed.onnxT)Úsave_as_external_dataÚall_tensors_to_one_fileN)r   rç  r   r7   rÚ  rv   rD  Úsave)r   rÛ  Údump_model_on_failureÚes   &&& r   Útopological_sortÚOnnxModel.topological_sort¢  sn   € ð
	Ü×,Ñ,¨T¯Z©Z×-=Ñ-=Ð?OÖPøÜô 	ß$Ü—‘Øwôô —‘Ø—J‘JÐ 8ÐPTÐnrð ô ð ˆGûð	ús   ‚*. ®B ¹AA;Á;B c           
     óB  € \        V4      P                  P                  R R R7       V P                   Uu. uF  qfP                  R8X  g   K  VNK  	  ppV P
                  P                   Uu. uF  qˆP                  R8X  g   K  VNK  	  p	pV	'       d1   V'       g)   V P                  P                  4       p^Vn        RVn        V'       Ed?   \        V4      P                  p
V
P                  R R R7       VR,           pV'       d   \        V4      P                  MRp\        P                  P                  V4      '       d/   \        P                  RV 24       \        P                  ! V4       V'       dU   \        P                  P                  V4      '       d/   \        P                  RV 24       \        P                  ! V4       M+\        P                   ! V
4      '       d   \#        RV
 R24      h\%        V VR VVVVR	7       R# \%        W4       R# u upi u upi )
T)r±   Úexist_okzcom.microsoftz.dataNzDelete the existing onnx file: z(Delete the existing external data file: zOutput directory (z!) for external data is not empty.)rê  rë  ÚlocationÚsize_thresholdÚconvert_attribute)r   r½   ÚmkdirÚopset_importÚdomainr7   r8   r×  Úversionr]   ÚosrË   Úexistsrv   rD  ru   ÚlistdirrÚ  r   )r   Úoutput_pathrê  rë  rô  rõ  ÚopsetÚms_opsetr8   Úms_nodeÚ
output_dirÚexternal_data_pathró  s   &&&&&&       r   rì  ÚOnnxModel.save²  s°  € ô 	ˆ[Ó× Ñ ×&Ñ&¨t¸dÐ&ÔCð (-×'9Ò'9Ó]Ñ'9˜e¿\¹\È_Ñ=\—E�EÑ'9ˆÐ]ð %*§K¡K×$4Ò$4ÓWÑ$4˜D¿¹ÀÑ8V—4�4Ñ$4ˆÐWßŸ8Ø×&Ñ&×*Ñ*Ó,ˆEØˆEŒMØ*ˆEŒLç Ð ä˜kÓ*×1Ñ1ˆJØ×Ñ T°DÐÔ9Ø!,¨wÕ!6Ðß8O”tÐ.Ó/×4Ò4ÐUYˆHä�w‰w�~‰~˜k×*Ò*Ü—‘Ð=¸k¸]ÐKÔLÜ—	’	˜+Ô&ç&Ü—7‘7—>‘>Ð"4×5Ò5ä—K‘KÐ"JÐK]ÐJ^Ð _Ô`Ü—I’IÐ0Ô1øä—:’:˜j×)Ò)Ü&Ð);¸J¸<ÐGhÐ'iÓjÐjäØØØ&*Ø(?Ø!Ø-Ø"3÷ô �uÖ*ùòO ^ùò Xs   µHÁHÁ,HÂHc                óÈ   € \         P                  R 4       V P                  4        \        P	                  V P
                  VVVVV4       \         P                  RV 24       R# )z Sort graphs in topological orderzModel saved to N)rv   rD  rï  r   rì  r   )r   rý  Úuse_external_data_formatrë  rô  rõ  s   &&&&&&r   Úsave_model_to_fileÚOnnxModel.save_model_to_fileç  sV   € ô 	�‰Ð6Ô7Ø×ÑÔô 	�‰Ø�J‰JØØ$Ø#ØØô	
ô 	�‰�o k ]Ð3Ö4r   c                ó¸   € . pV P                   P                  P                   F3  pV P                  VP                  4      e   K"  VP                  V4       K5  	  V# )zK
Returns real graph inputs (excluding initializers from older onnx model).
)r   r7   r9   r¥   r]   r:   )r   rˆ  r9   s   &  r   Ú'get_graph_inputs_excluding_initializersÚ1OnnxModel.get_graph_inputs_excluding_initializers   sN   € ð ˆØ—Z‘Z×%Ñ%×+Ô+ˆEØ×#Ñ# E§J¡JÓ/Ô7Ø×#Ñ# EÖ*ñ ,ð Ðr   c                ó�   € V P                   P                   F"  pVP                  R9   g   K  VP                  u # 	  \	        R4      h)z™Get opset version of onnx domain

Raises:
    RuntimeError: ONNX model has no opset for default domain.

Returns:
    int: opset version of onnx domain.
z*ONNX model has no opset for default domain)Ú zai.onnx)r   r÷  rø  rù  rÚ  )r   rþ  s   & r   Úget_opset_versionÚOnnxModel.get_opset_version
  s<   € ð —Z‘Z×,Ô,ˆEØ�|‰|˜Ö.Ø—}‘}Ò$ñ -ô ÐGÓHÐHr   c                óN  € / pV P                  4        F\  pV'       d&   VP                  '       d   VP                  R,           MRVP                  ,           pWB9  d   ^MW$,          ^,           W$&   K^  	  \        P	                  R\        VP                  4       R R7       24       V# )z"
Returns node count of operators.
Ú:r  z
Operators:c                 ó(   € V ^,          ) V ^ ,          3# )r�  rÒ  )Úkvs   &r   r�  Ú3OnnxModel.get_operator_statistics.<locals>.<lambda>"  s   € È2ÈaÍ5È&ÐRTÐUVÕRWÉr   rÐ  )r6   rø  r¨   rv   rD  rØ  Úitems)r   Úinclude_domainÚop_countr8   Úops   &&   r   Úget_operator_statisticsÚ!OnnxModel.get_operator_statistics  s~   € ð ˆØ—J‘J–LˆDß'5¸$¿+¿+¸+�$—+‘+ Ö#È2ÐQU×Q]ÑQ]Õ]ˆBØ "Ô 2™1¸½ÈÕ9IˆH‹Lñ !ô
 	�‰�j¤¨¯©Ó(8Ñ>XÔ!YÐ ZÐ[Ô\àˆr   c                ó,   <€ V ^8„  d   QhRS[ RS[RS[/# )rê   r‹   Úbase_dirÚreturn)r
   r’   rì   )rí   rî   s   "€r   rï   rð   '  s"   ø€ ÷ +ñ +™[ð +±Cð +Áñ +r   c                ó’  € V P                  R4      '       d   \        R4      hV P                  \        P                  8X  d   \        R4      hV P                  p\        P                  ! V4      pV P                  \        P                  8X  dE   \        W4      p\        \        ;QJ d    . R V 4       F  NK  	  54      # ! R V 4       4      4      # \        V 4      '       d   \        W4       V P                  R4      '       d   \        V P                  4      # \        P                   ! V 4      p\        VP#                  4       4      # )zæConverts a tensor def object to a hash for data comparison purposes.
Args:
    tensor: a TensorProto object.
    base_dir: if external tensor exists, base_dir can help to find the path to it
Returns:
    hash: a hash of the data.
Úsegmentz*Currently not supporting loading segments.z4The element type in the input tensor is not defined.c              3   óB   "  € T F  qP                  R 4      x € K  	  R# 5i)zutf-8N)Údecode)rÓ  Úss   & r   rÔ  Ú)OnnxModel.to_data_hash.<locals>.<genexpr>8  s   é € ÐF¹°AŸh™h w×/Ð/»ùs   ‚Úraw_data)r$  rx  r3  r
   rf  Ú	TypeErrorr   Útensor_dtype_to_fieldÚSTRINGÚgetattrÚhashrÈ   r   r   r#  r   r   Útobytes)r‹   r  Útensor_dtypeÚstorage_fieldÚutf8_stringsÚnp_datas   &&    r   Úto_data_hashÚOnnxModel.to_data_hash&  sõ   € ð �?‰?˜9×%Ò%ÜÐIÓJÐJØ×Ñœ{×4Ñ4Ô4ÜÐRÓSÐSØ×'Ñ'ˆÜ×4Ò4°\ÓBˆà×Ñœ{×1Ñ1Ô1Ü" 6Ó9ˆLÜŸœÑF¹ÓFŸÓGÐG˜ÑF¹ÓFÓFÓGÐGä˜f×%Ò%Ü)¨&Ô;Ø�?‰?˜:×&Ò&Ü˜Ÿ™Ó(Ð(ä"×+Ò+¨FÓ3ˆGÜ˜Ÿ™Ó)Ó*Ð*r   c                ó`   <€ V ^8„  d   QhRS[ RS[ RS[R,          RS[R,          RS[RS[RS[/# )	rê   Útensor1Útensor2Úsignature_cache1NÚsignature_cache2ÚrtolÚatolr  )r
   ÚdictÚfloatrK  )rí   rî   s   "€r   rï   rð   C  sW   ø€ ÷ /ñ /Ùð/áð/ñ  �+ð/ñ  �+ð	/ñ
 ð/ñ ð/ñ 
ñ/r   c                ób  € V'       d$   V P                   V9   d   W P                   ,          M\        P                  V 4      pV'       d$   VP                   V9   d   W1P                   ,          M\        P                  V4      pVe   WbV P                   &   Ve   WsVP                   &   V P                  VP                  8X  dp   V P                  VP                  8X  dU   \
        P                  ! V 4      p\
        P                  ! V4      p	Wg8X  d   W‰8H  P                  4       # ^ RIH	p
 V
! W‰WER7      # R# )aˆ  Returns True when two tensors have same value.
   Note that name can be different.

Args:
    tensor1 (TensorProto): initializer 1
    tensor2 (TensorProto): initializer 2
    signature_cache1 (dict): Optional dictionary to store data signatures of tensor1 in order to speed up comparison.
    signature_cache2 (dict): Optional dictionary to store data signatures of tensor2 in order to speed up comparison.
    rtol (float): Optional relative difference threshold for minor precision differences
    atol (float): Optional absolute difference threshold for minor precision differences
Returns:
    bool: True when two initializers has same value.
)Úallclose)r5  r6  F)
r]   r   r.  r3  r9  r   r   ÚallÚnumpyr:  )r1  r2  r3  r4  r5  r6  Úsig1Úsig2Ún1Ún2r:  s   &&&&&&     r   Úhas_same_valueÚOnnxModel.has_same_valueB  sô   € ÷0   G§L¡LÐ4DÔ$Dð Ÿ\™\Ö*ä×'Ñ'¨Ó0ð 	÷   G§L¡LÐ4DÔ$Dð Ÿ\™\Ö*ä×'Ñ'¨Ó0ð 	ð
 Ò'Ø-1˜WŸ\™\Ñ*ØÒ'Ø-1˜WŸ\™\Ñ*Ø×Ñ × 1Ñ 1Ô1°g·l±lÀgÇlÁlÔ6RÜ×&Ò& wÓ/ˆBÜ×&Ò& wÓ/ˆBØŒ|à™—~‘~Ó'Ð'õ +á ¨TÔ=Ð=ár   c                ó¼   € V P                  4        F1  pWP                  9   g   K  VP                  P                  V4        R # 	  \        P	                  RV4       R # )NzFailed to remove initializer %s)rK   rŠ   ru   rv   rw   )r   r‹   r7   s   && r   Úremove_initializerÚOnnxModel.remove_initializert  sF   € Ø—[‘[–]ˆEØ×*Ñ*Ö*Ø×!Ñ!×(Ñ(¨Ô0Úñ #ô 	�‰Ð8¸&ÖAr   c                ó.   <€ V ^8„  d   QhRS[ R,          /# )rê   ÚcacheN)r7  )rí   rî   s   "€r   rï   rð   {  s   ø€ ÷ #Iñ #I±4¸$µ;ñ #Ir   c                óÆ  € \        V P                  4       4      ^8”  d   \        P                  R4       \        V P                  P
                  P                  4      pR.V,          p\        V^,
          4       Fš  pW4,          ^ 8¼  d   K  \        V^,           V4       Fq  p\        P                  V P                  P
                  P                  V,          V P                  P
                  P                  V,          VV4      '       g   Km  WCV&   Ks  	  Kœ  	  ^ p\        V4       F‘  pW4,          ^ 8¼  g   K  V^,          pV P                  V P                  P
                  P                  V,          P                  V P                  P
                  P                  W4,          ,          P                  4       K“  	  V^ 8”  d"   V P                  4        \        RV R24       R# R# )a  Remove initializers with duplicated values, and only keep the first one.
It could help reduce size of models (like ALBert) with shared weights.
If require_raw_data passed, method will only compare raw_data initializers to speed runtime
Note: this function does not process subgraph.
z9remove_duplicated_initializer does not process subgraphs.zRemoved z# initializers with duplicated valueNrÇ   )ro   rK   rv   rw   r   r7   rŠ   r“   r   rA  rš   r]   r±  r.   )r   rG  Úinitializer_countÚsamerµ   r–   Úcounts   &&     r   Úremove_duplicated_initializerÚ'OnnxModel.remove_duplicated_initializer{  sv  € ô ˆt�{‰{‹}Ó Ô!Ü�N‰NÐVÔWä §
¡
× 0Ñ 0× <Ñ <Ó=ÐàˆtÐ'Õ'ˆÜÐ(¨1Õ,Ö-ˆAØ�w˜!Œ|ÙÜ˜1˜q�5Ð"3Ö4�Ü×+Ñ+Ø—J‘J×$Ñ$×0Ñ0°Õ3Ø—J‘J×$Ñ$×0Ñ0°Õ3ØØ÷	ô ð  ˜“Gó 5ñ .ð ˆÜÐ(Ö)ˆAØ�w˜!Ž|Ø˜•
�Ø×/Ñ/Ø—J‘J×$Ñ$×0Ñ0°Õ3×8Ñ8Ø—J‘J×$Ñ$×0Ñ0°µÕ9×>Ñ>öñ *ð �1Œ9Ø×ÑÔÜ�H˜U˜GÐ#FÐGÖHñ r   c                ó    <€ V ^8„  d   QhRS[ /# )rê   rz  ©r’   )rí   rî   s   "€r   rï   rð      s   ø€ ÷  ;ñ  ;©#ñ  ;r   c                óZ  € \        V P                  4       4      ^8”  d   \        P                  R4       V P                  P
                  P                   Uu. uF  q"P                  NK  	  upV P                  P
                  P                   Uu. uF  q3P                  NK  	  up,           R.,           pV P                  P
                  P                   FF  pVP                  V9  g   K  WP                  ,           V9  g   K/  WP                  ,           Vn        KH  	  V P                  P
                  P                   EF  p\        \        VP                  4      4       Fc  pVP                  V,          V9  g   K  WP                  V,          ,           V9  g   K=  WP                  V,          ,           VP                  V&   Ke  	  \        \        VP                  4      4       Fc  pVP                  V,          V9  g   K  WP                  V,          ,           V9  g   K=  WP                  V,          ,           VP                  V&   Ke  	  EK  	  V P                  P
                  P                   F-  pVP                  V9  g   K  WP                  ,           Vn        K/  	  R# u upi u upi )zåAdd prefix to initializer or intermediate outputs in graph. Main graph inputs and outputs are excluded.
It could help avoid conflicting in name of node_args when merging two graphs.
Note: this function does not process subgraph.
z/add_prefix_to_names does not process subgraphs.r  N)ro   rK   rv   rw   r   r7   r9   r]   rA   rŠ   r8   r“   r1  )	r   rz  rµ   r©  ÚexcludedrŠ   r8   r–   r1  s	   &&       r   Úadd_prefix_to_namesÚOnnxModel.add_prefix_to_names   sÊ  € ô
 ˆt�{‰{‹}Ó Ô!Ü�N‰NÐLÔMð %)§J¡J×$4Ñ$4×$:Ò$:Ó;Ñ$:˜q—F”FÑ$:Ñ;ÈtÏzÉz×O_ÑO_×OfÒOfÓ>gÑOfÈ!¿v¼vÑOfÑ>gÕgÐkmÐjnÕnˆàŸ:™:×+Ñ+×7Ô7ˆKØ×Ñ xÖ/Ø×,Ñ,Õ,°HÖ<Ø'-×0@Ñ0@Õ'@�KÖ$ñ 8ð
 —J‘J×$Ñ$×)Õ)ˆDäœ3˜tŸz™z›?Ö+�Ø—:‘:˜a•=¨Ö0Ø§
¡
¨1¥Õ-°XÖ=Ø(.·±¸AµÕ(>˜Ÿ
™
 1›ñ ,ô œ3˜tŸ{™{Ó+Ö,�Ø—;‘;˜q•>¨Ö1Ø§¡¨A¥Õ.°hÖ>Ø)/·+±+¸aµ.Õ)@˜Ÿ™ A›ô -ñ *ð Ÿ*™*×*Ñ*×5Ô5ˆJØ�‰ hÖ.Ø"(¯?©?Õ":�
–ó 6ùò) <ùÒ>gs   ÁJ#ÂJ(c                óP   € V P                   P                  P                  R 4       R# )r1  N)r   r7   rh  r(   s   &r   Úclean_shape_inferÚOnnxModel.clean_shape_inferÂ  s   € Ø�
‰
×Ñ×#Ñ# LÖ1r   c                óì  € . pVP                  V P                  P                  4       V'       EdÄ   . pV EFµ  p\        V\        4      '       g   K  \
        P                  ! VP                  VP                  VP                  4       F¨  pVP                  P                  P                  \        P                  8X  d     R# VP                  P                  R4      '       g   K]  VP                  P                   P                  P                  P                  \        P                  8X  g   K¦    R# 	  VP"                   F&  pVP$                  \        P                  8X  g   K$    R# 	  VP&                   EFp  pVP(                  R8X  dK   VP*                   F:  pVP,                  R8X  g   K  VP.                  \        P                  8X  g   K7     R# 	  VP*                   EF   pVP                  \0        P2                  8X  d   VP                  VP4                  4       VP6                   F  pVP                  V4       K  	  \        VP8                  \        4      '       d/   VP8                  P$                  \        P                  8X  d      R# VP:                   F@  p\        V\        4      '       g   K  VP$                  \        P                  8X  g   K<      R# 	  EK  	  EKs  	  EK¸  	  TpEKÌ  R# )z$Check whether the model uses float16TÚsequence_typerC  ÚtoF)r:   r   r7   rV   r   r/  r0  r9   rA   r1  rS   r%  r2  r
   ÚFLOAT16r$  rX  rŠ   r3  r8   r¨   rR   r]   rµ   r   rU   rW   rK   r  Útensors)	r   ÚqueueÚ
sub_graphsr7   Úvr  r8   rZ   rW   s	   &        r   Úuse_float16ÚOnnxModel.use_float16Å  sò  € àˆØ�‰�T—Z‘Z×%Ñ%Ô&ßˆeØˆJÜ�Ü! %¬×4Ò4Ùä"Ÿš¨¯©°e·l±lÀE×DTÑDTÖU�AØ—v‘v×)Ñ)×3Ñ3´{×7JÑ7JÔJÛ#Ø—v‘v—‘ ×7Ô7ØŸ6™6×/Ñ/×9Ñ9×EÑE×OÑOÔS^×SfÑSfÖfÛ#'ñ Vð ×*Ô*�AØ—{‘{¤k×&9Ñ&9Ö9Û#ñ +ð "ŸJ�J�DØ—|‘| vÔ-Ø$(§N¤N˜DØ#Ÿy™y¨DÖ0°T·V±V¼{×?RÑ?RÖ5RÜ'+ñ %3ð !%§¥˜ØŸ9™9¬×(<Ñ(<Ô<Ø&×-Ñ-¨d¯f©fÔ5à!%§¤˜AØ&×-Ñ-¨aÖ0ñ "-ô & d§f¡f¬k×:Ò:¸t¿v¹v×?OÑ?OÔS^×SfÑSfÔ?fÜ#'à!%§¤˜AÜ)¨!¬[×9Ô9¸a¿k¹kÌ[×M`ÑM`Ö>`Ý'+ô ".ô !/ô 'ñ ðF ‹Eár   c                ó&   <€ V ^8„  d   QhRS[ RS[/# )rê   Úgraph_inputÚnew_type©r   rì   )rí   rî   s   "€r   rï   rð   ò  s   ø€ ÷ =.ñ =.á#ð=.ñ ñ=.r   c                ó¤  € \        V\        4      '       g   Q hV P                  VP                  4      '       g   Q hVP                  P
                  P                  \        V4      8X  d   R. 3# V P                  4       pRp. pV P                  4       pVP                  V9   Edþ   WaP                  ,          pV Uu. uF  qˆP                  R8w  g   K  VNK  	  p	pV	'       dð   V P                  R4      p
V
R,           VP                  ,           pVP                  P                  4       pVP                  V4       W¼n        \        P                   ! RVP                  .V.\        VP                  P
                  P                  4      V
R7      pVP"                  P%                  V.4       V	 F#  p\&        P)                  W�P                  V4       K%  	  V Uu. uF  qˆP                  R8X  g   K  VNK  	  ppV F�  p\&        P+                  VR4      \        V4      8X  d.   V P-                  VP.                  ^ ,          VP                  4       V P1                  VP.                  ^ ,          4      '       d   K~  VP3                  V4       K‘  	  V'       d   V P5                  V4       \        V4      VP                  P
                  n        WE3# u upi u upi )a9  Change graph input type, and add Cast node if needed.

Args:
    graph_input (ValueInfoProto): input of the graph
    new_type (int): new data type like TensorProto.INT32.

Returns:
    NodeProto: a new Cast node that added. None if Cast node is not added.
    List[NodeProto]: Cast nodes that have been removed.
NrC  rt  ©rY  r]   rY  )rV   r   r  r]   rS   r%  r2  rì   r7   r<   r¨   r|  r1  r×  rg  r   Ú	make_noder8   r   r   r—   r@  rš   rA   r‚  r:   r|   )r   rb  rc  r7   Únew_cast_noder{   r<   r6   r8   Únodes_not_castÚ	node_namerC   Únew_value_infoÚ
nodes_casts   &&&           r   Úchange_graph_input_typeÚ!OnnxModel.change_graph_input_typeò  sL  € ô ˜+¤~×6Ò6Ð6Ð6Ø×$Ñ$ [×%5Ñ%5×6Ò6Ð6Ð6à×Ñ×'Ñ'×1Ñ1´S¸³]ÔBØ˜�8ˆOà—
‘
“ˆØˆØˆà"×6Ñ6Ó8ÐØ×ÑÐ2Õ2Ø'×(8Ñ(8Õ9ˆEñ 05ÓO©u t¿¹ÈÑ8NŸd˜d©uˆNÐOßØ ×1Ñ1°&Ó9�	Ø'¨#�o°×0@Ñ0@Õ@�Ø!&×!1Ñ!1×!5Ñ!5Ó!7�Ø×'Ñ'¨Ô4Ø&1Ô#Ü &× 0Ò 0ØØ ×%Ñ%Ð&Ø �MÜ˜;×+Ñ+×7Ñ7×AÑAÓBØ"ô!�ð —
‘
×!Ñ! = /Ô2ã*�DÜ×0Ñ0°×7GÑ7GÈÖUñ +ñ
 ,1ÓK©5 4·L±LÀFÑ4JŸ$˜$©5ˆJÐKÛ"�Ü×/Ñ/°°dÓ;¼sÀ8»}ÔLØ×3Ñ3°D·K±KÀµNÀK×DTÑDTÔUØ×-Ñ-¨d¯k©k¸!­n×=Ô=Ø#×*Ñ*¨4Ö0ñ	 #÷
 Ø×!Ñ! /Ô2ä14°X³ˆ×Ñ×$Ñ$Ô.ØÐ-Ð-ùò? Pùò* Ls   Â:KÃKÇKÇ+Kc                ó&   <€ V ^8„  d   QhRS[ RS[/# )rê   Úgraph_outputrc  rd  )rí   rî   s   "€r   rï   rð   1  s   ø€ ÷ 'ñ 'á$ð'ñ ñ'r   c                óÐ  € \        V\        4      '       g   Q hV P                  VP                  4      '       g   Q hVP                  P
                  P                  \        V4      8X  d   R# RpV P                  4       pV P                  R4      pVR,           VP                  ,           pV P                  VP                  V4       VP                  P                  4       pVP                  V4       Wgn        \        P                  ! RV.VP                  .\        V4      VR7      pVP                   P#                  V.4       \        V4      VP                  P
                  n        V# )zñChange graph input type, and add Cast node if needed.

Args:
    graph_input (str | ValueInfoProto): output of the graph
    new_type (int): new data type.

Returns:
    NodeProto: a new Cast node that added. None if Cast node is not added.
NrC  rt  rf  )rV   r   r‚  r]   rS   r%  r2  rì   r7   r|  rš   r1  r×  rg  r   rg  r8   r   )r   rp  rc  Ú	cast_noder7   rj  r>   rk  s   &&&     r   Úchange_graph_output_typeÚ"OnnxModel.change_graph_output_type1  s+  € ô ˜,¬×7Ò7Ð7Ð7Ø×%Ñ% l×&7Ñ&7×8Ò8Ð8Ð8à×Ñ×(Ñ(×2Ñ2´c¸(³mÔCÙàˆ	Ø—
‘
“ˆð ×)Ñ)¨&Ó1ˆ	Ø •_ |×'8Ñ'8Õ8ˆ
Ø×'Ñ'¨×(9Ñ(9¸:ÔFØ×)Ñ)×-Ñ-Ó/ˆØ×Ñ Ô-Ø(ÔÜ×$Ò$ØØˆLØ×ÑÐÜ�8‹}Øô
ˆ	ð 	�
‰
×Ñ˜9˜+Ô&Ü25°h³-ˆ×Ñ×%Ñ%Ô/ØÐr   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# )rê   Úold_nameÚnew_namerO  )rí   rî   s   "€r   rï   rð   Z  s   ø€ ÷ 
'ñ 
'©Cð 
'¹3ñ 
'r   c                ó,  € W P                  4       9   d   \        R 4      hV P                  4       pVP                   FT  pVP                  V8X  g   K  \
        P                  RW4       V P                  W4       V P                  W4       W$n        KV  	  R# )z{new_name} exists in graphz!replace output name from %s to %sN)	rB   rÚ  r7   rA   r]   rv   rº   rš   r¢   )r   rv  rw  r7   rA   s   &&&  r   Úrename_graph_outputÚOnnxModel.rename_graph_outputZ  sr   € Ø×/Ñ/Ó1Ô1ÜÐ;Ó<Ð<à—
‘
“ˆØ—l”lˆFØ�{‰{˜hÖ&Ü—‘Ð@À(ÔUØ×/Ñ/°ÔCØ×0Ñ0°ÔDØ&–ó #r   )r$   r    r%   r#   r"   r   r!   )Fr   r¹   )NNNr   )g�íµ ÷Æ°>)T)FF)FTi   F)r  )NNgñhãˆµøä>g:Œ0âŽyE>)XÚ__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r   r)   r3   r<   rB   rG   r6   r7   rK   r_   rc   rg   rk   rr   rx   r|   r‚   r‡   rŒ   r�   Ústaticmethodr—   rš   rŸ   r¢   r¥   r©   r®   r²   r¶   r¾   rÄ   rÍ   rÔ   rÉ   rç   r÷   rû   r  r  r  r  r  r  r(  r5  r:  r@  rG  rQ  rW  r   r|  r  r‚  r…  rŠ  rÁ   r“  r˜  r£  rE  r±  rÊ  rç  rï  rì  r  r	  r  r  r.  rA  rD  rL  rR  rU  r_  rm  rs  ry  Ú__static_attributes__Ú__classdictcell__)rî   s   @r   r   r      s‡  ø‡ € òò8ò(ð 8:À%ô ô
#ô#òòò òò&òòòòò9ò#ô0ô0ô/ô(ð ñ/ó ð/òOð ñ1ó ð1òRòòôô"ô*ð UWô ð6 Ø ØØô0òdò
0ô6ôpð& /3Ø Ø÷= ò = ô~ò$òôò
ôJôò2
÷ò ÷2ò ð@ ÷ó ðòò& ôDfô_)ôB!$òFòôô,ð" ñó ðòPò%ò
5ômô^+&òZð" ó6(ó ð6(ôpð  ó2+ó ð2+ôh5ò2òIôð ÷+ñ +ó ð+ð6 ÷/ñ /ó ð/òbB÷#Ið #I÷J ;ð  ;òD2ò+÷Z=.ð =.÷~'ð '÷R
'ö 
'r   r   )r/  Úloggingrú  r/   Úcollectionsr   Úpathlibr   Úfloat16r   Úonnxr   r   r   r	   r
   r   r   r   r   Úonnx.external_data_helperr   r   r!   r   Ú	getLoggerr{  rv   r   rÒ  r   r   Ú<module>r‰     sP   ðó Û Û 	Û 
Ý Ý å ,÷
÷ 
õ 
÷ XÝ ;à	×	Ò	˜8Ó	$€÷E'ó E'r   