
    g%                     .   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ ddl	m
Z
mZmZmZ ddlmZ ddlmZ d	d
lmZmZ d	dlmZ d	dlmZ dZdgZd Zd Zd Zedk    r6 ej        d          Ze                     ej!                    e             dS dS )    N)ArgumentParser)Path)version   )AutoFeatureExtractorAutoImageProcessorAutoProcessorAutoTokenizer)logging)is_optimum_available   )exportvalidate_model_outputs)FeaturesManager)get_preprocessorz1.5.0zvision-encoder-decoderc                    t                      rSddlm} t          j        |          }|t          j        t
                    k     rt          dt
           d| d          nt          d          t          j        ddd	| j	         d
| j
         | j        
d| j         nd| j         g}t          j        |t          j                  }|                                 t"                              d           d S )Nr   )__version__z&transformers.onnx requires optimum >= z but zT is installed. You can upgrade optimum by running: pip install -U optimum[exporters]zqtransformers.onnx requires optimum to run, you can install the library by running: pip install optimum[exporters]-mzoptimum.exporters.onnxz--model z--task z--framework  )stdouta  The export was done by optimum.exporters.onnx. We recommend using to use this package directly in future, as transformers.onnx is deprecated, and will be removed in v5. You can find more information here: https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model.)r   optimum.versionr   r   parseMIN_OPTIMUM_VERSIONRuntimeErrorsys
executablemodelfeature	frameworkoutput
subprocessPopenPIPEwaitloggerinfo)argsoptimum_versionparsed_optimum_versioncmd_lineprocs        V/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/onnx/__main__.pyexport_with_optimumr-   #   s?    
BBBBBB!(!?!?!GM2E$F$FFFT9L T TSb T T T   G !
 
 	

 	 4: $,  +/>+E't~'''2;H HZ_===DIIKKK
KK	Z        c                 N
   | j                                         r| j         n| j                             d          | _         | j         j                                        s | j         j                            d           t          j        | j        | j	        | j
        | j                  }t          j        || j                  \  }} ||j                  }|t          v r|                                }|                                }|                    |j                  }|                    |j        |j        | j                  }| j        t)          |j        |j                  | _        | j        t-          |j        |j                  k     r6t/          d| j         d| dt-          |j        |j                   d	          t1          j        | j	                  }	t5          |	||| j        | j         j                            d
                    \  }
}t7          ||	|| j         j                            d
          || j        r| j        n|j                   t=          j        | j	                  }	t5          |	||| j        | j         j                            d                    \  }
}t7          ||	|| j         j                            d          || j        r| j        n|j                   t>                               d| j         j                            d
          !                                 d| j         j                            d          !                                            d S | j"        dk    rtG          | j	                  }	n| j"        dk    rt=          j        | j	                  }	n| j"        dk    rtI          j        | j	                  }	nb| j"        dk    rt1          j        | j	                  }	n=| j"        dk    rtK          j        | j	                  }	nt/          d| j"         d          | j        |j        | _        | j        |j        k     r#t/          d| j         d| d|j         d	          t5          |	||| j        | j                   \  }
}| j        |j        | _        t7          ||	|| j         || j                   t>                               d| j         !                                            tM          j'        dtP                     d S )Nz
model.onnxT)parents)r   	cache_dir)r   zOpset z is not sufficient to export z. At least  z is required.zencoder_model.onnxzdecoder_model.onnxzAll good, model saved at: z, auto	tokenizerimage_processorfeature_extractor	processorzUnknown preprocessor type ''a   The export was done by transformers.onnx which is deprecated and will be removed in v5. We recommend using optimum.exporters.onnx in future. You can find more information here: https://huggingface.co/docs/optimum/exporters/onnx/usage_guides/export_a_model.))r    is_filejoinpathparentexistsmkdirr   get_model_from_featurer   r   r   r1   check_supported_model_or_raiseconfigENCODER_DECODER_MODELSget_encoderget_decoderget_encoder_configget_decoder_configopsetmaxdefault_onnx_opsetmin
ValueErrorr   from_pretrainedr   r   atolatol_for_validationr
   r%   r&   as_posixpreprocessorr   r   r	   warningswarnFutureWarning)r'   r   
model_kindmodel_onnx_configonnx_configencoder_modeldecoder_modelencoder_onnx_configdecoder_onnx_configrN   onnx_inputsonnx_outputss               r,   export_with_transformersr[   E   sp   !%!4!4!6!6^$++DK<P<PQ]<^<^DK;$$&& /   ... 2djDNdn  E %4$RSXbfbn$o$o$o!J!##EL11K+++))++))++)<<]=QRR)<< -"6 = 
 
 :0CEXEkllDJ:/BDWDjkkkkw w w* w w+>@S@fggw w w  
 ,;DJGG$*JK''(<==%
 %
!\ 	K''(<==ODII(;(O	
 	
 	
 %4TZ@@$*JK''(<==%
 %
!\ 	K''(<==ODII(;(O	
 	
 	
 	O);)D)DEY)Z)Z)c)c)e)e O O"++,@AAJJLLO O	
 	
 	
 	
 	
 &&+DJ77LL+--(8DDLL"333-=djIILL"555/?
KKLL+--(8DDLLO4;LOOOPPP :$7DJ:666K K K* K K(;K K K  
 %+JK%
 %
!\ 9#7DI{L%l\`\efffI1E1E1G1GIIJJJ_ 		
 	
 	
 	
 	
r.   c                     t          d          } |                     ddt          dd           |                     ddd	
           |                     dt          d d           |                     dt          d d           |                     dt          ddgd d           |                     dt
          d           |                     dt          d d           |                     dt          g ddd           |                     ddd !           |                                 }|j        st                      st          |           d S t          |           d S )"Nz'Hugging Face Transformers ONNX exporterr   z--modelTz>Model ID on huggingface.co or path on disk to load model from.)typerequiredhelpz	--featuredefaultz.The type of features to export the model with.)r`   r_   z--opsetz,ONNX opset version to export the model with.)r]   r`   r_   z--atolz8Absolute difference tolerance when validating the model.z--frameworkpttfzThe framework to use for the ONNX export. If not provided, will attempt to use the local checkpoint's original framework or what is available in the environment.)r]   choicesr`   r_   r    z4Path indicating where to store generated ONNX model.)r]   r_   z--cache_dirz%Path indicating where to store cache.z--preprocessor)r2   r3   r5   r4   r6   r2   zKWhich type of preprocessor to use. 'auto' tries to automatically detect it.z--export_with_transformers
store_truezWhether to use transformers.onnx instead of optimum.exporters.onnx to perform the ONNX export. It can be useful when exporting a model supported in transformers but not in optimum, otherwise it is not recommended.)actionr_   )
r   add_argumentstrintfloatr   
parse_argsr[   r   r-   )parserr'   s     r,   mainrl      s   EFFF
icD7w     =    
 	T@nooo
ud1k     t8  
 
 
 t2hiii
CDklll
ZZZZ     $	     D$ ",@,B,B " &&&&&D!!!!!r.   __main__ztransformers.onnx)"r!   r   rO   argparser   pathlibr   	packagingr   r   r   r   r	   r
   utilsr   utils.import_utilsr   convertr   r   featuresr   r   r   r@   r-   r[   rl   __name__
get_loggerr%   setLevelINFO r.   r,   <module>rz      sn       



  # # # # # #             U U U U U U U U U U U U       5 5 5 5 5 5 3 3 3 3 3 3 3 3 % % % % % % # # # # # #  23   Dt
 t
 t
n0" 0" 0"f zW 344F
OOGL!!!DFFFFF r.   