o
    §ôj,  ã                   @   sF  d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlmZ ddlmZmZmZmZ dd	lmZmZmZ e	rldd
lm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& eƒ rud dl'm(Z( e )e*¡Z+dZ,dZ-ej.G dd„ dƒƒZ/G dd„ deƒZ0G dd„ de0eƒZ1G dd„ de1ƒZ2dS )é    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                   @   sJ   e Zd ZU dZeed< eed< eed< dZe	e ed< dZ
e	e ed< dS )ÚPatchingSpeca½  
    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__Ú__doc__r   Ú__annotations__Ústrr   r&   r   r'   © r.   r.   úi/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/transformers/onnx/config.pyr"   /   s   
 r"   c                   @   s\  e Zd ZdZdZdZdZe d¡Z	e
dddd	œiƒe
d
ddd	œiƒe
dddd	œiƒe
ddd	œddd	œddd	œdœƒe
dddd	œiƒe
dddd	œiƒe
dddiiƒe
ddd	œddd	œdœƒe
ddd	œddd	œdœƒe
ddddddœiƒe
dddd	œiƒe
dddiiƒe
dddd	œiƒe
dddd	œiƒe
dddd	œiƒdœZd\dddedee fdd„Zed]dddedd fdd„ƒZeedeeeeef f fd d!„ƒƒZedeeeeef f fd"d#„ƒZedeeeef  fd$d%„ƒZedefd&d'„ƒZedefd(d)„ƒZedefd*d+„ƒZedefd,d-„ƒZedefd.d/„ƒZ ede!fd0d1„ƒZ"e#d2ede!fd3d4„ƒZ$	6d^d7ed8ed9ed:efd;d<„Z%	?d_d7ed@edAedBefdCdD„Z&	E	E	E	F		5	6	6	=	>	?	d`dGe'dH d7edIedJedKe!dLee( d8ed:ed9ed@edAedBedMdNdeeef fdOdP„Z)dQeeef deeef fdRdS„Z*dTdU„ Z+dVdW„ Z,edXedYe-e de.eef fdZd[„ƒZ/dS )aÚ
OnnxConfigzv
    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)r3   Ú
pred_boxesÚ
pred_masksr   )r3   r8   )Ú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-lmrA   NÚconfigr   ÚtaskÚpatching_specsc                 C   s€   || _ || jvrt|› d| j ¡ › �ƒ‚|| _g | _|d ur |ng D ]}|}|jd u r7tj|t	|j
|jƒd�}| j |¡ q"d S )Nz+ is not a supported task, supported tasks: )r&   )Ú_configÚ_tasks_to_common_outputsÚ
ValueErrorÚkeysrD   Ú_patching_specsr&   ÚdataclassesÚreplaceÚgetattrr#   r$   Úappend)ÚselfrC   rD   rE   ÚspecZ
final_specr.   r.   r/   Ú__init__o   s   
ÿ
üzOnnxConfig.__init__Úreturnc                 C   s   | ||d�S )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
        )rD   r.   ©ÚclsrC   rD   r.   r.   r/   Úfrom_model_config   s   zOnnxConfig.from_model_configc                 C   s   t ƒ ‚)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©rO   r.   r.   r/   ÚinputsŒ   ó   	zOnnxConfig.inputsc                 C   s   | j | j }t |¡S )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
        )rG   rD   ÚcopyÚdeepcopy©rO   Úcommon_outputsr.   r.   r/   Úoutputs—   s   
