
    fThn                        S SK r S SKJrJr  S SKJrJrJrJrJ	r	J
r
Jr  S SKrSSKJrJrJr  SSKJrJrJr  SSKJr  \(       a  S S	KJrJr  \R2                  " \5      r\" 5       (       a"  S S
KJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+  \" 5       (       a  S SKJ,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4  \" 5       (       d  \" 5       (       d  \Rk                  S5        SS.S\6S\\6   S\\6\\/\4   4   4S jjr7 " S S5      r8g)    N)partialreduce)TYPE_CHECKINGCallableDictOptionalTupleTypeUnion   )PretrainedConfigis_tf_availableis_torch_available)TF2_WEIGHTS_NAMEWEIGHTS_NAMElogging   )
OnnxConfigPreTrainedModelTFPreTrainedModel)	AutoModelAutoModelForCausalLMAutoModelForImageClassificationAutoModelForImageSegmentationAutoModelForMaskedImageModelingAutoModelForMaskedLMAutoModelForMultipleChoiceAutoModelForObjectDetectionAutoModelForQuestionAnswering AutoModelForSemanticSegmentationAutoModelForSeq2SeqLM"AutoModelForSequenceClassificationAutoModelForSpeechSeq2SeqAutoModelForTokenClassificationAutoModelForVision2Seq)	TFAutoModelTFAutoModelForCausalLMTFAutoModelForMaskedLMTFAutoModelForMultipleChoiceTFAutoModelForQuestionAnswering"TFAutoModelForSemanticSegmentationTFAutoModelForSeq2SeqLM$TFAutoModelForSequenceClassification!TFAutoModelForTokenClassificationzThe ONNX export features are only supported for PyTorch or TensorFlow. You will not be able to export models without one of these libraries installed.onnx_config_clssupported_featuresr1   returnc                    U c  [        S5      e[        nU R                  S5       H  n[        X#5      nM     0 nU HI  nSU;   a*  UR	                  SS5      n[        UR                  US9XE'   M3  [        UR                  US9XE'   MK     U$ )aG  
Generate the mapping between supported the features and their corresponding OnnxConfig for a given model.

Args:
    *supported_features: The names of the supported features.
    onnx_config_cls: The OnnxConfig full name corresponding to the model.

Returns:
    The dictionary mapping a feature to an OnnxConfig constructor.
z#A OnnxConfig class must be provided.
-with-past )task)
ValueErrortransformerssplitgetattrreplacer   	with_pastfrom_model_config)r1   r2   
config_cls	attr_namemappingfeaturer8   s          R/var/www/auris/envauris/lib/python3.13/site-packages/transformers/onnx/features.pysupported_features_mappingrE   7   s     >??J$**3/	Z3
 0G%7"??<4D&z';';$GG&z'C'C'RG & N    c                   b   \ rS rSr0 r0 r\" 5       (       a  \\\	\
\\\\\\\\\\\S.r\" 5       (       a  \\\\\\\\\S.	r0 S\ " SSSSS	S
SS9_S\ " SSSSSSSS
SS9	_S\ " SSSS9_S\ " SSSSSS	S
SS9_S\ " SSSSSS	S
SS9_S\ " SSSSSSSS
SS9	_S\ " SSSSSSSS9_S\ " SSSSSSS S9_S!\ " SSSSSS	S"S9_S#\ " SSSSSS	S
S$S9_S%\ " SS&S9_S'\ " SSS(S9_S)\ " SSSSS	S
S*S9_S+\ " SSS,S9_S-\ " SSSSS	S
S.S9_S/\ " SSS0S9_S1\ " SSSS	S
S2S9_0 S3\ " SSSSS	S
S4S9_S5\ " SSS6S9_S7\ " SS8S9S:S9_S;\ " SSSSS	S
S<S9_S=\ " SSSSSS	S
S>S9_S?\ " SSSSSS	S
S@S9_SA\ " SSSSSS	SBS9_SC\ " SSSSS
SSDS9_SE\ " SSSSSSFS9_SG\ " SSHS9_SI\ " SSSSS	S
SJS9_SK\ " SSSLS9_SM\ " SSSS	SNS9_SO\ " SS
SS	SPS9_SQ\ " SSSRS9_SS\ " SSSSSTS9_SU\ " SSSS
SS	SVS9_E0 SW\ " SSSSSSSXS9_SY\ " SSSSSSSS
SZS9	_S[\ " SSSSS	S
S\S9_S]\ " SSS^S9_S_\ " SSS`S9_Sa\ " SSSbS9_Sc\ " SSSSSdS9_Se\ " SSSSSfS9_Sg\ " SShS9_Si\ " SSSSjS9_Sk\ " SSSlS9_Sm\ " SSSSSS	S
SnS9_So\ " SSSpS9_Sq\ " SSSSSS	S
SrS9_Ss\ " SSSSS	SS
S	StS9	_Su\ " SSSvSwS9_Sx\ " SSSSS	S
SyS9_E\ " SSSzS9\ " SSSSS{S9\ " S|S}S9\ " SSS~S9\ " SSSSSS9\ " SSSSSS	S
SS9\ " SSSSSS	S
SS9\ " SS8SS9S.Er!\"" \#" S S \!RI                  5        5       5      5      r%\& SS\'S\(\'   S\)\'\*\+/\,4   4   4S jj5       r-\&S\'S\'4S j5       r.\&S\'4S j5       r/\&SS\'S\'S\04S jj5       r1\&SS\'S\(\'   S\'4S jj5       r2\& SS\'S\'S\(\'   S\(\'   S\3S   4
S jj5       r4\& SS\3S   S\'S\5\'\*4   4S jj5       r6S\'S\'S\,4S jr7Sr8g)FeaturesManagerU   )default	masked-lm	causal-lm
seq2seq-lmsequence-classificationtoken-classificationmultiple-choiceobject-detectionquestion-answeringimage-classificationimage-segmentationz	masked-imsemantic-segmentationvision2seq-lmspeech2seq-lm)	rJ   rK   rL   rM   rN   rO   rP   rR   rU   albertrJ   rK   rN   rP   rO   rR   zmodels.albert.AlbertOnnxConfigr0   bartzdefault-with-pastrL   zcausal-lm-with-pastrM   zseq2seq-lm-with-pastzmodels.bart.BartOnnxConfigbeitrS   zmodels.beit.BeitOnnxConfigbertzmodels.bert.BertOnnxConfigzbig-birdz!models.big_bird.BigBirdOnnxConfigzbigbird-pegasusz/models.bigbird_pegasus.BigBirdPegasusOnnxConfig
blenderbotz&models.blenderbot.BlenderbotOnnxConfigzblenderbot-smallz1models.blenderbot_small.BlenderbotSmallOnnxConfigbloomzmodels.bloom.BloomOnnxConfig	camembertz$models.camembert.CamembertOnnxConfigclipzmodels.clip.CLIPOnnxConfigcodegenz models.codegen.CodeGenOnnxConfigconvbertz"models.convbert.ConvBertOnnxConfigconvnextz"models.convnext.ConvNextOnnxConfigzdata2vec-textz&models.data2vec.Data2VecTextOnnxConfigzdata2vec-visionz(models.data2vec.Data2VecVisionOnnxConfigdebertaz models.deberta.DebertaOnnxConfigz
deberta-v2z%models.deberta_v2.DebertaV2OnnxConfigdeitzmodels.deit.DeiTOnnxConfigdetrrQ   rT   zmodels.detr.DetrOnnxConfig
distilbertz&models.distilbert.DistilBertOnnxConfigelectraz models.electra.ElectraOnnxConfigflaubertz"models.flaubert.FlaubertOnnxConfiggpt2zmodels.gpt2.GPT2OnnxConfiggptjzmodels.gptj.GPTJOnnxConfigzgpt-neozmodels.gpt_neo.GPTNeoOnnxConfiggroupvitz"models.groupvit.GroupViTOnnxConfigibertzmodels.ibert.IBertOnnxConfigimagegptz"models.imagegpt.ImageGPTOnnxConfiglayoutlmz"models.layoutlm.LayoutLMOnnxConfig
layoutlmv3z&models.layoutlmv3.LayoutLMv3OnnxConfiglevitzmodels.levit.LevitOnnxConfiglongt5zmodels.longt5.LongT5OnnxConfig
longformerz&models.longformer.LongformerOnnxConfigmarianzmodels.marian.MarianOnnxConfigmbartzmodels.mbart.MBartOnnxConfig
mobilebertz&models.mobilebert.MobileBertOnnxConfigzmobilenet-v1z)models.mobilenet_v1.MobileNetV1OnnxConfigzmobilenet-v2z)models.mobilenet_v2.MobileNetV2OnnxConfig	mobilevitz$models.mobilevit.MobileViTOnnxConfigmt5zmodels.mt5.MT5OnnxConfigzm2m-100zmodels.m2m_100.M2M100OnnxConfigowlvitzmodels.owlvit.OwlViTOnnxConfig	perceiverz$models.perceiver.PerceiverOnnxConfig
poolformerz&models.poolformer.PoolFormerOnnxConfigrembertz models.rembert.RemBertOnnxConfigresnetzmodels.resnet.ResNetOnnxConfigrobertaz models.roberta.RobertaOnnxConfigroformerz"models.roformer.RoFormerOnnxConfig	segformerrU   z$models.segformer.SegformerOnnxConfigsqueezebertz(models.squeezebert.SqueezeBertOnnxConfigzmodels.swin.SwinOnnxConfigzmodels.t5.T5OnnxConfigrV   z<models.vision_encoder_decoder.VisionEncoderDecoderOnnxConfigzmodels.vit.ViTOnnxConfigrW   zspeech2seq-lm-with-pastz models.whisper.WhisperOnnxConfigzmodels.xlm.XLMOnnxConfigz'models.xlm_roberta.XLMRobertaOnnxConfigzmodels.yolos.YolosOnnxConfig)swint5zvision-encoder-decodervitwhisperxlmzxlm-robertayolosc                 
    X-  $ N )s1s2s     rD   <lambda>FeaturesManager.<lambda>*  s    bgrF   c              #   @   #    U  H  oR                  5       v   M     g 7fr   )keys).0vs     rD   	<genexpr>FeaturesManager.<genexpr>*  s     ?qRpQRps   N
model_type
model_namer3   c                    U R                  5       n U [        R                  ;  aJ  U(       a  U  SU S3OU n[        U S[	        [        R                  R                  5       5       SU  S35      e[        R                  U    $ )a  
Tries to retrieve the feature -> OnnxConfig constructor map from the model type.

Args:
    model_type (`str`):
        The model type to retrieve the supported features for.
    model_name (`str`, *optional*):
        The name attribute of the model object, only used for the exception message.

Returns:
    The dictionary mapping each feature to a corresponding OnnxConfig constructor.
z ()z is not supported yet. Only z' are supported. If you want to support z) please propose a PR or open up an issue.)lowerrH   _SUPPORTED_MODEL_TYPEKeyErrorlistr   )r   r   model_type_and_model_names      rD   %get_supported_features_for_model_type5FeaturesManager.get_supported_features_for_model_type,  s       %%'
_BBBJT:,bA(FZd%,- ._BBGGIJK L**45^` 
 44Z@@rF   rC   c                 &    U R                  SS5      $ )Nr6   r7   )r=   )rC   s    rD   feature_to_taskFeaturesManager.feature_to_taskF  s    |R00rF   	frameworkc                     U S;  a  [        SU  S35      eU S:X  a  [        5       (       d  [        S5      eU S:X  a  [        5       (       d  [        S5      egg)	zs
Validates if the framework requested for the export is both correct and available, otherwise throws an
exception.
pttfzAOnly two frameworks are supported for ONNX export: pt or tf, but z was provided.r   zOCannot export model to ONNX using PyTorch because no PyTorch package was found.r   zUCannot export model to ONNX using TensorFlow because no TensorFlow package was found.N)r9   r   RuntimeErrorr   )r   s    rD   _validate_framework_choice*FeaturesManager._validate_framework_choiceJ  sk     L(ST]S^^lm  $'9';';pqq$'8'8vww (9rF   c           	      "   [         R                  U 5      n[         R                  U5        US:X  a  [         R                  nO[         R                  nX#;  a6  [        SU  S[        [         R                  R                  5       5       35      eX2   $ )a  
Attempts to retrieve an AutoModel class from a feature name.

Args:
    feature (`str`):
        The feature required.
    framework (`str`, *optional*, defaults to `"pt"`):
        The framework to use for the export.

Returns:
    The AutoModel class corresponding to the feature.
r   zUnknown task: z. Possible values are )rH   r   r   _TASKS_TO_AUTOMODELS_TASKS_TO_TF_AUTOMODELSr   r   values)rC   r   r8   task_to_automodels       rD   get_model_class_for_feature+FeaturesManager.get_model_class_for_featureY  s     ..w7229= / D D / G G( 	)?_EiEiEpEpEr@s?tu  !&&rF   modelc                    Ub  U$ SSS.nSSS.n[         R                  R                  U 5      (       a  [         R                  R                  [         R                  R	                  U [
        5      5      (       a  SnOc[         R                  R                  [         R                  R	                  U [        5      5      (       a  SnO[        S[
         S	[         S
35      e[        R                  SX!    S35        O/[        5       (       a  SnO[        5       (       a  SnO[        S5      e[        R                  SX1    S35        U$ )a  
Determines the framework to use for the export.

The priority is in the following order:
    1. User input via `framework`.
    2. If local checkpoint is provided, use the same framework as the checkpoint.
    3. Available framework in environment, with priority given to PyTorch

Args:
    model (`str`):
        The name of the model to export.
    framework (`str`, *optional*, defaults to `None`):
        The framework to use for the export. See above for priority if none provided.

Returns:
    The framework to use for the export.

PyTorch
TensorFlowr   torchtf2onnxr   r   zMCannot determine framework from given checkpoint location. There should be a z for PyTorch or z for TensorFlow.zLocal z model found.zKNeither PyTorch nor TensorFlow found in environment. Cannot export to ONNX.zFramework not requested. Using z to export to ONNX.)ospathisdirisfilejoinr   r   FileNotFoundErrorloggerinfor   r   EnvironmentError)r   r   framework_mapexporter_maps       rD   determine_framework#FeaturesManager.determine_frameworkt  s   (  (=%Y777==ww~~bggll5,?@@ 	U4D EFF 	'**6 8+,,<> 
 KK&!9 :-HI!## 	 "" 	&'tuu5l6M5NNabcrF   	cache_dirr   c                 F   [         R                  X5      n[         R                  X5      n UR                  XS9nU$ ! [         aY    US:X  a)  [
        R                  S5        UR                  USUS9n U$ [
        R                  S5        UR                  USUS9n U$ f = f)a  
Attempts to retrieve a model from a model's name and the feature to be enabled.

Args:
    feature (`str`):
        The feature required.
    model (`str`):
        The name of the model to export.
    framework (`str`, *optional*, defaults to `None`):
        The framework to use for the export. See `FeaturesManager.determine_framework` for the priority should
        none be provided.

Returns:
    The instance of the model.

)r   r   z=Loading TensorFlow model in PyTorch before exporting to ONNX.T)from_tfr   z=Loading PyTorch model in TensorFlow before exporting to ONNX.)from_ptr   )rH   r   r   from_pretrainedOSErrorr   r   )rC   r   r   r   model_classs        rD   get_model_from_feature&FeaturesManager.get_model_from_feature  s    ( $77I	%AA'U	^///KE   	^D [\#33E4S\3]  [\#33E4S\3]	^s   = 6B 6&B B c                 >   U R                   R                  R                  SS5      n[        U SS5      n[        R                  X#S9nX;  a'  [        U R                   R                   SU SU 35      eU R                   R                  [        R                  U   U   4$ )a  
Check whether or not the model has the requested features.

Args:
    model: The model to export.
    feature: The name of the feature to check if it is available.

Returns:
    (str) The type of the model (OnnxConfig) The OnnxConfig instance holding the model export properties.

_-namer7   )r   z doesn't support feature z. Supported values are: )configr   r=   r<   rH   r   r9   r   )r   rC   r   r   model_featuress        rD   check_supported_model_or_raise.FeaturesManager.check_supported_model_or_raise  s     \\,,44S#>
UFB/
(NNzNq(<<**++DWIMefteuv  ||&&(M(Mj(YZa(bbbrF   c                 .    [         R                  U    U   $ )a  
Gets the OnnxConfig for a model_type and feature combination.

Args:
    model_type (`str`):
        The model type to retrieve the config for.
    feature (`str`):
        The feature to retrieve the config for.

Returns:
    `OnnxConfig`: config for the combination
)rH   r   )r   rC   s     rD   
get_configFeaturesManager.get_config  s     44Z@IIrF   r   r   )r   )NN)rJ   )9__name__
__module____qualname____firstlineno__r   r   r   r   r   r   r"   r#   r%   r   r   r    r   r   r   r!   r&   r$   r   r'   r)   r(   r-   r.   r/   r*   r+   r,   rE   r   sortedr   r   AVAILABLE_FEATURESstaticmethodstrr   r   r   r   r   r   r   r   r
   r   r   r   r   r	   r   r   __static_attributes__r   rF   rD   rH   rH   U   s
     --/'I$C9 ;"?$C"?8%E36 
" "//1'K$E;"A%G
#
p,%" <
p 	*!"% 8

p, 	*-?[
-p2 	*%" 8	
3pF 	.%" ?	
GpZ 	5!"% M

[pp 	0!"D
qpB 	6!"O
CpT 	+!%":
Upf 	/%" B	
gpz 	*8
{pB 	->
CpL 	.%" @
Mp^ 	."@
_ph 	3%" D
ipz 	5" G
{pH 	-%" >
IpX 	0%" C
Ypj 	*-?[
kpp 	* 8	
qp| 	0%" D
}pN 	-%" >	
Opb 	.%" @	
cpv 	*!%"8
wpH 	*! %8
IpZ 	-!%=
[pj 	.@
kpr 	+%" :
spD 	.-?c
EpJ 	.%"@
KpX 	0 %"D
Ypf 	+-?]
gpl 	,"<
mpz 	0 %"D
{pL 	,"!<
Mp^ 	+!"% :

_pt 	0%" D
upF	 	2"G
G	pP	 	2"G
Q	pZ	 	/"B
[	pd	 	)"6
e	pr	 	-"=
s	p@
 	,<
A
pH
 	/"%B	
I
pT
 	0-?g
U
pZ
 	-%" >	
[
pn
 	,"<
o
px
 	-%" >	
y
pL 	.%" "@

Mpb 	/"#B	
cpn 	1%" F
op@ +-?[
 )"4
 #=-k#
 *-?Y
 .%>
 *%" 6	
 2%" E	
 ,:
Wpd  '=?qRgRnRnRp?q rs59AA%-c]A	c8-.
:;;	<A A2 1 1 1 1 xc x x 'S 'S 'D ' '4 /3 /8C= /C / /b ^b -5c]NVWZm	5	6 @ MVc;<cGJc	sH}	c c0Js JS JZ JrF   rH   )9r   	functoolsr   r   typingr   r   r   r   r	   r
   r   r:   r7   r   r   r   utilsr   r   r   r   r   r   r   
get_loggerr   r   transformers.models.autor   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   warningr   rE   rH   r   rF   rD   <module>r      s    	 % N N N  D D ; ;  ? 
		H	%    " 
 
 
 O$5$5
NN	5 @D/7}	#x)*J67
78<X
J X
JrF   