+
    ©úÎj2)  ã                   ó¦   € ^ RI t ^ RIt^ RIt^ RIHt ^ RIt^ RIt^ RIHtH	t	 ^RI
Ht ^RIHt ^RIHtHt ] P"                  ! ]4      tR	R R lltR# )
é    N)ÚPath)Úextract_raw_data_from_modelÚhas_external_data)ÚReplaceUpsampleWithResize)Ú	ONNXModel)Úadd_pre_process_metadataÚ&save_and_reload_model_with_shape_inferc                ó8  € V ^8„  d   QhR\         \        ,          \        P                  ,          R,          R\         \        ,          R,          R\        R\        R\        R\        R\
        R	\        R
\
        R\        R\        R\         R,          R\
        RR/# )é   Úinput_modelNÚoutput_model_pathÚskip_optimizationÚskip_onnx_shapeÚskip_symbolic_shapeÚ
auto_mergeÚint_maxÚguess_output_rankÚverboseÚsave_as_external_dataÚall_tensors_to_one_fileÚexternal_data_locationÚexternal_data_size_thresholdÚreturn)Ústrr   ÚonnxÚ
ModelProtoÚboolÚint)Úformats   "Úb/opt/data/cache/scratch/pip-target-_o6w5emm/lib/python/onnxruntime/quantization/shape_inference.pyÚ__annotate__r!      sÃ   € ÷ B,ñ B,Ü”t•œdŸo™oÕ-°Õ4ðB,äœT•z DÕ(ðB,ô ðB,ô ð	B,ô
 ðB,ô ðB,ô ðB,ô ðB,ô ðB,ô  ðB,ô "ðB,ô   $�JðB,ô #&ðB,ð 
ñB,ó    c                óB
  € V f   VP                  RR4      p V f   Q hVf   Q R4       h\        P                  ! RR7      ;_uu_ 4       p\        V4      p\	        V \
        P                  4      '       d   T M\
        P                  ! V 4      pRpVP                   Uu. uF*  pVP                  '       d   VP                  R8X  g   K(  VNK,  	  pp\        V4      ^8X  dk   V^ ,          P                  pV^
8:  dQ   \        \        V4      V4      P                  4        \
        P                  P!                  V^4      p\#        V4      pRpV'       g4    ^ R	IHp \*        P-                  R4       TP/                  TTTTT4      pRpV'       Eg‡   T pV'       dO   \1        VR,          4      pV	'       d   \
        P2                  ! VVRV
VRR7       M\
        P4                  ! VV4       \1        VR,          4      p \6        P8                  ! 4       pVVn        \6        P<                  P>                  Vn         \	        V\
        P                  4      '       d`   \C        V4      '       d   \E        R4      h\G        V4      w  ppVPI                  \K        V4      \K        V4      4       VPM                  4       pM"V'       d   V	'       d   VPO                  RR4       \6        PP                  ! VVR.R7      p?V'       d   \
        P                  ! V4      pMRpTp  V'       gô   VeQ   \1        VR,          4      p V	'       d   \
        P2                  ! VV RV
VRR7       M\
        P4                  ! VV 4       Rp\	        V \
        P                  4      '       d8   \1        \        V4      R,          4      p \
        P2                  ! VV RV
VRR7       \1        VR,          4      p\
        PZ                  P]                  V V4       \
        P                  ! V4      pVf9   \	        V \
        P                  4      '       d   T M\
        P                  ! V 4      pRRR4       \_        X4       V	'       d    \
        P2                  ! VVRV
VVRR7       R# \
        P4                  ! VV4       R# u upi   \(         d   p\)        R
4      ThRp?ii ; i  \R         dB    \*        PU                  R4       \*        PU                  \V        PX                  ! 4       4        ELùi ; i  + '       g   i     LÎ; i)a(  Shape inference and model optimization, in preparation for quantization.

Args:
    input_model: Path to the input model file or ModelProto
    output_model_path: Path to the output model file
    skip_optimization: Skip model optimization step if true. This may result in ONNX shape
        inference failure for some models.
    skip_onnx_shape: Skip ONNX shape inference. Symbolic shape inference is most effective
        with transformer based models. Skipping all shape inferences may
        reduce the effectiveness of quantization, as a tensor with unknown
        shape can not be quantized.
    skip_symbolic_shape: Skip symbolic shape inference. Symbolic shape inference is most
        effective with transformer based models. Skipping all shape
        inferences may reduce the effectiveness of quantization, as a tensor
        with unknown shape can not be quantized.
    auto_merge: For symbolic shape inference, automatically merge symbolic dims when
        conflict happens.
    int_max: For symbolic shape inference, specify the maximum value for integer to be
        treated as boundless for ops like slice
    guess_output_rank: Guess output rank to be the same as input 0 for unknown ops
    verbose: Logs detailed info of inference, 0: turn off, 1: warnings, 3: detailed
    save_as_external_data: Saving an ONNX model to external data
    all_tensors_to_one_file: Saving all the external data to one file
    external_data_location: The file location to save the external file
    external_data_size_threshold: The size threshold for external data
