
    is                        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
  S SK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&  \RN                  " \(5      r)Sr*Sr+\RX                   " S S5      5       r- " S S\5      r. " S S\.\5      r/ " S S\/5      r0g)    N)ABCabstractmethod)OrderedDict)IterableMapping)TYPE_CHECKINGAnyCallableOptional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)
PatchingSpec0   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(       h/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/transformers/onnx/config.pyr!   r!   0   s7    
 F
I"&GXh&%)J")r1   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
OnnxConfigE   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)r8   
pred_boxes
pred_masksr   )r8   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keysrI   _patching_specsr&   dataclassesreplacegetattrr#   r$   append)selfrH   rI   rJ   spec
final_specs         r2   __init__OnnxConfig.__init__p   s     444&CDDaDaDfDfDhCij  	!&4&@NbHDJ||#(00wtvvtyy?YZ
  ''
3	 Ir1   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
)rI   r(   clsrH   rI   s      r2   from_model_configOnnxConfig.from_model_config   s     6%%r1   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rU   s    r2   inputsOnnxConfig.inputs   s     "##r1   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
)rM   rI   copydeepcopy)rU   common_outputss     r2   outputsOnnxConfig.outputs   s'     66tyyA}}^,,r1   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)hasattrrL   rb   s    r2   values_overrideOnnxConfig.values_override   s#     4<<--''r1   c                 "    [         R                  $ )zP
The default batch size to use if no other indication

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

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

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

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

Returns:
    Float absolute tolerance value.
gh㈵>r(   rb   s    r2   atol_for_validationOnnxConfig.atol_for_validation   s     r1   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)rU   r   s     r2   is_torch_support_available%OnnxConfig.is_torch_support_available   s1     <==!2!459X9XXXr1   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    r2   use_external_data_format#OnnxConfig.use_external_data_format   s!     /~?T?TU./	
r1   
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randrT   r   	fromarrayastypeconvert)rU   r   r   r   r   images_datas           r2   _generate_dummy_images!OnnxConfig._generate_dummy_images  sa     z"A99>>,\JSPDMM%//$++g*>?GGNO # r1   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intrT   sinpi)rU   r   r   r   r   
audio_datar   ts           r2   _generate_dummy_audio OnnxConfig._generate_dummy_audio  sm     
z"AA}c-2O.P[`aA cBFF1ruu9y+@1+D$EEF # r1   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 rG   )	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   
isinstancerN   warningswarnFutureWarningloggerwarningr   r4   rq   num_special_tokens_to_addru   	unk_tokenlenjoinrI   ry   itemsr   dictconvert_to_tensorsmodel_input_names	__class__r)   r   r   )rU   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                           r2   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(   )rU   r   s     r2   !generate_dummy_inputs_onnxruntime,OnnxConfig.generate_dummy_inputs_onnxruntime  s
     &%r1   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)rP   r'   r%   setattrr#   r$   )rU   rV   r%   s      r2   	patch_opsOnnxConfig.patch_ops  sJ    ((D*.//*AtW[WeWeGfIDFFDIIy1 )r1   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   )rP   r'   r&   r   r#   r$   )rU   rV   r&   s      r2   restore_opsOnnxConfig.restore_ops  sJ    ((D&*oo&=dll4??SWS_S_C`GDFFDIIw/ )r1   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         r2   "flatten_output_collection_property-OnnxConfig.flatten_output_collection_property  sC     	$7@ATATUZA[7\]7\)#4&#%7\]]]s   <)rL   rP   rI   )rF   NrF   )r   rD   (   r   )r   "V        @   )r   r   FNrD   r   r   r   r   r   N)2r)   r*   r+   r,   r-   rq   ru   ry   r   r   r   r   rM   r/   r   listr!   rX   classmethodr^   propertyr   r   r   rc   ri   r	   rn   rr   rv   rz   r~   floatr   boolr   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r0   r(   r1   r2   r4   r4   E   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 ^ ^r1   r4   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  rH   r   rI   rJ   use_pastc                 .   > [         TU ]  XUS9  X@l        g )N)rI   rJ   )superrX   r  )rU   rH   rI   rJ   r  r   s        r2   rX   OnnxConfigWithPast.__init__  s     	>J r1   rZ   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)rI   r  r(   r\   s      r2   	with_pastOnnxConfigWithPast.with_past  s     6t44r1   c                 ^   > [         TU ]  nU R                  (       a  U R                  USS9  U$ )Nri   	direction)r  ri   r  fill_with_past_key_values_)rU   rh   r   s     r2   ri   OnnxConfigWithPast.outputs  s,    ==++Ni+Pr1   c                 V    [        U R                  S5      (       a  SU R                  0$ g )Nrl   )rm   rL   r  rb   s    r2   rn   "OnnxConfigWithPast.values_override  s%    4<<--//r1   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)rm   rL   AttributeErrorr  rb   s    r2   r  OnnxConfigWithPast.num_layers  s:     t||\22 B  ||&&&r1   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)rm   rL   r  r  rb   s    r2   r  &OnnxConfigWithPast.num_attention_heads  s;     t||%:;; V  ||///r1   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   rN   torchshaper  rL   hidden_sizer  catonesr   r  rT   zeros)rU   r   r   r   r   r   common_inputsr  r9   seqlenpast_key_values_lengthr  
