Ë
    T^(hò.  ã                   óœ   — d 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 G d
„ de«      ZdgZy)zIdefics2 model configurationé   )ÚPretrainedConfig)Úloggingé   )ÚCONFIG_MAPPINGÚ
AutoConfigc                   óB   ‡ — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚIdefics2VisionConfiga   
    This is the configuration class to store the configuration of a [`Idefics2VisionModel`]. It is used to instantiate a
    Idefics2 vision encoder according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the SigLIP checkpoint
    [google/siglip-base-patch16-224](https://huggingface.co/google/siglip-base-patch16-224) used in the Idefics2 model
    [HuggingFaceM4/idefics2-8b](https://huggingface.co/HuggingFaceM4/idefics2-8b).

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

    Args:
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 3072):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 12):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_channels (`int`, *optional*, defaults to 3):
            Number of channels in the input images.
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 32):
            The size (resolution) of each patch.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu_pytorch_tanh"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"` and `"gelu_new"` `"quick_gelu"` are supported.
        layer_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the layer normalization layers.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation for initializing all weight matrices in the model.

    Example:

    ```python
    >>> from transformers.models.idefics2.modeling_idefics2 import Idefics2VisionTransformer
    >>> from transformers.models.idefics2.configuration_idefics2 import Idefics2VisionConfig

    >>> # Initializing a Idefics2VisionConfig with google/siglip-base-patch16-224 style configuration
    >>> configuration = Idefics2VisionConfig()

    >>> # Initializing a Idefics2VisionTransformer (with random weights) from the google/siglip-base-patch16-224 style configuration
    >>> model = Idefics2VisionTransformer(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úidefics2_visionÚvision_configc                 ó¾   •— t        ‰| �  di |¤Ž || _        || _        || _        || _        || _        || _        || _        |
| _	        |	| _
        || _        || _        y )N© )ÚsuperÚ__init__Úhidden_sizeÚintermediate_sizeÚnum_hidden_layersÚnum_attention_headsÚnum_channelsÚ
patch_sizeÚ
image_sizeÚattention_dropoutÚlayer_norm_epsÚ
hidden_actÚinitializer_range)Úselfr   r   r   r   r   r   r   r   r   r   r   ÚkwargsÚ	__class__s                €úq/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/idefics2/configuration_idefics2.pyr   zIdefics2VisionConfig.__init__O   sj   ø€ ô 	‰ÑÑ"˜6Ò"à&ˆÔØ!2ˆÔØ!2ˆÔØ#6ˆÔ Ø(ˆÔØ$ˆŒØ$ˆŒØ!2ˆÔØ,ˆÔØ$ˆŒØ!2ˆÕó    )i   i   é   r    r   éà   é    Úgelu_pytorch_tanhç�íµ ÷Æ°>ç        g{®Gáz”?)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeÚbase_config_keyr   Ú__classcell__©r   s   @r   r	   r	      sB   ø„ ñ1ðf #€JØ%€Oð ØØØØØØØ&ØØØ÷3ñ 3r   r	   c                   ó:   ‡ — e Zd ZdZdZ	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚIdefics2PerceiverConfigaÖ  
    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the perceiver block.
        hidden_size (`int`, *optional*, defaults to 4096):
            Dimension of the hidden representations.
        rms_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the rms normalization layers.
        resampler_n_latents (`int`, *optional*, defaults to 64):
            Number of latent embeddings to resample ("compress") the input sequence to (usually < 128).
        resampler_depth (`int`, *optional*, defaults to 3):
            Depth of the Perceiver Resampler (Transformer w/ cross attention). Should be shallow (<= 3).
        resampler_n_heads (`int`, *optional*, defaults to 16):
            Number of heads in each Transformer block (for multi-headed self-attention).
        resampler_head_dim (`int`, *optional*, defaults to 96):
            Dimensionality of each head projection in the Transformer block.
        num_key_value_heads (`int`, *optional*, defaults to 4):
            Number of key-value heads in the perceiver attention block.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
    Úidefics2_perceiverc
                 ó  •— || _         || _        || _        || _        || _        || _        || _        || _        |	| _        | j                  | j
                  kD  r%t        d| j                  › d| j
                  › �«      ‚t        ‰| �,  di |
