Ë
    T^(h“=  ã                   óª   — d 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 G d„ de«      Zg d¢Zy)z InstructBLIP model configurationé   )ÚPretrainedConfig)Ú!MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)Úloggingé   )ÚCONFIG_MAPPINGÚ
AutoConfigc                   óB   ‡ — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚInstructBlipVisionConfigaW  
    This is the configuration class to store the configuration of a [`InstructBlipVisionModel`]. It is used to
    instantiate a InstructBLIP vision encoder according to the specified arguments, defining the model architecture.
    Instantiating a configuration defaults will yield a similar configuration to that of the InstructBLIP
    [Salesforce/instruct-blip-flan-t5](https://huggingface.co/Salesforce/instruct-blip-flan-t5) architecture.

    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 1408):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 6144):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 39):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 16):
            Number of attention heads for each attention layer in the Transformer encoder.
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 14):
            The size (resolution) of each patch.
        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"` `"gelu"` are supported. to 1e-5): The epsilon used by the layer
            normalization layers.
        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 1e-10):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        qkv_bias (`bool`, *optional*, defaults to `True`):
            Whether to add a bias to the queries and values in the self-attention layers.

    Example:

    ```python
    >>> from transformers import InstructBlipVisionConfig, InstructBlipVisionModel

    >>> # Initializing a InstructBlipVisionConfig with Salesforce/instruct-blip-flan-t5 style configuration
    >>> configuration = InstructBlipVisionConfig()

    >>> # Initializing a InstructBlipVisionModel (with random weights) from the Salesforce/instruct-blip-flan-t5 style configuration
    >>> model = InstructBlipVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úinstructblip_vision_modelÚvision_configc                 ó¾   •— t        ‰| �  di |¤Ž || _        || _        || _        || _        || _        || _        |
| _        |	| _	        || _
        || _        || _        y )N© )ÚsuperÚ__init__Úhidden_sizeÚintermediate_sizeÚnum_hidden_layersÚnum_attention_headsÚ
patch_sizeÚ
image_sizeÚinitializer_rangeÚattention_dropoutÚlayer_norm_epsÚ
hidden_actÚqkv_bias)Úselfr   r   r   r   r   r   r   r   r   r   r   ÚkwargsÚ	__class__s                €úy/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/instructblip/configuration_instructblip.pyr   z!InstructBlipVisionConfig.__init__P   si   ø€ ô 	‰ÑÑ"˜6Ò"à&ˆÔØ!2ˆÔØ!2ˆÔØ#6ˆÔ Ø$ˆŒØ$ˆŒØ!2ˆÔØ!2ˆÔØ,ˆÔØ$ˆŒØ ˆ�ó    )é€  i   é'   é   éà   é   Úgelug�íµ ÷Æ°>g        g»½×Ùß|Û=T©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeÚbase_config_keyr   Ú__classcell__©r   s   @r   r
   r
      sB   ø„ ñ0ðd -€JØ%€Oð ØØØØØØØØØØ÷!ñ !r    r
   c                   óJ   ‡ — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚInstructBlipQFormerConfiga¹  
    This is the configuration class to store the configuration of a [`InstructBlipQFormerModel`]. It is used to
    instantiate a InstructBLIP Querying Transformer (Q-Former) 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 InstructBLIP [Salesforce/instruct-blip-flan-t5](https://huggingface.co/Salesforce/instruct-blip-flan-t5)
    architecture. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs.
    Read the documentation from [`PretrainedConfig`] for more information.

    Note that [`InstructBlipQFormerModel`] is very similar to [`BertLMHeadModel`] with interleaved cross-attention.

    Args:
        vocab_size (`int`, *optional*, defaults to 30522):
            Vocabulary size of the Q-Former model. Defines the number of different tokens that can be represented by
            the `inputs_ids` passed when calling the model.
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers and the pooler layer.
        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.
        intermediate_size (`int`, *optional*, defaults to 3072):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"silu"` and `"gelu_new"` are supported.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout ratio for the attention probabilities.
        max_position_embeddings (`int`, *optional*, defaults to 512):
            The maximum sequence length that this model might ever be used with. Typically set this to something large
            just in case (e.g., 512 or 1024 or 2048).
        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.
        pad_token_id (`int`, *optional*, defaults to 0):
            Token id used for padding sequences.
        position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
            Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For
            positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to
            [Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155).
            For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models
            with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).
        cross_attention_frequency (`int`, *optional*, defaults to 2):
            The frequency of adding cross-attention to the Transformer layers.
        encoder_hidden_size (`int`, *optional*, defaults to 1408):
            The hidden size of the hidden states for cross-attention.

    Examples:

    ```python
    >>> from transformers import InstructBlipQFormerConfig, InstructBlipQFormerModel

    >>> # Initializing a InstructBLIP Salesforce/instruct-blip-flan-t5 style configuration
    >>> configuration = InstructBlipQFormerConfig()

    >>> # Initializing a model (with random weights) from the Salesforce/instruct-blip-flan-t5 style configuration
    >>> model = InstructBlipQFormerModel(configuration)
    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úinstructblip_qformerÚqformer_configc                 óì   •— t        ‰| �  dd|i|¤Ž || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        y )NÚpad_token_idr   )r   r   Ú
vocab_sizer   r   r   r   r   Úhidden_dropout_probÚattention_probs_dropout_probÚmax_position_embeddingsr   r   Úposition_embedding_typeÚcross_attention_frequencyÚencoder_hidden_size)r   r6   r   r   r   r   r   r7   r8   r9   r   r   r5   r:   r;   r<   r   r   s                    €r   r   z"InstructBlipQFormerConfig.__init__±   sˆ   ø€ ô& 	‰ÑÑ= lÐ=°fÒ=à$ˆŒØ&ˆÔØ!2ˆÔØ#6ˆÔ Ø$ˆŒØ!2ˆÔØ#6ˆÔ Ø,HˆÔ)Ø'>ˆÔ$Ø!2ˆÔØ,ˆÔØ'>ˆÔ$Ø)BˆÔ&Ø#6ˆÕ r    )i:w  i   é   r=   i   r&   çš™™™™™¹?r>   i   ç{®Gáz”?gê-�™—q=é    Úabsoluter   r!   r'   r/   s   @r   r1   r1   n   sN   ø„ ñ=ð~ (€JØ&€Oð ØØØØØØØ%(Ø #ØØØØ *Ø"#Ø ÷!"7ñ "7r    r1   c                   ó\   ‡ — e Zd ZdZdZeeedœZ	 	 	 	 	 d	ˆ fd„	Z	e
dededefd„«       Zˆ xZS )
ÚInstructBlipConfiga@
  
    [`InstructBlipConfig`] is the configuration class to store the configuration of a
    [`InstructBlipForConditionalGeneration`]. It is used to instantiate a InstructBLIP model according to the specified
    arguments, defining the vision model, Q-Former model and language model configs. Instantiating a configuration with
    the defaults will yield a similar configuration to that of the InstructBLIP
    [Salesforce/instruct-blip-flan-t5](https://huggingface.co/Salesforce/instruct-blip-flan-t5) architecture.

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

    Args:
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`InstructBlipVisionConfig`].
        qformer_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`InstructBlipQFormerConfig`].
        text_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize any [`PretrainedConfig`].
        num_query_tokens (`int`, *optional*, defaults to 32):
            The number of query tokens passed through the Transformer.

        image_token_index (`int`, *optional*):
            Token index of special image token.
        kwargs (*optional*):
            Dictionary of keyword arguments.

    Example:

    ```python
    >>> from transformers import (
    ...     InstructBlipVisionConfig,
    ...     InstructBlipQFormerConfig,
    ...     OPTConfig,
    ...     InstructBlipConfig,
    ...     InstructBlipForConditionalGeneration,
    ... )

    >>> # Initializing a InstructBlipConfig with Salesforce/instruct-blip-flan-t5 style configuration
    >>> configuration = InstructBlipConfig()

    >>> # Initializing a InstructBlipForConditionalGeneration (with random weights) from the Salesforce/instruct-blip-flan-t5 style configuration
    >>> model = InstructBlipForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config

    >>> # We can also initialize a InstructBlipConfig from a InstructBlipVisionConfig, InstructBlipQFormerConfig and any PretrainedConfig

    >>> # Initializing InstructBLIP vision, InstructBLIP Q-Former and language model configurations
    >>> vision_config = InstructBlipVisionConfig()
    >>> qformer_config = InstructBlipQFormerConfig()
    >>> text_config = OPTConfig()

    >>> config = InstructBlipConfig.from_text_vision_configs(vision_config, qformer_config, text_config)
    ```Úinstructblip)Útext_configr3   r   c                 óú  •— t        ‰| �  di |¤Ž |€i }t        j                  d«       |€i }t        j                  d«       |€i }t        j                  d«       t	        di |¤Ž| _        t        di |¤Ž| _        d|v r|d   nd}t        |   di |¤Ž| _	        || _
        || _        | j
                  j                  | j                  _        | j                  j                  t        v | _        d| _        d| _        y )	NzUvision_config is None. initializing the InstructBlipVisionConfig with default values.zWqformer_config is None. Initializing the InstructBlipQFormerConfig with default values.zTtext_config is None. Initializing the text config with default values (`OPTConfig`).r,   Úoptg      ð?r?   r   )r   r   ÚloggerÚinfor
   r   r1   r3   r   rE   Únum_query_tokensÚimage_token_indexr   r<   r,   r   Úuse_decoder_only_language_modelÚinitializer_factorr   )	r   r   r3   rE   rJ   rK   r   Útext_model_typer   s	           €r   r   zInstructBlipConfig.__init__  sú   ø€ ô 	‰ÑÑ"˜6Ò"àÐ ØˆMÜ�K‰KÐoÔpàÐ!ØˆNÜ�K‰KÐqÔràÐØˆKÜ�K‰KÐnÔoä5ÑF¸ÑFˆÔÜ7ÑI¸.ÑIˆÔØ7CÀ{Ñ7R˜+ lÒ3ÐX]ˆÜ)¨/Ñ:ÑI¸[ÑIˆÔà 0ˆÔØ!2ˆÔØ26×2DÑ2D×2PÑ2Pˆ×ÑÔ/Ø/3×/?Ñ/?×/JÑ/JÔNoÐ/oˆÔ,Ø"%ˆÔØ!%ˆÕr    r   r3   rE   c                 ón   —  | d|j                  «       |j                  «       |j                  «       dœ|¤ŽS )zý
        Instantiate a [`InstructBlipConfig`] (or a derived class) from a InstructBLIP vision model, Q-Former and
        language model configurations.

        Returns:
            [`InstructBlipConfig`]: An instance of a configuration object
        )r   r3   rE   r   )Úto_dict)Úclsr   r3   rE   r   s        r   Ú from_vision_qformer_text_configsz3InstructBlipConfig.from_vision_qformer_text_configs8  sD   € ñ  ð 
Ø'×/Ñ/Ó1Ø)×1Ñ1Ó3Ø#×+Ñ+Ó-ñ
ð ñ	
ð 	
r    )NNNé    N)r(   r)   r*   r+   r,   r   r1   r
   Úsub_configsr   Úclassmethodr   rR   r.   r/   s   @r   rC   rC   Ö   sg   ø„ ñ5ðn  €Jà!Ø3Ø1ñ€Kð ØØØØõ!&ðF ð
à/ð
ð 2ð
ð &ò	
ó ô
r    rC   )rC   r1   r
   N)r+   Úconfiguration_utilsr   Úmodels.auto.modeling_autor   Úutilsr   Úautor   r   Ú
get_loggerr(   rH   r
   r1   rC   Ú__all__r   r    r   ú<module>r\      sb   ðñ 'å 3Ý JÝ ß -ð 
ˆ×	Ñ	˜HÓ	%€ôQ!Ð/ô Q!ôhe7Ð 0ô e7ôPw
Ð)ô w
òt Z�r    