mask_dtyper   r   s                 r2   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 , r1   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.

rc   ri   4direction must either be "inputs" or "outputs", but 
 was givenrc   r  presentr9   zpast_sequence + sequencer   r   r   .keyr;   .valueN)rN   r   r  )rU   r)  r
  r*  r$   r   s         r2   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 (r1   c                 8    US   X SU S3'   US   X SU S3'   g )Nr   r   r1  r   r2  r(   rU   flattened_outputr$   r   r   s        r2   _flatten_past_key_values_,OnnxConfigWithPast._flatten_past_key_values_B  s6    01!63%t,-23A$63%v./r1   r$   r   c                    > 0 nUS;   a(  [        U5       H  u  pEU R                  X1XE5        M     U$ [        TU ]  X5      nU$ )N)r/  r  )r   r7  r  r   )rU   r$   r   r6  r   r   r   s         r2   r   5OnnxConfigWithPast.flatten_output_collection_propertyF  sT    11#E*../?sN +
    %wI$Vr1   )r  )rF   NFr   r   r   FN)F)r)   r*   r+   r,   r/   r   r   r!   r   rX   r   r  r   r   r   ri   r	   rn   r  r  r   r   r  r7  r   r   r   r0   __classcell__r   s   @r2   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    r1   r   c                     ^  \ rS rSr\S\\\\\4   4   4U 4S jj5       r\S\	\S4   4U 4S jj5       r
\S\	\S4   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$ )OnnxSeq2SeqConfigWithPastiQ  rZ   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_sequencerE   r:   ri   r	  )r  r   ri   r   r  r  )rU   rh   r$   
axes_namessequence_nameaxis_idxr   s         r2   ri   !OnnxSeq2SeqConfigWithPast.outputsR  s    14@ . 4 4 6D2;t2C.I[M","2"2"4%+8x( ,0x( #5 !7 ==++Ni+Pr1   .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  rm   rL   rH  rI  )rU   r  r   s     r2   r  $OnnxSeq2SeqConfigWithPast.num_layersc  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  rm   rL   rM  rN  )rU   r  r   s     r2   r  -OnnxSeq2SeqConfigWithPast.num_attention_headss  s    	"''"=#6"L #"  	t||%>??GDLLZsDtDt'+||'K'KT\\MqMq&r# #" % 		rK  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_idsrD   r  rA  decoderr(   )r  r   r   r  r   r   r   rN   r  r  r  rL   r   r  minmaxr   rT   r#  )rU   r   r   r   r   r   encoder_inputsdecoder_seq_lengthdecoder_inputsr$   tensorr$  r  r9   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                             r2   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-  r.  rc   r  r/  rA  rS  past_encoder_sequencepast_decoder_sequencez past_decoder_sequence + sequencer9   r0  r   .decoder.key.decoder.value.encoder.key.encoder.valuer1  )rN   r  rT  rU  r   )rU   r)  r
  r$   r_  r`  ra  rb  rc  rB  rE   r   	axes_infos                r2   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 7r1   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   rh  r   ri  r   rj  rD   rk  r(   r5  s        r2   r7  3OnnxSeq2SeqConfigWithPast._flatten_past_key_values_  sj    89!63%|45:;A$63%~6789!63%|45:;A$63%~67r1   r(   r;  )r)   r*   r+   r,   r   r   r/   r   ri   tupler  r  r   r   r   r	   r   r  r7  r0   r<  r=  s   @r2   r?  r?  Q  s   gc3h&7!78    E#s(O   #U38_ # #$ *.C56C C 	C
 C J'C 
c	C CJSGCQTVYQYIZDZ<[ Shk S8? ?r1   r?  )1rf   rQ   r   abcr   r   collectionsr   collections.abcr   r   typingr   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!   r4   r   r?  r(   r1   r2   <module>r|     s       # # - @ @   P P h h 6A=A 			H	%   #9  * * *(v^ v^rP S P fW? 2 W?r1   