¤Ž y )Nznum_key_value_heads=z1 must be less than or equal to resampler_n_heads=r   )r   r   Úrms_norm_epsÚresampler_n_latentsÚresampler_depthÚresampler_n_headsÚnum_key_value_headsÚresampler_head_dimr   Ú
ValueErrorr   r   )r   r   r   r2   r3   r4   r5   r7   r6   r   r   r   s              €r   r   z Idefics2PerceiverConfig.__init__‰   s¤   ø€ ð %ˆŒØ&ˆÔØ(ˆÔØ#6ˆÔ Ø.ˆÔØ!2ˆÔØ#6ˆÔ Ø"4ˆÔØ!2ˆÔØ×#Ñ# d×&<Ñ&<Ò<ÜØ& t×'?Ñ'?Ð&@ð A&Ø&*×&<Ñ&<Ð%=ð?óð ô 	‰ÑÑ"˜6Ó"r   )	Úsilui   r$   é@   r   é   é`   é   r%   )r&   r'   r(   r)   r*   r   r,   r-   s   @r   r/   r/   m   s6   ø„ ñð2 &€Jð ØØØØØØØØ÷#ñ #r   r/   c                   ó@   ‡ — e Zd ZdZdZeeedœZ	 	 	 	 	 	 dˆ fd„	Z	ˆ xZ
S )ÚIdefics2ConfigaÉ  
    This is the configuration class to store the configuration of a [`Idefics2Model`]. It is used to instantiate a
    Idefics2 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 model of the Idefics2
    [HuggingFaceM4/idefics2-8b](https://huggingface.co/HuggingFaceM4/idefics2-8b) architecture.

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

    Args:
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should cache the key/value pairs of the attention mechanism.
        image_token_id (`int`, *optional*, defaults to 32001):
            The id of the "image" token.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether or not to tie the word embeddings with the token embeddings.
        vision_config (`IdeficsVisionConfig` or `dict`, *optional*):
            Custom vision config or dict
        perceiver_config (`IdeficsPerceiverConfig` or `dict`, *optional*):
            Custom perceiver config or dict
        text_config (`MistralConfig` or `dict`, *optional*):
            Custom text config or dict for the text model

    Example:
    ```python
    >>> from transformers import Idefics2Model, Idefics2Config
    >>> # Initializing configuration
    >>> configuration = Idefics2Config()
    >>> # Initializing a model from the configuration
    >>> model = Idefics2Model(configuration)
    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úidefics2)Útext_configÚperceiver_configr   c                 óª  •— || _         || _        || _        |€%t        «       | _        t
        j                  d«       n8t        |t        «      rt        di |¤Ž| _        nt        |t        «      r|| _        |€%t        «       | _
        t
        j                  d«       n8t        |t        «      rt        di |¤Ž| _
        nt        |t        «      r|| _
        t        |t        «      r d|v r|d   nd|d<   t        |d      di |¤Ž}n)|€'t
        j                  d«       t        d   dddd	¬
«      }|| _        | j                  j                  | j                  j                  k7  r_| j                  j                  | j                  _        | j                  j                  | j                  _        t
        j                  d«       t!        ‰| �D  di |¤d|i¤Ž y )Nz7perciver_config is None, using default perceiver configz2vision_config is None, using default vision configr*   Úmistralz.text_config is None, using default text configi €  gñhãˆµøä>é    F)Úmax_position_embeddingsr2   Úpad_token_idÚtie_word_embeddingsz×Perceiver config has a different `hidden_size` than text config, which means default values were used. In your model's config on the hub, add `hidden_size` and `rms_norm_eps` keys under the `perceiver_config` dict. rH   r   )Úimage_token_idÚ	use_cacherH   r/   rB   ÚloggerÚinfoÚ
isinstanceÚdictr	   r   r   rA   r   r2   Úwarning_oncer   r   )	r   rJ   rI   rH   r   rB   rA   r   r   s	           €r   r   zIdefics2Config.__init__Ñ   s¨  ø€ ð -ˆÔØ"ˆŒØ#6ˆÔ àÐ#Ü$;Ó$=ˆDÔ!Ü�K‰KÐQÕRÜÐ(¬$Ô/Ü$;Ñ$OÐ>NÑ$OˆDÕ!ÜÐ(Ô*AÔBØ$4ˆDÔ!àÐ Ü!5Ó!7ˆDÔÜ�K‰KÐLÕMÜ˜¤tÔ,Ü!5Ñ!F¸Ñ!FˆDÕÜ˜Ô';Ô<Ø!.ˆDÔä�k¤4Ô(ØEQÐU`ÑE`¨°LÒ(AÐfoˆK˜Ñ%Ü(¨°\Ñ)BÑCÑRÀkÑR‰KØÐ Ü�K‰KÐHÔIÜ(¨Ñ3Ø(0Ø!àØ$)ôˆKð 'ˆÔØ×Ñ×'Ñ'¨4×+@Ñ+@×+LÑ+LÒLØ04×0@Ñ0@×0LÑ0LˆD×!Ñ!Ô-Ø15×1AÑ1A×1NÑ1NˆD×!Ñ!Ô.Ü×ÑðCôô
 	‰ÑÑK˜6ÑKÐ7JÔKr   )Ti}  FNNN)r&   r'   r(   r)   r*   r   r/   r	   Úsub_configsr   r,   r-   s   @r   r?   r?   §   s@   ø„ ñ ðD €Jà!Ø3Ø-ñ€Kð ØØ!ØØØ÷4Lñ 4Lr   r?   N)r)   Úconfiguration_utilsr   Úutilsr   Úautor   r   Ú
get_loggerr&   rK   r	   r/   r?   Ú__all__r   r   r   ú<module>rV      sa   ðñ #å 3Ý ß -ð 
ˆ×	Ñ	˜HÓ	%€ôR3Ð+ô R3ôj7#Ð.ô 7#ôt^LÐ%ô ^LðB Ð
�r   