§
    kŠtjk  ã                   óÌ  — d Z ddlZddlZddlZddlmZ d„ Z	 	 	 	 	 	 	 	 	 	 ddeej        z  ej	        z  deej        z  d	e
d
e
de
dedz  dede
dee         dz  dee         dz  deeeef                  dz  de
de
fd„Zedk    r_ e¦   «         Z eej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ¬¦  «         dS dS )z@Provide entry point to preprocess ONNX model especially for QNN.é    N)Úqnnc                  ó¶  — t          j        d¬¦  «        } |                      dddd¬¦  «         |                      dd	dd
¬¦  «         |                      ddd¬¦  «         |                      ddd¬¦  «         |                      dd¬¦  «         |                      ddt          d¬¦  «         |                      ddd¬¦  «         |                      ddd¬¦  «         |                      dddd¬ ¦  «         |                      d!ddd"¬ ¦  «         |                      d#d$d%t          dd&¬'¦  «         |                      d(dd)¬¦  «         |                      ¦   «         S )*zParse cmdline arguments.z#Arguments for QNN model preprocess.)Údescriptionz--input_model_pathz-iTzPath to the input ONNX model.)ÚrequiredÚhelpz--output_model_pathz-ozPath to the output ONNX model.z--save_as_external_dataÚ
store_truez;Whether the output model would be saved with external data.)Úactionr   z--all_tensors_to_one_filezgWhether to save all external data in one file or save each tensor to a file named with the tensor name.z--external_data_locationzbFilename of the external file where all tensors are saved. The path is relative to the model path.)r   z--external_data_size_thresholdé   zQTensors with data size larger than this threshold are converted to external data.)ÚdefaultÚtyper   z!--external_data_convert_attributezKWhether to save all tensors, including attribute tensors, to external data.z--fuse_layernormzLWhether to fuse matched sequences into LayerNormalization nodes if possible.z--inputs_to_make_channel_lastú+Nz=List of graph input names to be transposed into channel-last.)Únargsr   r   z--outputs_to_make_channel_lastz>List of graph output names to be transposed into channel-last.z--dynamic_input_shapesé   ÚappendzdModel input name and desired static shape in comma seprated format, for example: 'input' 1,3,256,256)r   r	   r   r   r   z --exclude_initializer_from_inputzBWhether to exclude initializer from input if model.ir_version >= 4)ÚargparseÚArgumentParserÚadd_argumentÚintÚstrÚ
parse_args)Úparsers    ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/onnxruntime/tools/qnn/preprocess.pyÚ_parse_argumentsr      s  € åÔ$Ð1VÐWÑWÔW€Fà
×ÒÐ,¨d¸TÐHgÐÑhÔhÐhØ
×ÒÐ-¨t¸dÐIiÐÑjÔjÐjð ×ÒØ!ØØJð ñ ô ð ð
 ×ÒØ#ØØvð ñ ô ð ð
 ×ÒØ"Øqð ñ ô ð ð ×ÒØ(ØÝØ`ð	 ñ ô ð ð ×ÒØ+ØØZð ñ ô ð ð ×ÒØØØ[ð ñ ô ð ð ×ÒØ'ØØØLð	 ñ ô ð ð ×ÒØ(ØØØMð	 ñ ô ð ð ×ÒØ ØØÝØØsð ñ ô ð ð ×ÒØ*ØØQð ñ ô ð ð ×ÒÑÔÐó    Fr
   Úmodel_inputÚmodel_outputÚfuse_layernormÚsave_as_external_dataÚall_tensors_to_one_fileÚexternal_data_locationÚexternal_data_size_thresholdÚexternal_data_convert_attributeÚinputs_to_make_channel_lastÚoutputs_to_make_channel_lastÚdynamic_input_shapesÚexclude_initializer_from_inputÚreturnc                 óB   — t          j        | |||||||||	|
|¬¦  «        S )a<  Preprocess ONNX model for QNN.

    Args:
        model_input: A path or ONNX ModelProto specifiying the model to be preprocessed.
        model_output: A path specifying where the preprocessed model to be saved.
        fuse_layernorm: A bool specifying whether to fuse the matched sequence into a single LayerNormalization node.
            Defaults to False.
        save_as_external_data: A bool specifying whether to save model with external data. Defaults to False.
        all_tensors_to_one_file: A bool specifying whether to save all external data in one file or save each tensor to
            a file named with the tensor name. This argument is effective only when `save_as_external_data` is True.
            Defaults to False.
        external_data_location: A str specifying where to save the external data. The path is relative to the model
            path. This argument is effective only when `save_as_external_data` is True. Defaults to the model name.
        external_data_size_threshold: An int specifying the threshold of data size for tensors be saved as external
            data. This argument is effective only when `save_as_external_data` is True. Defaults to 1024.
        external_data_convert_attribute: A bool specifying whether to save all tensors including attributes as external
            data. This argument is effective only when `save_as_external_data` is True. Defaults to False.
        inputs_to_make_channel_last: A list of strs specifying graph input names to be transposed into channel-last.
            Defaults to None.
        outputs_to_make_channel_last: A list of strs specifying graph output names to be transposed into channel-last.
            Defaults to None.
        dynamic_input_shapes: A list of tuples specifying model input name to and its static shape in comma seprated
            format, for example: [('input', '1,3,256,256')]. Defaults to None.
        exclude_initializer_from_input: A bool specifying whether to exclude initializer from input. Defaults to False.

    Returns:
        A bool indicating whether the model is modified.
    ©
r   r   r   r    r!   r"   r#   r$   r%   r&   )r   Úqnn_preprocess_model)r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   s               r   r*   r*   \   sC   € õT Ô#ØØØ%Ø3Ø 7Ø5Ø%AØ(GØ$?Ø%AØ1Ø'Eðñ ô ð r   Ú__main__r)   )
FFFNr
   FNNNF)Ú__doc__r   ÚpathlibÚonnxÚ,onnxruntime.quantization.execution_providersr   r   r   ÚPathÚ
ModelProtoÚboolr   ÚlistÚtupler*   Ú__name__ÚargsÚinput_model_pathÚoutput_model_pathr   r   r   r    r!   r"   r#   r$   r%   r&   © r   r   ú<module>r:      sÒ  ðð GÐ Fà €€€Ø €€€à €€€à <Ð <Ð <Ð <Ð <Ð <ðIð Ið Ið^ !Ø"'Ø$)Ø)-Ø(,Ø,1Ø48Ø59Ø9=Ø+0ð7ð 7Ø�w”|Ñ# d¤oÑ5ð7à˜œÑ$ð7ð ð7ð  ð	7ð
 "ð7ð   $™Jð7ð #&ð7ð &*ð7ð "& c¤¨TÑ!1ð7ð #' s¤)¨dÑ"2ð7ð ˜u S¨# XœÔ/°$Ñ6ð7ð %)ð7ð 
ð7ð 7ð 7ð 7ðt ˆzÒÐØÐÑÔ€DØÐØÔØÔØÔ*Ø"Ô8Ø $Ô <Ø#Ô:Ø%)Ô%FØ(,Ô(LØ$(Ô$DØ%)Ô%FØ!Ô6Ø'+Ô'Jðñ ô ð ð ð ð Ðr   