Ë
    T^(h%  ã                   ó(  — 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(  r5 ej<                  d«      ZejA                  ejB                  «        e«        yy)é    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        «       rMddlm} t        j                  |«      }|t        j                  t
        «      k  r!t        dt
        › d|› d�«      ‚t        d«      ‚t        j                  ddd	| j                  › �d
| j                  › �| j                  �d| j                  › �nd| j                  › g}t        j                  |t        j                  ¬«      }|j!                  «        t"        j%                  d«       y )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        úX/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/onnx/__main__.pyÚexport_with_optimumr-   #   só   € ÜÔÝBä!(§¡¨Ó!?ÐØ!¤G§M¡MÔ2EÓ$FÒFÜØ8Ô9LÐ8MÈUÐSbÐRcð dTð Tóð ô
 ð!ó
ð 	
ô
 	�‰ØØ Ø
�4—:‘:�,ÐØ
�$—,‘,�Ð Ø+/¯>©>Ð+Eˆ,�t—~‘~Ð&Ñ'È2Ø�;‰;ˆ-ð€Hô ×Ñ˜H¬Z¯_©_Ô=€DØ‡I�I„Kä
‡K�Kð	Zõó    c                 ó  — | j                   j                  «       r| j                   n| j                   j                  d«      | _         | j                   j                  j	                  «       s&| j                   j                  j                  d¬«       t        j                  | j                  | j                  | j                  | j                  ¬«      }t        j                  || j                  ¬«      \  }} ||j                  «      }|t        v �rì|j                  «       }|j!                  «       }|j#                  |j                  «      }|j%                  |j                  |j                  | j                  ¬«      }| j&                  €%t)        |j*                  |j*                  «      | _        | j&                  t-        |j*                  |j*                  «      k  r=t/        d| j&                  › d|› dt-        |j*                  |j*                  «      › d	�«      ‚t1        j2                  | j                  «      }	t5        |	||| j&                  | j                   j                  j                  d
«      «      \  }
}t7        ||	|| j                   j                  j                  d
«      || j8                  r| j8                  n|j:                  «       t=        j2                  | j                  «      }	t5        |	||| j&                  | j                   j                  j                  d«      «      \  }
}t7        ||	|| j                   j                  j                  d«      || j8                  r| j8                  n|j:                  «       t>        jA                  d| j                   j                  j                  d
«      jC                  «       › d| j                   j                  j                  d«      jC                  «       › �«       y | jD                  dk(  rtG        | j                  «      }	nÕ| jD                  dk(  r t=        j2                  | j                  «      }	n¦| jD                  dk(  r tI        j2                  | j                  «      }	nw| jD                  dk(  r t1        j2                  | j                  «      }	nH| jD                  dk(  r tK        j2                  | j                  «      }	nt/        d| jD                  › d�«      ‚| j&                  €|j*                  | _        | j&                  |j*                  k  r)t/        d| j&                  › d|› d|j*                  › d	�«      ‚t5        |	||| j&                  | j                   «      \  }
}| j8                  €|j:                  | _        t7        ||	|| j                   || j8                  «       t>        jA                  d| j                   jC                  «       › �«       tM        jN                  dtP        «       y )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   s   € Ø!%§¡×!4Ñ!4Ô!6�$—+’+¸D¿K¹K×<PÑ<PÐQ]Ó<^€D„KØ�;‰;×Ñ×$Ñ$Ô&Ø�‰×Ñ× Ñ ¨Ð Ô.ô ×2Ñ2Ø�‰�d—j‘j¨D¯N©NÀdÇnÁnô€Eô %4×$RÑ$RÐSXÐbf×bnÑbnÔ$oÑ!€JÐ!Ù# E§L¡LÓ1€KàÔ+Ò+Ø×)Ñ)Ó+ˆØ×)Ñ)Ó+ˆà)×<Ñ<¸]×=QÑ=QÓRÐØ)×<Ñ<Ø× Ñ  -×"6Ñ"6ÀÇÁð =ó 
Ðð �:‰:ÐÜÐ0×CÑCÐEX×EkÑEkÓlˆDŒJà�:‰:œÐ/×BÑBÐDW×DjÑDjÓkÒkÜØ˜Ÿ™˜Ð$AÀ*Àð NÜÐ+×>Ñ>Ð@S×@fÑ@fÓgÐhÐhuðwóð ô
 ,×;Ñ;¸D¿J¹JÓGˆä$*ØØØØ�J‰JØ�K‰K×Ñ×'Ñ'Ð(<Ó=ó%
Ñ!ˆ�\ô 	ØØØØ�K‰K×Ñ×'Ñ'Ð(<Ó=ØØŸšˆD�IŠIÐ(;×(OÑ(Oô	
ô %×4Ñ4°T·Z±ZÓ@ˆä$*ØØØØ�J‰JØ�K‰K×Ñ×'Ñ'Ð(<Ó=ó%
Ñ!ˆ�\ô 	ØØØØ�K‰K×Ñ×'Ñ'Ð(<Ó=ØØŸšˆD�IŠIÐ(;×(OÑ(Oô	
ô 	�‰Ø(¨¯©×);Ñ);×)DÑ)DÐEYÓ)Z×)cÑ)cÓ)eÐ(fð gØ—‘×"Ñ"×+Ñ+Ð,@ÓA×JÑJÓLÐMðOõ	
ð ×Ñ Ò&Ü+¨D¯J©JÓ7‰LØ×Ñ +Ò-Ü(×8Ñ8¸¿¹ÓD‰LØ×ÑÐ"3Ò3Ü-×=Ñ=¸d¿j¹jÓI‰LØ×ÑÐ"5Ò5Ü/×?Ñ?ÀÇ
Á
ÓK‰LØ×Ñ +Ò-Ü(×8Ñ8¸¿¹ÓD‰LäÐ:¸4×;LÑ;LÐ:MÈQÐOÓPÐPð �:‰:ÐØ$×7Ñ7ˆDŒJà�:‰:˜×6Ñ6Ò6ÜØ˜Ÿ™˜Ð$AÀ*Àð NØ(×;Ñ;Ð<¸MðKóð ô
 %+ØØØØ�J‰JØ�K‰Kó%
Ñ!ˆ�\ð �9‰9ÐØ#×7Ñ7ˆDŒIä˜{¨L¸%ÀÇÁÈlÐ\`×\eÑ\eÔfÜ�‰Ð0°·±×1EÑ1EÓ1GÐ0HÐIÔJÜ�‰ð_ô õ		
r.   c                  óN  — t        d«      } | j                  ddt        dd¬«       | j                  ddd	¬
«       | j                  dt        d d¬«       | j                  dt        d d¬«       | j                  dt        ddgd d¬«       | j                  dt
        d¬«       | j                  dt        d d¬«       | j                  dt        g d¢dd¬«       | j                  ddd ¬!«       | j                  «       }|j                  s
t        «       st        |«       y t        |«       y )"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Útfz¡The 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_truezÕWhether 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   ¼   sL  € ÜÐEÓF€FØ
×ÑØˆiœc¨DÐ7wð ô ð ×ÑØØØ=ð ô ð
 ×Ñ˜	¬°TÐ@nÐÔoØ
×ÑØ”u dÐ1kð ô ð ×ÑØÜØ�t�Øð8ð ô 
ð ×Ñ˜¤tÐ2hÐÔiØ
×Ñ˜¬C¸ÐDkÐÔlØ
×ÑØÜÚZØØZð ô ð ×ÑØ$Øðð	 ô ð ×ÑÓ€DØ×$Ò$Ô,@Ô,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      s‰   ðó Û 
Û Ý #Ý å ç UÓ UÝ Ý 5ß 3Ý %Ý #ð Ð à2Ð3Ð òòDt
òn0"ðf ˆzÒØˆW×ÑÐ 3Ó4€FØ
‡O�O�G—L‘LÔ!Ù…Fð r.   