zOnnxConfig.outputsc                 C   s   t | jdƒr
ddiS dS )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)ÚhasattrrF   rW   r.   r.   r/   Úvalues_override¢   s   zOnnxConfig.values_overridec                 C   ó   t jS )zp
        The default batch size to use if no other indication

        Returns:
            Integer > 0
        )r0   Údefault_fixed_batchrW   r.   r.   r/   Údefault_batch_size¯   rY   zOnnxConfig.default_batch_sizec                 C   rb   )zu
        The default sequence length to use if no other indication

        Returns:
            Integer > 0
        )r0   Údefault_fixed_sequencerW   r.   r.   r/   Údefault_sequence_lengthº   ó   z"OnnxConfig.default_sequence_lengthc                 C   rb   )zw
        The default number of choices to use if no other indication

        Returns:
            Integer > 0
        )r0   Údefault_fixed_num_choicesrW   r.   r.   r/   Údefault_num_choicesÄ   rg   zOnnxConfig.default_num_choicesc                 C   s   t S )z{
        Which onnx opset to use when exporting the model

        Returns:
            Integer ONNX Opset version
        )ÚDEFAULT_ONNX_OPSETrW   r.   r.   r/   Údefault_onnx_opsetÎ   ó   zOnnxConfig.default_onnx_opsetc                 C   s   dS )z˜
        What absolute tolerance value to use during model conversion validation.

        Returns:
            Float absolute tolerance value.
        gñhãˆµøä>r.   rW   r.   r.   r/   Úatol_for_validationØ   rl   zOnnxConfig.atol_for_validationc                 C   s(   t ƒ rddlm} t |ƒ ¡| jkS dS )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.utilsrn   r   ÚparseÚtorch_onnx_minimum_version)rO   rn   r.   r.   r/   Úis_torch_support_availableâ   s   z%OnnxConfig.is_torch_support_availableÚnum_parametersc                 C   s   t | tjƒtkS )a  
        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)rs   r.   r.   r/   Úuse_external_data_formatñ   s   
ÿÿz#OnnxConfig.use_external_data_formatr?   é(   Ú
batch_sizeÚnum_channelsÚimage_heightÚimage_widthc                 C   sF   g }t |ƒD ]}tj |||¡d }| t | d¡¡ d¡¡ q|S )Néÿ   Úuint8ÚRGB)	ÚrangeÚnpÚrandomÚrandrN   r    Ú	fromarrayÚastypeÚconvert)rO   rx   ry   rz   r{   ÚimagesÚ_Údatar.   r.   r/   Ú_generate_dummy_images  s
   z!OnnxConfig._generate_dummy_imagesé"V  ç      @éÜ   Úsampling_rateÚtime_durationÚ	frequencyc                 C   sR   g }t |ƒD ] }tjd|t|| ƒdd�}| dt dtj | | ¡ ¡ q|S )Nr   F)Úendpointg      à?r   )r   r€   ÚlinspaceÚintrN   ÚsinÚpi)rO   rx   r�   rŽ   r�   Ú
audio_datar‡   Útr.   r.   r/   Ú_generate_dummy_audio  s
   $z OnnxConfig._generate_dummy_audioéÿÿÿÿFÚpreprocessor)r   r   r   Ú
seq_lengthÚnum_choicesÚis_pairÚ	frameworkÚ	tokenizerr   c                    sL  ddl m} ddlm} ddlm} t||ƒr|durtdƒ‚|dur0t 	dt
¡ t d¡ |}t||ƒr¨t|tjd	d
�}| |¡}t|tj|d
�}|jdurYt|jƒd	krY|jnd}d |g¡| g| }| jdkr tˆ tjd	d
�‰ |ˆ  }|||d�}| ¡ D ]\}‰‡ ‡fdd„td	tˆƒˆ ƒD ƒ||< q�t|j|d�ƒS t|||d�ƒS t||ƒrÚ|jd	 dkrÃtd|jj› d|jd	 › �ƒ‚t|tjd�}|  |||	|¡}t|||d�ƒS t||ƒrý|jd	 dkrýt|tjd�}|  |||	|¡}t|||d�ƒS t||ƒ�r"|jd	 dk�r"t|tjd�}|  ||
||¡}t|||d�ƒS tdƒ‚)am  
        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   NzPYou 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.zSOverwriting the `preprocessor` argument with `tokenizer` to generate dummmy inputs.r   )Úfixed_dimensionZnum_token_to_addÚ0ú rB   )Ú	text_pairc                    s   g | ]
}ˆ||ˆ  … ‘qS r.   r.   )Ú.0Úi©r›   Úvr.   r/   Ú
<listcomp>r  ó    z4OnnxConfig.generate_dummy_inputs.<locals>.<listcomp>)Ú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   Ú
isinstancerH   ÚwarningsÚwarnÚFutureWarningÚloggerÚwarningr   r0   rc   Únum_special_tokens_to_addre   Ú	unk_tokenÚlenÚjoinrD   rh   Úitemsr   ÚdictÚconvert_to_tensorsÚmodel_input_namesÚ	__class__r(   r‰   r—   )rO   r™   rx   rš   r›   rœ   r�   ry   r{   rz   r�   rŽ   r�   rž   r   r   r   Ztoken_to_addZinput_tokenZdummy_inputZtokenized_inputÚkr.   r¥   r/   Úgenerate_dummy_inputs  st   0ý

ÿ
ÿÿý
ÿ&
ÿÿÿÿz OnnxConfig.generate_dummy_inputsÚreference_model_inputsc                 C   s   |S )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.   )rO   rÁ   r.   r.   r/   Ú!generate_dummy_inputs_onnxruntime�  s   z,OnnxConfig.generate_dummy_inputs_onnxruntimec                 C   ó<   | j D ]}|jd u r|jn| |j¡}t|j|j|ƒ qd S ©N)rJ   r'   r%   Úsetattrr#   r$   )rO   rP   r%   r.   r.   r/   Ú	patch_opsž  ó   
þzOnnxConfig.patch_opsc                 C   rÃ   rÄ   )rJ   r'   r&   rÅ   r#   r$   )rO   rP   r&   r.   r.   r/   Úrestore_ops£  rÇ   zOnnxConfig.restore_opsr$   Úfieldc                    s(   ddl m} ‡ fdd„t| |¡ƒD ƒS )a‹  
        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   )Úchainc                    s    i | ]\}}ˆ › d |› �|“qS )Ú.r.   )r£   ÚidxÚitem©r$   r.   r/   Ú
