
    fTha                        S SK r S SKrS SKrS SKJrJr  S SKJr  S SKJ	r	J
r
JrJrJrJrJrJrJrJr  S SKrS SKJr  SSKJrJrJrJr  SS	KJrJrJr  \	(       a  SS
KJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  \" 5       (       a  S SK'J(r(  \RR                  " \*5      r+Sr,Sr-\R\                   " S S5      5       r/ " S S\5      r0 " S S\0\5      r1 " S S\15      r2g)    N)ABCabstractmethod)OrderedDict)
TYPE_CHECKINGAnyCallableDictIterableListMappingOptionalTupleUnion)version   )
TensorTypeis_torch_availableis_vision_availablelogging   )ParameterFormat compute_effective_axis_dimension"compute_serialized_parameters_size)PretrainedConfigFeatureExtractionMixinImageProcessingMixinPreTrainedTokenizerBase)Image   l        c                   `    \ rS rSr% Sr\\S'   \\S'   \\S'   Sr	\
\   \S'   Sr\
\   \S'   S	rg)
PatchingSpec/   a  
Data class that holds patching specifications.

Args:
    o: Module / object where the op to patch is located
    name: Name of the op to monkey patch
    custom_op: Custom op that patches the original op
    orig_op: Original op that is being patched
    op_wrapper: Wrapper (optional) that wraps both the original and custom ops.
        It is useful for ops that are class or static methods for instance.
oname	custom_opNorig_op
op_wrapper )__name__
__module____qualname____firstlineno____doc__r   __annotations__strr   r)   r   r*   __static_attributes__r+       P/var/www/auris/envauris/lib/python3.13/site-packages/transformers/onnx/config.pyr$   r$   /   s7    
 F
I"&GXh&%)J")r4   r$   c                   t   \ rS rSrSrSrSrSr\R                  " S5      r
\" SSS	S
.05      \" SSS	S
.05      \" SSS	S
.05      \" SS	S
.SS	S
.SS	S
.S.5      \" SSS	S
.05      \" SSS	S
.05      \" SSS005      \" SS	S
.SS	S
.S.5      \" SS	S
.SS	S
.S.5      \" SSSSSS.05      \" SSSS
.05      \" SSS005      \" SSS	S
.05      \" SSS	S
.05      \" SSS	S
.05      S.r SCSSS\S\\\      4S jjr\SDSSS\SS 4S jj5       r\\S\\\\\4   4   4S j5       5       r\S\\\\\4   4   4S j5       r\S\\\\4      4S  j5       r\S\4S! j5       r\S\4S" j5       r\S\4S# j5       r\S\4S$ j5       r\S\ 4S% j5       r!\S\"4S& j5       r#\$S'\S\"4S( j5       r% SES)\S*\S+\S,\4S- jjr& SFS)\S.\S/\ S0\4S1 jjr'            SGS2\(S3   S)\S4\S5\S6\"S7\\)   S*\S,\S+\S.\S/\ S0\S8\S9   S\\\4   4S: jjr*S;\\\4   S\\\4   4S< jr+S= r,S> r-\S?\S@\.\   S\/\\4   4SA j5       r0SBr1g)H
OnnxConfigD   zn
Base class for ONNX exportable model describing metadata on how to export the model through the ONNX format.
r         z1.8logitsbatchsequencer   r   last_hidden_state)r;   
pred_boxes
pred_masksr   )r;   r@   )start_logits
end_logits
num_labelsheightwidth)r   r   r      decoder_sequence)z	causal-lmdefaultzimage-classificationzimage-segmentationz	masked-imz	masked-lmmultiple-choicezobject-detectionzquestion-answeringzsemantic-segmentationz
seq2seq-lmzsequence-classificationztoken-classificationzvision2seq-lmzspeech2seq-lmNconfigr   taskpatching_specsc                 n   Xl         X R                  ;  a(  [        U SU R                  R                  5        35      eX l        / U l        Ub  UO/  H`  nUnUR                  c3  [        R                  " U[        UR                  UR                  5      S9nU R
                  R                  U5        Mb     g )Nz+ is not a supported task, supported tasks: )r)   )_config_tasks_to_common_outputs
ValueErrorkeysrL   _patching_specsr)   dataclassesreplacegetattrr&   r'   append)selfrK   rL   rM   spec
final_specs         r5   __init__OnnxConfig.__init__o   s     444&CDDaDaDfDfDhCij  	!&4&@NbHDJ||#(00wtvvtyy?YZ
  ''
3	 Ir4   returnc                     U " XS9$ )z
Instantiate a OnnxConfig for a specific model

Args:
    config: The model's configuration to use when exporting to ONNX

Returns:
    OnnxConfig for this model
)rL   r+   clsrK   rL   s      r5   from_model_configOnnxConfig.from_model_config   s     6%%r4   c                     [        5       e)z
Mapping containing the axis definition of the input tensors to provide to the model

Returns:
    For each input: its name associated to the axes symbolic name and the axis position within the tensor
)NotImplementedErrorrX   s    r5   inputsOnnxConfig.inputs   s     "##r4   c                 `    U R                   U R                     n[        R                  " U5      $ )z
Mapping containing the axis definition of the output tensors to provide to the model

Returns:
    For each output: its name associated to the axes symbolic name and the axis position within the tensor
)rP   rL   copydeepcopy)rX   common_outputss     r5   outputsOnnxConfig.outputs   s'     66tyyA}}^,,r4   c                 B    [        U R                  S5      (       a  SS0$ g)z
Dictionary of keys to override in the model's config before exporting

Returns:
    Dictionary with the keys (and their corresponding values) to override
	use_cacheFN)hasattrrO   re   s    r5   values_overrideOnnxConfig.values_override   s#     4<<--''r4   c                 "    [         R                  $ )zP
