Ë
    T^(h±/  ã                   óÐ   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ  ej*                  e«      Z G d„ de	«      Z G d„ de«      ZddgZy)zPerceiver model configurationé    )ÚOrderedDict)ÚAnyÚMappingÚOptionalÚUnioné   )ÚPretrainedConfig)ÚFeatureExtractionMixin)Ú
OnnxConfig)Ú compute_effective_axis_dimension)ÚPreTrainedTokenizerBase)Ú
TensorTypeÚloggingc                   óf   ‡ — e Zd ZdZdZdddddddd	d	d
ddddddddddddgdddg d¢ddfˆ fd„	Zˆ xZS )ÚPerceiverConfiga¨  
    This is the configuration class to store the configuration of a [`PerceiverModel`]. It is used to instantiate an
    Perceiver model according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the Perceiver
    [deepmind/language-perceiver](https://huggingface.co/deepmind/language-perceiver) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        num_latents (`int`, *optional*, defaults to 256):
            The number of latents.
        d_latents (`int`, *optional*, defaults to 1280):
            Dimension of the latent embeddings.
        d_model (`int`, *optional*, defaults to 768):
            Dimension of the inputs. Should only be provided in case [*PerceiverTextPreprocessor*] is used or no
            preprocessor is provided.
        num_blocks (`int`, *optional*, defaults to 1):
            Number of blocks in the Transformer encoder.
        num_self_attends_per_block (`int`, *optional*, defaults to 26):
            The number of self-attention layers per block.
        num_self_attention_heads (`int`, *optional*, defaults to 8):
            Number of attention heads for each self-attention layer in the Transformer encoder.
        num_cross_attention_heads (`int`, *optional*, defaults to 8):
            Number of attention heads for each cross-attention layer in the Transformer encoder.
        qk_channels (`int`, *optional*):
            Dimension to project the queries + keys before applying attention in the cross-attention and self-attention
            layers of the encoder. Will default to preserving the dimension of the queries if not specified.
        v_channels (`int`, *optional*):
            Dimension to project the values before applying attention in the cross-attention and self-attention layers
            of the encoder. Will default to preserving the dimension of the queries if not specified.
        cross_attention_shape_for_attention (`str`, *optional*, defaults to `"kv"`):
            Dimension to use when downsampling the queries and keys in the cross-attention layer of the encoder.
        self_attention_widening_factor (`int`, *optional*, defaults to 1):
            Dimension of the feed-forward layer in the cross-attention layer of the Transformer encoder.
        cross_attention_widening_factor (`int`, *optional*, defaults to 1):
            Dimension of the feed-forward layer in the self-attention layers of the Transformer encoder.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"` and `"gelu_new"` are supported.
        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout ratio for the attention probabilities.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        layer_norm_eps (`float`, *optional*, defaults to 1e-12):
            The epsilon used by the layer normalization layers.
        use_query_residual (`float`, *optional*, defaults to `True`):
            Whether to add a query residual in the cross-attention layer of the encoder.
        vocab_size (`int`, *optional*, defaults to 262):
            Vocabulary size for the masked language modeling model.
        max_position_embeddings (`int`, *optional*, defaults to 2048):
            The maximum sequence length that the masked language modeling model might ever be used with. Typically set
            this to something large just in case (e.g., 512 or 1024 or 2048).
        image_size (`int`, *optional*, defaults to 56):
            Size of the images after preprocessing, for [`PerceiverForImageClassificationLearned`].
        train_size (`List[int]`, *optional*, defaults to `[368, 496]`):
            Training size of the images for the optical flow model.
        num_frames (`int`, *optional*, defaults to 16):
            Number of video frames used for the multimodal autoencoding model.
        audio_samples_per_frame (`int`, *optional*, defaults to 1920):
            Number of audio samples per frame for the multimodal autoencoding model.
        samples_per_patch (`int`, *optional*, defaults to 16):
            Number of audio samples per patch when preprocessing the audio for the multimodal autoencoding model.
        output_shape (`List[int]`, *optional*, defaults to `[1, 16, 224, 224]`):
            Shape of the output (batch_size, num_frames, height, width) for the video decoder queries of the multimodal
            autoencoding model. This excludes the channel dimension.
        output_num_channels (`int`, *optional*, defaults to 512):
            Number of output channels for each modalitiy decoder.

    Example:

    ```python
    >>> from transformers import PerceiverModel, PerceiverConfig

    >>> # Initializing a Perceiver deepmind/language-perceiver style configuration
    >>> configuration = PerceiverConfig()

    >>> # Initializing a model from the deepmind/language-perceiver style configuration
    >>> model = PerceiverModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Ú	perceiveré   i   i   é   é   é   NÚkvÚgelugš™™™™™¹?g{®Gáz”?gê-�™—q=Ti  i   é8   ip  ið  é   i€  )r   r   éà   r   i   i   c                 óž  •— t        ‰| �  di |¤Ž || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        y )N© )ÚsuperÚ__init__Únum_latentsÚ	d_latentsÚd_modelÚ
num_blocksÚnum_self_attends_per_blockÚnum_self_attention_headsÚnum_cross_attention_headsÚqk_channelsÚ
v_channelsÚ#cross_attention_shape_for_attentionÚself_attention_widening_factorÚcross_attention_widening_factorÚ
hidden_actÚattention_probs_dropout_probÚinitializer_rangeÚlayer_norm_epsÚuse_query_residualÚ
vocab_sizeÚmax_position_embeddingsÚ
image_sizeÚ
train_sizeÚ
num_framesÚaudio_samples_per_frameÚsamples_per_patchÚoutput_shapeÚoutput_num_channelsÚ_label_trainable_num_channels)Úselfr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   ÚkwargsÚ	__class__s                                €ús/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/perceiver/configuration_perceiver.pyr   zPerceiverConfig.__init__v   sä   ø€ ô> 	‰ÑÑ"˜6Ò"à&ˆÔØ"ˆŒØˆŒØ$ˆŒØ*DˆÔ'Ø(@ˆÔ%Ø)BˆÔ&Ø&ˆÔØ$ˆŒØ3VˆÔ0Ø.LˆÔ+Ø/NˆÔ,Ø$ˆŒØ,HˆÔ)Ø!2ˆÔØ,ˆÔØ"4ˆÔà$ˆŒØ'>ˆÔ$à$ˆŒà$ˆŒà$ˆŒØ'>ˆÔ$Ø!2ˆÔØ(ˆÔØ#6ˆÔ Ø-JˆÕ*ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typer   Ú__classcell__)r=   s   @r>   r   r      st   ø„ ñRðh €Jð ØØØØ#%Ø!"Ø"#ØØØ,0Ø'(Ø()ØØ%(ØØØØØ $ØØ˜�:ØØ $ØÚ&ØØ&*÷9?Kñ ?Kr?   r   c                   ó¤   — e Zd Zedeeeeef   f   fd„«       Zedefd„«       Z		 	 	 	 	 	 	 	 dde
d   deded	ed
edee   dedededeeef   fd„Zy)ÚPerceiverOnnxConfigÚreturnc                 óZ   — | j                   dk(  rddddœ}ndddœ}t        d|fd|fg«      S )	Nzmultiple-choiceÚbatchÚchoiceÚsequence)r   r   é   )r   r   ÚinputsÚattention_mask)Útaskr   )r;   Údynamic_axiss     r>   rN   zPerceiverOnnxConfig.inputs¹   sG   € à�9‰9Ð)Ò)Ø&¨8¸
ÑC‰Là&¨:Ñ6ˆLÜà˜<Ð(Ø! <Ð0ðó
ð 	
r?   c                  ó   — y)Ng-Cëâ6?r   )r;   s    r>   Úatol_for_validationz'PerceiverOnnxConfig.atol_for_validationÆ   s   € àr?   NÚpreprocessor)r   r
   Ú
batch_sizeÚ
seq_lengthÚnum_choicesÚis_pairÚ	frameworkÚnum_channelsÚimage_widthÚimage_heightc
                 óB  — t        |t        «      r‹t        |t        j                  d¬«      }|j                  |«      }
t        |t        j                  |
¬«      }dj                  dg«      |z  g|z  }t         |||¬«      «      }|j                  d«      |d<   |S t        |t        «      rj|j                  d   dk(  rXt        |t        j                  ¬	«      }| j                  |||	|«      }t         |||¬
«      «      }|j                  d«      |d<   |S t        d«      ‚)Nr   )Úfixed_dimensionÚnum_token_to_addú Úa)Úreturn_tensorsÚ	input_idsrN   Úpixel_values)r^   )Úimagesrb   z\Unable to generate dummy inputs for the model. Please provide a tokenizer or a preprocessor.)Ú
isinstancer   r   r   Údefault_fixed_batchÚnum_special_tokens_to_addÚdefault_fixed_sequenceÚjoinÚdictÚpopr
   Úmodel_input_namesÚ_generate_dummy_imagesÚ
ValueError)r;   rT   rU   rV   rW   rX   rY   rZ   r[   r\   Útoken_to_addÚdummy_inputrN   s                r>   Úgenerate_dummy_inputsz)PerceiverOnnxConfig.generate_dummy_inputsÊ   s  € ô �lÔ$;Ô<ä9Ø¬J×,JÑ,JÐ]^ôˆJð (×AÑAÀ'ÓJˆLÜ9Ø¬J×,MÑ,MÐ`lôˆJð Ÿ8™8 S E›?¨ZÑ7Ð8¸:ÑEˆKÜ™, {À9ÔMÓNˆFØ%Ÿz™z¨+Ó6ˆF�8ÑØˆMÜ˜Ô&<Ô=À,×B`ÑB`ÐabÑBcÐguÒBuä9¸*ÔV`×VtÑVtÔuˆJØ×5Ñ5°jÀ,ÐP\Ð^iÓjˆKÜ™,¨kÈ)ÔTÓUˆFØ%Ÿz™z¨.Ó9ˆF�8ÑØˆMäØnóð r?   )éÿÿÿÿrs   rs   FNr   é(   rt   )r@   rA   rB   Úpropertyr   ÚstrÚintrN   ÚfloatrS   r   Úboolr   r   r   rr   r   r?   r>   rG   rG   ¸   sÞ   „ Øð

˜  W¨S°#¨XÑ%6Ð 6Ñ7ò 

ó ð

ð ð Uò ó ðð ØØØØ*.ØØØñ'àÐOÑPð'ð ð'ð ð	'ð
 ð'ð ð'ð ˜JÑ'ð'ð ð'ð ð'ð ð'ð 
��c�Ñ	ô'r?   rG   N)rC   Úcollectionsr   Útypingr   r   r   r   Úconfiguration_utilsr	   Úfeature_extraction_utilsr
   Úonnxr   Ú
onnx.utilsr   Útokenization_utils_baser   Úutilsr   r   Ú
get_loggerr@   Úloggerr   rG   Ú__all__r   r?   r>   ú<module>r…      se   ðñ $å #ß 0Ó 0å 3Ý >Ý Ý :Ý >ß (ð 
ˆ×	Ñ	˜HÓ	%€ôVKÐ&ô VKôr9˜*ô 9ðx Ð3Ð
4�r?   