<dictcomp>¸  s     zAOnnxConfig.flatten_output_collection_property.<locals>.<dictcomp>)Ú	itertoolsrÊ   Ú	enumerateÚfrom_iterable)rT   r$   rÉ   rÊ   r.   rÎ   r/   Ú"flatten_output_collection_property¨  s   z-OnnxConfig.flatten_output_collection_property)rA   N©rA   )r   r?   rw   rw   )r   rŠ   r‹   rŒ   )r˜   r˜   r˜   FNr?   rw   rw   rŠ   r‹   rŒ   N)0r(   r)   r*   r+   rc   re   rh   r   rp   rq   r   rG   r-   r
   r"   rQ   ÚclassmethodrU   Úpropertyr   r   r’   rX   r^   r   r   ra   rd   rf   ri   rk   Úfloatrm   Úboolrr   Ústaticmethodrv   r‰   r—   r   r   rÀ   rÂ   rÆ   rÈ   r	   r   rÓ   r.   r.   r.   r/   r0   D   sú    
ýÿþÿþÿá""	 

				ÿÿÿÿ
ÿ
ÿÿÿÿ
ÿòþýüûúùø	÷
öõôóò

ñ"x(r0   c                       sR  e Zd Z			d*dddedee def‡ fd	d
„Zed+dddedd fdd„ƒZ	e
deeeeef f f‡ fdd„ƒZe
deeeef  fdd„ƒZe
defdd„ƒZe
defdd„ƒZ				d,dddedededee deeef f‡ fdd„Z	d-deeeeef f d ed!efd"d#„Zd$d%„ Zd&ed'ee deeef f‡ fd(d)„Z‡  ZS ).ÚOnnxConfigWithPastrA   NFrC   r   rD   rE   Úuse_pastc                    s   t ƒ j|||d� || _d S )N)rD   rE   )ÚsuperrQ   rÛ   )rO   rC   rD   rE   rÛ   ©r¾   r.   r/   rQ   ¼  s   
zOnnxConfigWithPast.__init__rR   c                 C   s   | ||dd�S )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)rD   rÛ   r.   rS   r.   r.   r/   Ú	with_pastÆ  s   zOnnxConfigWithPast.with_pastc                    s    t ƒ j}| jr| j|dd� |S )Nr^   ©Ú	direction)rÜ   r^   rÛ   Úfill_with_past_key_values_r\   rÝ   r.   r/   r^   Ó  s   zOnnxConfigWithPast.outputsc                 C   s   t | jdƒrd| jiS d S )Nr_   )r`   rF   rÛ   rW   r.   r.   r/   ra   Û  s   
z"OnnxConfigWithPast.values_overridec                 C   ó   t | jdƒs
tdƒ‚| jjS )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_layersz�could not find the number of layers attribute in the model configuration, override the num_layers property of the model OnnxConfig to solve this)r`   rF   ÚAttributeErrorrã   rW   r.   r.   r/   rã   â  ó
   ÿzOnnxConfigWithPast.num_layersc                 C   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_headsz¢could 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)r`   rF   rä   ræ   rW   r.   r.   r/   ræ   ï  rå   z&OnnxConfigWithPast.num_attention_headsr˜   rž   r   rx   rš   rœ   r�   c                    sÒ   t ƒ j|||||d�}| jrgtƒ stdƒ‚dd l}|d j\}}	|	d }
|| j|
| jj	| j f}d|v rL|d j
}|j|d |j||
|d�gdd	�|d< g |d
< t| jƒD ]}|d
  | |¡| |¡f¡ qU|S )N©rx   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   rH   ÚtorchÚshaperæ   rF   Úhidden_sizerë   ÚcatÚonesr   rã   rN   Úzeros)rO   rž   rx   rš   rœ   r�   Úcommon_inputsrî   r4   ÚseqlenÚpast_key_values_lengthrï   Z
mask_dtyper‡   rÝ   r.   r/   rÀ   ü  s0   	
ÿü

þ z(OnnxConfigWithPast.generate_dummy_inputsÚinputs_or_outputsrà   Úinverted_values_shapec                 C   s�   |dvrt d|› d�ƒ‚|dkrdnd}t| jƒD ],}ddd	œ||› d
|› d�< |r8dddœ||› d
|› d�< qddd	œ||› d
|› d�< qdS )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.

        ©rX   r^   ú4direction must either be "inputs" or "outputs", but ú
 was givenrX   rí   Úpresentr4   zpast_sequence + sequence©r   r   rË   ú.keyr6   ú.valueN)rH   r   rã   )rO   r÷   rà   rø   r$   r¤   r.   r.   r/   rá   &  s   ûz-OnnxConfigWithPast.fill_with_past_key_values_c                 C   s4   |d ||› d|› d�< |d ||› d|› d�< d S )Nr   rË   rþ   r   rÿ   r.   ©rO   Úflattened_outputr$   rÌ   r–   r.   r.   r/   Ú_flatten_past_key_values_?  s   z,OnnxConfigWithPast._flatten_past_key_values_r$   rÉ   c                    sD   i }|dv rt |ƒD ]\}}|  ||||¡ q
|S tƒ  ||¡}|S )N)rü   rí   )rÑ   r  rÜ   rÓ   )rO   r$   rÉ   r  rÌ   r–   rÝ   r.   r/   rÓ   C  s   þz5OnnxConfigWithPast.flatten_output_collection_property)rA   NFrÔ   ©r˜   r˜   FN)F)r(   r)   r*   r-   r
   r"   rØ   rQ   rÕ   rÞ   rÖ   r   r’   r^   r   r   ra   rã   ræ   r   rÀ   rá   r  r	   r   rÓ   Ú__classcell__r.   r.   rÝ   r/   rÚ   »  sd    ûþýüû
$úþýüûú
ù+ÿÿÿ
ÿ.rÚ   c                       sÐ   e Zd Zedeeeeef f f‡ fdd„ƒZedee f‡ fdd„ƒZ	edee f‡ fdd„ƒZ
					
ddddedededee deeef f‡ fdd„Zdeeeeef f defdd„Zdd„ Z‡  ZS )ÚOnnxSeq2SeqConfigWithPastrR   c                    sr   t t| ƒj}| ¡ D ]"\}}d|v rdnd}| ¡ D ]\}}d|v r'|||< q|||< qq
| jr7| j|dd� |S )NÚencoderÚencoder_sequencer@   r5   r^   rß   )rÜ   rÚ   r^   rº   rÛ   rá   )rO   r]   r$   Ú
axes_namesZsequence_nameZaxis_idxrÝ   r.   r/   r^   O  s   

ûz!OnnxSeq2SeqConfigWithPast.outputsc                    ó\   zt ƒ j}||f}W |S  ty-   t| jdƒr)t| jdƒr)| jj| jjf}Y |S tdƒ‚w )NÚencoder_layersÚdecoder_layersz¥could 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ä   r`   rF   r
  r  )rO   rã   rÝ   r.   r/   rã   `  ó   

÷ûÿüz$OnnxSeq2SeqConfigWithPast.num_layersc                    r	  )NÚencoder_attention_headsÚdecoder_attention_headszÃcould 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ä   r`   rF   r  r  )rO   ræ   rÝ   r.   r/   ræ   p  r  z-OnnxSeq2SeqConfigWithPast.num_attention_headsr˜   FNrž   r   rx   rš   rœ   r�   c              	      sš  t t| ƒj|||||d�}| js|nd}t t| ƒj|||||d�}dd„ | ¡ D ƒ}tdi |¤|¤Ž}	| jrËtƒ s=tdƒ‚dd l}
|	d j	d }|	d j	d }|	d j	d }| j
\}}|||| jj| f}|||d	 | jj| f}g |	d
< | j\}}t||ƒ}t||ƒ| }||krŒdnd}t|ƒD ]}|	d
  |
 |¡|
 |¡|
 |¡|
 |¡f¡ q’|dkr²|n|}t||ƒD ]}|	d
  |
 |¡|
 |¡f¡ q¹|	S )Nrç   r   c                 S   s   i | ]