The default batch size to use if no other indication

Returns:
    Integer > 0
)r7   default_fixed_batchre   s    r5   default_batch_sizeOnnxConfig.default_batch_size   s     ---r4   c                 "    [         R                  $ )zU
The default sequence length to use if no other indication

Returns:
    Integer > 0
)r7   default_fixed_sequencere   s    r5   default_sequence_length"OnnxConfig.default_sequence_length   s     000r4   c                 "    [         R                  $ )zW
The default number of choices to use if no other indication

Returns:
    Integer > 0
)r7   default_fixed_num_choicesre   s    r5   default_num_choicesOnnxConfig.default_num_choices   s     333r4   c                     [         $ )z[
Which onnx opset to use when exporting the model

Returns:
    Integer ONNX Opset version
)DEFAULT_ONNX_OPSETre   s    r5   default_onnx_opsetOnnxConfig.default_onnx_opset   s
     "!r4   c                     g)zx
What absolute tolerance value to use during model conversion validation.

Returns:
    Float absolute tolerance value.
gh㈵>r+   re   s    r5   atol_for_validationOnnxConfig.atol_for_validation   s     r4   c                 ~    [        5       (       a.  SSKJn  [        R                  " U" 5       5      U R
                  :  $ g)z
The minimum PyTorch version required to export the model.

Returns:
    `bool`: Whether the installed version of PyTorch is compatible with the model.
r   )get_torch_versionF)r   transformers.utilsr   r   parsetorch_onnx_minimum_version)rX   r   s     r5   is_torch_support_available%OnnxConfig.is_torch_support_available   s1     <==!2!459X9XXXr4   num_parametersc                 D    [        U [        R                  5      [        :  $ )z
Flag indicating if the model requires using external data format

Args:
    num_parameters: Number of parameter on the model

Returns:
    True if model.num_parameters() * size_of(float32) >= 2Gb False otherwise
)r   r   FloatEXTERNAL_DATA_FORMAT_SIZE_LIMIT)r   s    r5   use_external_data_format#OnnxConfig.use_external_data_format   s!     /~?T?TU./	
r4   
batch_sizenum_channelsimage_heightimage_widthc                     / n[        U5       Hi  n[        R                  R                  X4U5      S-  nUR	                  [
        R                  " UR                  S5      5      R                  S5      5        Mk     U$ )N   uint8RGB)	rangenprandomrandrW   r!   	fromarrayastypeconvert)rX   r   r   r   r   images_datas           r5   _generate_dummy_images!OnnxConfig._generate_dummy_images  sa     z"A99>>,\JSPDMM%//$++g*>?GGNO # r4   sampling_ratetime_duration	frequencyc           	          / n[        U5       Hd  n[        R                  " SU[        X2-  5      SS9nUR	                  S[        R
                  " S[        R                  -  U-  U-  5      -  5        Mf     U$ )Nr   F)endpointg      ?r   )r   r   linspaceintrW   sinpi)rX   r   r   r   r   
audio_datar   ts           r5   _generate_dummy_audio OnnxConfig._generate_dummy_audio  sm     
z"AA}c-2O.P[`aA cBFF1ruu9y+@1+D$EEF # r4   preprocessor)r    r   r   
seq_lengthnum_choicesis_pair	framework	tokenizerr    c                    SSK Jn  SSKJn  SSKJn  [        UU5      (       a  Ub  [        S5      eUb2  [        R                  " S[        5        [        R                  S5        Un[        UU5      (       Ga7  [        U[        R                  SS	9nUR!                  U5      n[        U[        R"                  US	9nUR$                  b%  ['        UR$                  5      S:  a  UR$                  OS
nSR)                  U/5      U-  /U-  nU R*                  S:X  a  [        U[        R,                  SS	9nUU-  nU" UUS9nUR/                  5        H6  u  nn[1        S['        U5      U5       Vs/ s H  nUUUU-    PM     snUU'   M8     [3        UR5                  US95      $ [3        U" UUS95      $ [        X5      (       a  UR6                  S   S:w  a2  [        SUR8                  R:                   SUR6                  S    35      e[        U[        R                  S9nU R=                  X'X5      n[3        U" UUS95      $ [        X5      (       aM  UR6                  S   S:X  a:  [        U[        R                  S9nU R=                  X'X5      n[3        U" UUS95      $ [        X5      (       aM  UR6                  S   S:X  a:  [        U[        R                  S9nU R?                  X*X5      n[3        U" UUS95      $ [        S5      es  snf )a  
Generate inputs to provide to the ONNX exporter for the specific framework

Args:
    preprocessor: ([`PreTrainedTokenizerBase`], [`FeatureExtractionMixin`], or [`ImageProcessingMixin`]):
        The preprocessor associated with this model configuration.
    batch_size (`int`, *optional*, defaults to -1):
        The batch size to export the model for (-1 means dynamic axis).
    num_choices (`int`, *optional*, defaults to -1):
        The number of candidate answers provided for multiple choice task (-1 means dynamic axis).
    seq_length (`int`, *optional*, defaults to -1):
        The sequence length to export the model for (-1 means dynamic axis).
    is_pair (`bool`, *optional*, defaults to `False`):
        Indicate if the input is a pair (sentence 1, sentence 2)
    framework (`TensorType`, *optional*, defaults to `None`):
        The framework (PyTorch or TensorFlow) that the tokenizer will generate tensors for.
    num_channels (`int`, *optional*, defaults to 3):
        The number of channels of the generated images.
    image_width (`int`, *optional*, defaults to 40):
        The width of the generated images.
    image_height (`int`, *optional*, defaults to 40):
        The height of the generated images.
    sampling_rate (`int`, *optional* defaults to 22050)
        The sampling rate for audio data generation.
    time_duration (`float`, *optional* defaults to 5.0)
        Total seconds of sampling for audio data generation.
    frequency (`int`, *optional* defaults to 220)
        The desired natural frequency of generated audio.

Returns:
    Mapping[str, Tensor] holding the kwargs to provide to the model's forward function
r   r   r   r   zPYou cannot provide both a tokenizer and a preprocessor to generate dummy inputs.ztThe `tokenizer` argument is deprecated and will be removed in version 5 of Transformers. Use `preprocessor` instead.zROverwriting the `preprocessor` argument with `tokenizer` to generate dummy inputs.r   )fixed_dimensionnum_token_to_add0 rJ   )	text_pair)tensor_type)return_tensorspixel_valuesz*The `preprocessor` is an image processor (zC) and expects `model_input_names[0]` to be "pixel_values", but got )r   )r   r   input_featuresz\Unable to generate dummy inputs for the model. Please provide a tokenizer or a preprocessor.) feature_extraction_utilsr   image_processing_utilsr   tokenization_utils_baser    
isinstancerQ   warningswarnFutureWarningloggerwarningr   r7   rt   num_special_tokens_to_addrx   	unk_tokenlenjoinrL   r|   itemsr   dictconvert_to_tensorsmodel_input_names	__class__r,   r   r   )rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    token_to_addinput_tokendummy_inputtokenized_inputkvis                           r5   generate_dummy_inputs OnnxConfig.generate_dummy_inputs  s   ` 	FAEl$;<<AVopp MM+
 NNop$Ll$;<<9J,J,J]^J (AA'JL9J,M,M`lJ !**63|?U?U;VYZ;Z && 
 88[M2Z?@:MKyy-- ?1U1Uhi *K7".{k"R+113DAqJOPQSVWXSY[fJg)hJgQ!AK*@Jg)hOA& 4O>>9>UVV[KLL;;--a0NB @AWAWA`A`@a bMMYMkMklmMnLoq 
 :*V`VtVtuJ55jP\jKK	RSS==,B`B`abBcguBu9*V`VtVtuJ55jP\jKK	RSS|<<A_A_`aAbfvAv :*V`VtVtuJ44ZP]iK[KLLn 5 *is   ,Lreference_model_inputsc                     U$ )a  
Generate inputs for ONNX Runtime using the reference model inputs. Override this to run inference with seq2seq
models which have the encoder and decoder exported as separate ONNX files.

Args:
    reference_model_inputs ([`Mapping[str, Tensor]`):
        Reference inputs for the model.

Returns:
    `Mapping[str, Tensor]`: The mapping holding the kwargs to provide to the model's forward function
r+   )rX   r   s     r5   !generate_dummy_inputs_onnxruntime,OnnxConfig.generate_dummy_inputs_onnxruntime  s
     &%r4   c                     U R                    HX  nUR                  c  UR                  OUR                  UR                  5      n[        UR                  UR
                  U5        MZ     g N)rS   r*   r(   setattrr&   r'   )rX   rY   r(   s      r5   	patch_opsOnnxConfig.patch_ops  sJ    ((D*.//*AtW[WeWeGfIDFFDIIy1 )r4   c                     U R                    HX  nUR                  c  UR                  OUR                  UR                  5      n[        UR                  UR
                  U5        MZ     g r   )rS   r*   r)   r   r&   r'   )rX   rY   r)   s      r5   restore_opsOnnxConfig.restore_ops  sJ    ((D&*oo&=dll4??SWS_S_C`GDFFDIIw/ )r4   r'   fieldc                     SSK Jn  [        UR                  U5      5       VVs0 s H  u  pEU SU 3U_M     snn$ s  snnf )aK  
Flatten any potential nested structure expanding the name of the field with the index of the element within the
structure.

Args:
    name: The name of the nested structure
    field: The structure to, potentially, be flattened

Returns:
    (Dict[str, Any]): Outputs with flattened structure and key mapping this new structure.

r   )chain.)	itertoolsr   	enumeratefrom_iterable)r`   r'   r   r   idxitems         r5   "flatten_output_collection_property-OnnxConfig.flatten_output_collection_property  sC     	$7@ATATUZA[7\]7\)#4&#%7\]]]s   <)rO   rS   rL   )rI   NrI   )r   rG   (   r   )r   "V        @   )r   r   FNrG   r   r   r   r   r   N)2r,   r-   r.   r/   r0   rt   rx   r|   r   r   r   r   rP   r2   r   r   r$   r[   classmethodra   propertyr   r   r   rf   rl   r   rq   ru   ry   r}   r   floatr   boolr   staticmethodr   r   r   r   r   r   r   r   r   r
   r	   r   r3   r+   r4   r5   r7   r7   D   s     !!(u!5 (J,G!HI 3Z5PQR +X7z7R,S T)%*5")j9")j9
 !(J,G!HI (J,G!HI&1g,'?@'%*5")j9
 *$+
 ;")j9
 "-hGYafm8n-o!p!8=O-P"QR#.1g,/G#H +X7z7R,S T$hG
0K%LM$hG
0K%LM?  F qu4(4034QYZ^_kZlQm4$ 
&'9 
& 
&Ua 
& 
& $WS#X%6 67 $  $ -gc3h&7!78 - - 
'#s(*;!< 
 
 .C . . 1 1 1 4S 4 4 "C " " U   D   
 
 
 
" fh14HK_b mp25NSfi  *.""9=vghv v 	v
 v v J'v v v v v v v 56v 
c	vp&PSUXPXHY &^efiknfn^o &2
0
 ^c ^(3- ^TXY\^aYaTb ^ ^r4   r7   c                     ^  \ rS rSr   SSSS\S\\\      S\4U 4S jjjr	\
SSSS\SS 4S	 jj5       r\S\\\\\4   4   4U 4S
 jj5       r\S\\\\4      4S j5       r\S\4S j5       r\S\4S j5       r    S SSS\S\S\S\\   S\\\4   4U 4S jjjr S!S\\\\\4   4   S\S\4S jjrS rS\S\\   S\\\4   4U 4S jjrSrU =r$ )"OnnxConfigWithPasti  rK   r   rL   rM   use_pastc                 .   > [         TU ]  XUS9  X@l        g )N)rL   rM   )superr[   r  )rX   rK   rL   rM   r  r   s        r5   r[   OnnxConfigWithPast.__init__  s     	>J r4   r]   c                     U " XSS9$ )z
Instantiate a OnnxConfig with `use_past` attribute set to True

Args:
    config: The underlying model's config to use when exporting to ONNX

Returns:
    OnnxConfig with `.use_past = True`
T)rL   r  r+   r_   s      r5   	with_pastOnnxConfigWithPast.with_past  s     6t44r4   c                 ^   > [         TU ]  nU R                  (       a  U R                  USS9  U$ )Nrl   	direction)r  rl   r  fill_with_past_key_values_)rX   rk   r   s     r5   rl   OnnxConfigWithPast.outputs  s,    ==++Ni+Pr4   c                 V    [        U R                  S5      (       a  SU R                  0$ g )Nro   )rp   rO   r  re   s    r5   rq   "OnnxConfigWithPast.values_override  s%    4<<--//r4   c                 z    [        U R                  S5      (       d  [        S5      eU R                  R                  $ )z
The number of layers attribute retrieved from the model config. Override this for model configs where the
number of layers attribute is not called `num_layers`.

num_layerszcould not find the number of layers attribute in the model configuration, override the num_layers property of the model OnnxConfig to solve this)rp   rO   AttributeErrorr  re   s    r5   r  OnnxConfigWithPast.num_layers  s:     t||\22 B  ||&&&r4   c                 z    [        U R                  S5      (       d  [        S5      eU R                  R                  $ )z
The number of attention heads attribute retrieved from the model config. Override this for model configs where
the number of attention heads attribute is not called `num_attention_heads`.
num_attention_headszcould not find the number of attention heads attribute in the model configuration, override the num_attention_heads property of the model OnnxConfig to solve this)rp   rO   r  r  re   s    r5   r  &OnnxConfigWithPast.num_attention_heads  s;     t||%:;; V  ||///r4   r   r    r   r   r   r   c           	      2  > [         TU ]  XX4US9nU R                  (       a  [        5       (       d  [	        S5      eSS KnUS   R                  u  pU	S-   n
UU R                  U
U R                  R                  U R                  -  4nSU;   a5  US   R                  nUR                  US   UR                  XUS9/SS	9US'   / US
'   [        U R                  5       H7  nUS
   R                  UR!                  U5      UR!                  U5      45        M9     U$ )Nr   r   r   r   ACannot generate dummy past_keys inputs without PyTorch installed.r   	input_idsr   attention_mask)dtyper   )dimpast_key_values)r  r   r  r   rQ   torchshaper  rO   hidden_sizer  catonesr   r  rW   zeros)rX   r   r   r   r   r   common_inputsr   r<   seqlenpast_key_values_lengthr!  
mask_dtyper   r   s                 r5   r   (OnnxConfigWithPast.generate_dummy_inputs  s3    5`i 6 
 ==%'' !dee)+6<<ME%+aZ"((&((D,D,DD	E  =0*+;<BB
27))"#34ejjfpj6qr 3< 3./
 02M+,4??+/077U9KU[[Y^M_8`a , r4   inputs_or_outputsr  inverted_values_shapec                     US;  a  [        SU S35      eUS:X  a  SOSn[        U R                  5       H3  nSSS	.X S
U S3'   U(       a  SSS.X S
U S3'   M&  SSS	.X S
U S3'   M5     g)a  
Fill the input_or_outputs mapping with past_key_values dynamic axes considering.

Args:
    inputs_or_outputs: The mapping to fill.
    direction: either "inputs" or "outputs", it specifies whether input_or_outputs is the input mapping or the
        output mapping, this is important for axes naming.
    inverted_values_shape:
        If `True`, store values on dynamic axis 1, else on axis 2.

rf   rl   4direction must either be "inputs" or "outputs", but 
 was givenrf   r  presentr<   zpast_sequence + sequencer   r   r   .keyr>   .valueN)rQ   r   r  )rX   r+  r  r,  r'   r   s         r5   r  -OnnxConfigWithPast.fill_with_past_key_values_(  s     11ST]S^^hijj$-$9 yt'A7>C]3^as$/0$=DIc9d!F!A3f"56=DIc9d!F!A3f"56 (r4   c                 8    US   X SU S3'   US   X SU S3'   g )Nr   r   r3  r   r4  r+   rX   flattened_outputr'   r   r   s        r5   _flatten_past_key_values_,OnnxConfigWithPast._flatten_past_key_values_A  s6    01!63%t,-23A$63%v./r4   r'   r   c                    > 0 nUS;   a(  [        U5       H  u  pEU R                  X1XE5        M     U$ [        TU ]  X5      nU$ )N)r1  r  )r   r9  r  r   )rX   r'   r   r8  r   r   r   s         r5   r   5OnnxConfigWithPast.flatten_output_collection_propertyE  sT    11#E*../?sN +
    %wI$Vr4   )r  )rI   NFr   r   r   FN)F)r,   r-   r.   r/   r2   r   listr$   r   r[   r   r  r   r   r   rl   r   rq   r  r  r   r   r  r9  r
   r	   r   r3   __classcell__r   s   @r5   r  r    s    7;!"! ! !l!34	!
 ! ! 
51 
5 
5Ma 
5 
5 gc3h&7!78   '#s(*;!<   
'C 
' 
' 
0S 
0 
0 *.(,( ( 	(
 ( J'( 
c	( (V qve!(gc3h.?)?!@eMPeime27 s  8C=  UYZ]_bZbUc    r4   r  c                     ^  \ rS rSr\S\\\\\4   4   4U 4S jj5       r\S\	\   4U 4S jj5       r
\S\	\   4U 4S jj5       r    SS\S   S\S	\S
\S\\   S\\\4   4U 4S jjjrS\\\\\4   4   S\4S jrS rSrU =r$ )OnnxSeq2SeqConfigWithPastiP  r]   c                    > [         [        U ]
  nUR                  5        H8  u  p#SU;   a  SOSnUR                  5        H  u  pRSU;   a  XCU'   M  X#U'   M     M:     U R                  (       a  U R                  USS9  U$ )Nencoderencoder_sequencerH   r=   rl   r  )r  r  rl   r   r  r  )rX   rk   r'   
axes_namessequence_nameaxis_idxr   s         r5   rl   !OnnxSeq2SeqConfigWithPast.outputsQ  s    14@ . 4 4 6D2;t2C.I[M","2"2"4%+8x( ,0x( #5 !7 ==++Ni+Pr4   c                    >  [         TU ]  nX4nU$ ! [         aq    [        U R                  S5      (       aJ  [        U R                  S5      (       a/  U R                  R
                  U R                  R                  4n U$ [        S5      ef = f)Nencoder_layersdecoder_layerszcould not find the number of encoder and decoder layers attributes in the model configuration, override the num_layers property of the model OnnxConfig to solve this)r  r  r  rp   rO   rK  rL  )rX   r  r   s     r5   r  $OnnxSeq2SeqConfigWithPast.num_layersb  s    
	+J$1J   	t||%56674<<Qa;b;b"ll994<<;V;VW
  %^ 		    A,BBc                    >  [         TU ]  nX4nU$ ! [         aq    [        U R                  S5      (       aJ  [        U R                  S5      (       a/  U R                  R
                  U R                  R                  4n U$ [        S5      ef = f)Nencoder_attention_headsdecoder_attention_headszcould not find the number of attention heads for the encoder and the decoder attributes in the model configuration, override the num_attention_heads property of the model OnnxConfig to solve this)r  r  r  rp   rO   rP  rQ  )rX   r  r   s     r5   r  -OnnxSeq2SeqConfigWithPast.num_attention_headsr  s    	"''"=#6"L #"  	t||%>??GDLLZsDtDt'+||'K'KT\\MqMq&r# #" % 		rN  r   r    r   r   r   r   c           	      8  > [         [        U ]  XX4US9nU R                  (       d  UOSn[         [        U ]  XXtUS9nUR	                  5        V	V
s0 s H  u  pSU	 3U
_M     nn	n
[        S0 UDUD6nU R                  (       Ga  [        5       (       d  [        S5      eSS KnUS   R                  S   nUS   R                  S   nUS   R                  S   nU R                  u  nnUUUU R                  R                  U-  4nUUUS-   U R                  R                  U-  4n/ US	'   U R                  u  nn[        UU5      n[        UU5      U-
  nUU:  a  S
OSn[!        U5       HW  nUS	   R#                  UR%                  U5      UR%                  U5      UR%                  U5      UR%                  U5      45        MY     US
:X  a  UOUn[!        UU5       H7  nUS	   R#                  UR%                  U5      UR%                  U5      45        M9     U$ s  sn
n	f )Nr  r   decoder_r  r   r  decoder_input_idsrG   r  rD  decoderr+   )r  r  r   r  r   r   r   rQ   r   r!  r  rO   r"  r  minmaxr   rW   r%  )rX   r   r   r   r   r   encoder_inputsdecoder_seq_lengthdecoder_inputsr'   tensorr&  r   r<   encoder_seq_lengthnum_encoder_attention_headsnum_decoder_attention_headsencoder_shapedecoder_shapenum_encoder_layersnum_decoder_layersmin_num_layersmax_num_layersremaining_side_namer   r!  r   s                             r5   r   /OnnxSeq2SeqConfigWithPast.generate_dummy_inputs  s`    14N`i O 

 04}}Z!14N9Khq O 
 IWH\H\H^_H^HTF+V3H^_@~@@===%'' !dee!+.44Q7E!.{!;!A!A!!D!./B!C!I!I!!LGKG_G_D')D+"((,GG	M +"Q&((,GGM 02M+,59__2 2 !35GHN !35GH>YN/ADV/V)\e>* /077M2M2M2M2	 + &9I%EM=E>>:/077U9KU[[Y^M_8`a ; e `s   Hr+  r  c           	         US;  a  [        SU S35      eUS:X  a  SOSnU R                  u  pE[        XE5      n[        XE5      U-
  nXE:  a  SOSnS	n	US:X  a  S
OSn
[	        U5       H7  nSU
S.X SU S3'   SU
S.X SU S3'   SU	S.X SU S3'   SU	S.X SU S3'   M9     [	        Xg5       H!  nUS:X  a  SU	S.nOSU
S.nXU SU SU S3'   M#     g )Nr.  r/  r0  rf   r  r1  rD  rV  past_encoder_sequencepast_decoder_sequencez past_decoder_sequence + sequencer<   r2  r   .decoder.key.decoder.value.encoder.key.encoder.valuer3  )rQ   r  rW  rX  r   )rX   r+  r  r'   rb  rc  rd  re  rf  rE  rH   r   	axes_infos                r5   r  4OnnxSeq2SeqConfigWithPast.fill_with_past_key_values_  sL   11ST]S^^hijj$-$9 y 26./D/D~U+=+RiXa26?86K2Qs~&A?FK[;\as,78AHM]=^as.9:?FK[;\as,78AHM]=^as.9:	 ' ~6A"i/ ',<=	 ',<=	IRas!,?+@EF 7r4   c                 l    US   X SU S3'   US   X SU S3'   US   X SU S3'   US   X SU S	3'   g )
Nr   r   rk  r   rl  r   rm  rG   rn  r+   r7  s        r5   r9  3OnnxSeq2SeqConfigWithPast._flatten_past_key_values_  sj    89!63%|45:;A$63%~6789!63%|45:;A$63%~67r4   r+   r=  )r,   r-   r.   r/   r   r   r2   r   rl   r   r  r  r   r   r   r   r   r  r9  r3   r?  r@  s   @r5   rB  rB  P  s   gc3h&7!78    E#J   #U3Z # #$ *.C56C C 	C
 C J'C 
c	C CJSGCQTVYQYIZDZ<[ Shk S8? ?r4   rB  )3ri   rT   r   abcr   r   collectionsr   typingr   r   r   r	   r
   r   r   r   r   r   numpyr   	packagingr   utilsr   r   r   r   r   r   r   configuration_utilsr   r   r   r   r   r   r    PILr!   
get_loggerr,   r   r   r   	dataclassr$   r7   r  rB  r+   r4   r5   <module>r}     s       # # f f f   P P h h 6A=A 			H	%   #9  * * *(v^ v^rP S P fW? 2 W?r4   