U
    T?h[  ã                   @   sL  d dl Z d dlZd dlZd dlZd dlmZmZmZmZ ej	ddej
 dd¡ ¡ ejd e d¡Zd	d
„ Zdd„ ZedkrHeƒ Zejdk r edej› dƒ‚ej ej¡Zes¾e ej¡ de_e d¡ ejsÚde_ejsôe d¡ e e¡ ej se d¡ e !e¡ ej"s,e d¡ e #e¡ ej$sHe d¡ e %e¡ dS )é    N)Úchain_enc_dec_with_beamsearchÚexport_summarization_edinitÚ!export_summarization_enc_dec_pastÚonnx_inferencezO%(asctime)s | %(levelname)s | %(name)s |  [%(filename)s:%(lineno)d] %(message)sz%Y-%m-%d %H:%M:%SZLOGLEVELÚINFO)ÚformatÚdatefmtÚlevelÚstreamÚgeneratec                 C   s,   t | ƒD ]}t |› dt| |ƒ› ¡ qd S )Nz: )ÚvarsÚloggerÚinfoÚgetattr)ÚargsÚarg© r   ú]/var/www/html/venv/lib/python3.8/site-packages/onnxruntime/transformers/models/bart/export.pyÚ
print_args   s    r   c                  C   sD  t jdd} | jdtddd | jdtdd	d | jd
dtddd | jddtd dd | jddtd dd | jddtdd | jddtddd | jdtddd | jdtd d!d | jd"tdd#d | jd$td%d&d | jd'd(d) | jd*d(d) | jd+d(d) | jd,d(d) |  d-¡}|jd.d/td0d1d2 t|  	¡ ƒ |  	¡ S )3NF)Úadd_helpz--max_lengthé   zdefault to 20)ÚtypeÚdefaultÚhelpz--min_lengthr   zdefault to 0z-oz--outputZonnx_modelszdefault name is onnx_models.z-iz--input_textz
input textz-sz
--spm_pathz!tokenizer model from sentencepicez-vz--vocab_pathzvocab dictionary)r   r   z-bz--num_beamsé   zdefault to 5z--repetition_penaltyg      ð?zdefault to 1.0z--no_repeat_ngram_sizeé   zdefault to 3z--early_stoppingzdefault to Falsez--opset_versioné   zminimum is 14z--no_encoderÚ
store_true)Úactionz--no_decoderz
--no_chainz--no_inferencezrequired input argumentsz-mz--model_dirTzŒThe directory contains input huggingface model.                                An official model like facebook/bart-base is also acceptable.)r   Úrequiredr   )
ÚargparseÚArgumentParserÚadd_argumentÚintÚstrÚfloatÚboolÚadd_argument_groupr   Ú
parse_args)Zparent_parserZrequired_argsr   r   r   Úuser_command"   s4    
û	r)   Ú__main__r   z=The minimum supported opset version is 14! The given one was Ú.ÚcpuzENV: CPU ...a  PG&E stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions. The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by the shutoffs which were expected to last through at least midday tomorrow.z'========== EXPORTING ENCODER ==========z'========== EXPORTING DECODER ==========z'========== CONVERTING MODELS ==========z1========== INFERENCING WITH ONNX MODEL ==========)&r    ÚloggingÚosÚsysÚutilsr   r   r   r   ÚbasicConfigÚenvironÚgetÚupperÚstdoutÚ	getLoggerr   r   r)   Ú__name__r   Zopset_versionÚ
ValueErrorÚpathÚexistsÚoutputZisExistÚmakedirsZdevicer   Z
input_textZ
no_encoderZexport_encoderZ
no_decoderZexport_decoderZno_chainZconvert_modelZno_inferenceZrun_inferencer   r   r   r   Ú<module>   sJ   ü
!


ÿ