\}}d |› �|“qS )Údecoder_r.   )r£   r$   Útensorr.   r.   r/   rÏ   ‘  r¨   zCOnnxSeq2SeqConfigWithPast.generate_dummy_inputs.<locals>.<dictcomp>rè   r   ré   Údecoder_input_idsr?   rí   r  Údecoderr.   )rÜ   rÚ   rÀ   rÛ   rº   r»   r   rH   rî   rï   ræ   rF   rð   rã   ÚminÚmaxr   rN   ró   )rO   rž   rx   rš   rœ   r�   Úencoder_inputsÚdecoder_seq_lengthÚdecoder_inputsrô   rî   r4   Úencoder_seq_lengthZnum_encoder_attention_headsZnum_decoder_attention_headsZencoder_shapeZdecoder_shapeÚnum_encoder_layersÚnum_decoder_layersÚmin_num_layersÚmax_num_layersÚremaining_side_namer‡   rï   rÝ   r.   r/   rÀ   €  sX   

ÿ

ÿ

ü
û

üÿ
 z/OnnxSeq2SeqConfigWithPast.generate_dummy_inputsr÷   rà   c              	   C   s0  |dvrt d|› d�ƒ‚|dkrdnd}| j\}}t||ƒ}t||ƒ| }||kr+dnd}d	}	|dkr5d