NÚinput_model_pathzoutput_model_path is required.z
pre.quant.)ÚprefixFzai.onnxT)ÚSymbolicShapeInferencez¨sympy is required for symbolic shape inference in quantization preprocessing. Install with: 'pip install sympy' or pass skip_symbolic_shape=True to quant_pre_process().z&Performing symbolic shape inference...zpreprocessed.onnx)r   r   Úsize_thresholdÚconvert_attributezoptimized.onnxzÒModelProto has external data not loaded into memory, ORT cannot create session. Please load external data before calling this function. See https://onnx.ai/onnx/repo-docs/ExternalData.html for more information.z7session.optimized_model_external_initializers_file_namezoptimized.onnx.dataÚCPUExecutionProvider)Ú	providerszYONNX Runtime Model Optimization Failed! Consider rerun with option `--skip_optimization'.zsymbolic_shape_inferred.onnxzmodel_input.onnxzonnx_shape_inferred.onnx)r   r   Úlocationr'   r(   )0ÚpopÚtempfileÚTemporaryDirectoryr   Ú
isinstancer   r   ÚloadÚopset_importÚdomainÚlenÚversionr   r   ÚapplyÚversion_converterÚconvert_versionr	   Ú&onnxruntime.tools.symbolic_shape_inferr&   ÚImportErrorÚloggerÚinfoÚinfer_shapesr   Ú
save_modelÚsaveÚonnxruntimeÚSessionOptionsÚoptimized_model_filepathÚGraphOptimizationLevelÚORT_ENABLE_BASICÚgraph_optimization_levelr   Ú
ValueErrorr   Úadd_external_initializersÚlistÚSerializeToStringÚadd_session_config_entryÚInferenceSessionÚ	ExceptionÚerrorÚ	tracebackÚ
format_excÚshape_inferenceÚinfer_shapes_pathr   )r   r   r   r   r   r   r   r   r   r   r   r   r   Údeprecated_kwargsÚquant_tmp_dirÚ	temp_pathÚmodelÚmodel_updatedÚopsetÚai_onnx_domainÚopset_versionr&   ÚeÚoptimization_input_modelÚopt_model_pathÚsess_optionÚexternal_namesÚexternal_valuesÚsessÚinferred_model_paths   &&&&&&&&&&&&&,                r    Úquant_pre_processra      sd  € ðV ÒØ'×+Ñ+Ð,>ÀÓEˆØÒ"Ð"Ð"àÒ(ÐJÐ*JÓJÐ(ä	×	$Ò	$¨L×	9Õ	9¸]Ü˜Ó'ˆ	Ü)¨+´t·±×GÒG‘ÌTÏYÊYÐWbÓMcˆØˆð
 .3×-?Ò-?ÓqÑ-? EÀuÇ|Ç|À|ÐW\×WcÑWcÐgpÑWpŸ%˜%Ñ-?ˆÐqÜˆ~Ó !Ô#Ø*¨1Õ-×5Ñ5ˆMØ Ô"Ü)¬)°EÓ*:¸MÓJ×PÑPÔRÜ×.Ñ.×>Ñ>¸uÀbÓI�Ü>¸uÓE�Ø $�ç"ðÝYô �K‰KÐ@ÔAØ*×7Ñ7ØØØØ!ØóˆEð !ˆMç Ð à'2Ð$ßä+.¨yÐ;NÕ/NÓ+OÐ(ß(Ü—O’OØØ0Ø.2Ø0GØ'CØ*/öô —I’I˜eÐ%=Ô>ä  Ð-=Õ!=Ó>ˆNð&5Ü)×8Ò8Ó:�Ø7E�Ô4Ü7B×7YÑ7Y×7jÑ7j�Ô4äÐ6¼¿¹×HÒHÜ(Ð)A×BÒBÜ(ðióð ô
 7RÐRjÓ6kÑ3�N OØ×9Ñ9¼$¸~Ó:NÔPTÐUdÓPeÔfØ/G×/YÑ/YÓ/[Ñ,÷ )×-BØ×8Ñ8ØQÐShôô #×3Ò3Ø,¨kÐF\ÐE]ô�ð
 ß"ä ŸIšI nÓ5‘Eà �EØ"0‘K÷ ð
 Ò Ü! )Ð.LÕ"LÓM�ß(Ü—O’OØØ#Ø.2Ø0GØ'CØ*/öô —I’I˜e [Ô1Ø�ä˜+¤t§¡×7Ò7Ü!¤$ }Ó"5Ð8JÕ"JÓK�Ü—’ØØØ*.Ø,CØ#?Ø&+õô #& iÐ2LÕ&LÓ"MÐÜ× Ñ ×2Ñ2°;Ð@SÔTÜ—I’IÐ1Ó2ˆEàŠ=Ü#-¨k¼4¿?¹?×#KÒ#K‘KÔQU×QZÒQZÐ[fÓQgˆE÷E 
:ôH ˜UÔ#çÜ�ŠØØØ"&Ø$;Ø+Ø7Ø#÷	
ô 	�	Š	�%Ð*Ö+ùòS røô ô Ü!ðqóð ðûðûôH ô 5Ü—‘Øoôô —‘œY×1Ò1Ó3×4ð	5ú÷q 
:×	9ús¨   ÁATÂRÂ2RÃRÃBTÅR Å4TÆ	TÆA TÇ6CR?Ê8R?Ë 4R?Ë5R?ÌTÌR?ÌTÌD/TÒTÒ R<Ò+R7Ò7R<Ò<TÒ?ATÔTÔ
TÔTÔT	)NNFFFFiÿÿÿFr   FFNi   )Úloggingr-   rM   Úpathlibr   r   r?   Ú#onnxruntime.transformers.onnx_utilsr   r   Úfusionsr   Ú
onnx_modelr   Úquant_utilsr   r	   Ú	getLoggerÚ__name__r:   ra   © r"   r    Ú<module>rk      sA   ðó Û Û Ý ã ã ß ^å .Ý !ß Yà	×	Ò	˜8Ó	$€÷B,ñ B,r"   