nd}
t|ƒD ]6}d|
dœ||› d|› d�< d|
dœ||› d|› d�< d|	dœ||› d|› d�< d|	dœ||› d|› d�< q;t||ƒD ]}|dkrƒd|	dœ}nd|
dœ}|||› d|› d|› d�< qwd S )Nrù   rú   rû   rX   rí   rü   r  r  Zpast_encoder_sequenceZpast_decoder_sequencez past_decoder_sequence + sequencer4   rý   rË   ú.decoder.keyú.decoder.valueú.encoder.keyú.encoder.valuerþ   )rH   rã   r  r  r   )rO   r÷   rà   r$   r  r  r  r  r  r  r@   r¤   Z	axes_infor.   r.   r/   rá   Å  s(   


ûz4OnnxSeq2SeqConfigWithPast.fill_with_past_key_values_c                 C   sd   |d ||› d|› d�< |d ||› d|› d�< |d ||› d|› d�< |d ||› d|› d	�< d S )
Nr   rË   r  r   r  r   r   r?   r!  r.   r   r.   r.   r/   r  á  s   z3OnnxSeq2SeqConfigWithPast._flatten_past_key_values_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  N  s4    $úþýüûú
ù"Er  )3rZ   rK   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´   rj   ru   Ú	dataclassr"   r0   rÚ   r  r.   r.   r.   r/   Ú<module>   s8   0
  y 