
    gZ@                         d Z ddlZddlmZ ddlmZ ddlmZ  ej        e	          Z
 G d de          Z G d	 d
e          Z G d de          ZdS )zBlip model configuration    N)Union   )PretrainedConfig)loggingc                        e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Zedeee	j
        f         ddfd            Z xZS )BlipTextConfiga  
    This is the configuration class to store the configuration of a [`BlipTextModel`]. It is used to instantiate a BLIP
    text 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 `BlipText` used by the [base
    architectures](https://huggingface.co/Salesforce/blip-vqa-base).

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


    Args:
        vocab_size (`int`, *optional*, defaults to 30524):
            Vocabulary size of the `Blip` text model. Defines the number of different tokens that can be represented by
            the `inputs_ids` passed when calling [`BlipModel`].
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers and the pooler layer.
        encoder_hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers from the vision model.
        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 8):
            Number of attention heads for each attention layer in the Transformer encoder.
        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).
        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.
        layer_norm_eps (`float`, *optional*, defaults to 1e-12):
            The epsilon used by the layer normalization layers.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        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 of the truncated_normal_initializer for initializing all weight matrices.
        bos_token_id (`int`, *optional*, defaults to 30522):
            The id of the `beginning-of-sequence` token.
        eos_token_id (`int`, *optional*, defaults to 2):
            The id of the `end-of-sequence` token.
        pad_token_id (`int`, *optional*, defaults to 0):
            The id of the `padding` token.
        sep_token_id (`int`, *optional*, defaults to 102):
            The id of the `separator` token.
        is_decoder (`bool`, *optional*, defaults to `True`):
            Whether the model is used as a decoder.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models).
        label_smoothing (float, *optional*):
            A float in [0.0, 1.0]. Specifies the amount of smoothing when computing the loss, where 0.0 means no smoothing. The targets
            become a mixture of the original ground truth and a uniform distribution as described in
            `Rethinking the Inception Architecture for Computer Vision <https://arxiv.org/abs/1512.00567>`__. Default: :math:`0.0`.

    Example:

    ```python
    >>> from transformers import BlipTextConfig, BlipTextModel

    >>> # Initializing a BlipTextConfig with Salesforce/blip-vqa-base style configuration
    >>> configuration = BlipTextConfig()

    >>> # Initializing a BlipTextModel (with random weights) from the Salesforce/blip-vqa-base style configuration
    >>> model = BlipTextModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```blip_text_model<w                 gelu-q=        {Gz?:w     r   f   Tc                 $    t                      j        d||||d| || _        || _        || _        || _        || _        || _        || _        || _	        || _
        |
| _        |	| _        || _        || _        || _        || _        || _        d S )N)pad_token_idbos_token_ideos_token_idsep_token_id )super__init__
vocab_sizehidden_sizeencoder_hidden_sizeintermediate_sizeprojection_dimhidden_dropout_probnum_hidden_layersnum_attention_headsmax_position_embeddingslayer_norm_eps
hidden_actinitializer_rangeattention_probs_dropout_prob
is_decoder	use_cachelabel_smoothing)selfr   r    r!   r"   r#   r%   r&   r'   r)   r(   r$   r+   r*   r   r   r   r   r,   r-   r.   kwargs	__class__s                         g/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/blip/configuration_blip.pyr   zBlipTextConfig.__init__d   s    0 	 	
%%%%		
 	

 	
 	
 	
 %&#6 !2,#6 !2#6 '>$,$!2,H)$".    pretrained_model_name_or_pathreturnr   c                 N   |                      |            | j        |fi |\  }}|                    d          dk    r|d         }d|v rMt          | d          r=|d         | j        k    r,t
                              d|d          d| j         d            | j        |fi |S )N
model_typebliptext_configYou are using a model of type   to instantiate a model of type N. This is not supported for all configurations of models and can yield errors._set_token_in_kwargsget_config_dictgethasattrr7   loggerwarning	from_dictclsr4   r0   config_dicts       r2   from_pretrainedzBlipTextConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((F22%m4K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r3   )r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   TTr   __name__
__module____qualname____doc__r7   r   classmethodr   strosPathLikerH   __classcell__r1   s   @r2   r   r      s        D DL #J  #%(+// // // // // //b 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r3   r   c                   x     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 d fd	Zedeee	j
        f         ddfd            Z xZS )BlipVisionConfiga
  
    This is the configuration class to store the configuration of a [`BlipVisionModel`]. It is used to instantiate a
    BLIP vision model according to the specified arguments, defining the model architecture. Instantiating a
    configuration defaults will yield a similar configuration to that of the Blip-base
    [Salesforce/blip-vqa-base](https://huggingface.co/Salesforce/blip-vqa-base) 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 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.
        image_size (`int`, *optional*, defaults to 384):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 16):
            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.
        layer_norm_eps (`float`, *optional*, defaults to 1e-5):
            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.

    Example:

    ```python
    >>> from transformers import BlipVisionConfig, BlipVisionModel

    >>> # Initializing a BlipVisionConfig with Salesforce/blip-vqa-base style configuration
    >>> configuration = BlipVisionConfig()

    >>> # Initializing a BlipVisionModel (with random weights) from the Salesforce/blip-vqa-base style configuration
    >>> model = BlipVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```blip_vision_modelr   r   r   r        r   h㈵>r   绽|=c                      t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        |
| _
        |	| _        || _        d S )Nr   )r   r   r    r"   r#   r%   r&   
patch_size
image_sizer*   attention_dropoutr(   r)   )r/   r    r"   r#   r%   r&   r]   r\   r)   r(   r^   r*   r0   r1   s                r2   r   zBlipVisionConfig.__init__   s{     	""6"""&!2,!2#6 $$!2!2,$r3   r4   r5   r   c                 N   |                      |            | j        |fi |\  }}|                    d          dk    r|d         }d|v rMt          | d          r=|d         | j        k    r,t
                              d|d          d| j         d            | j        |fi |S )Nr7   r8   vision_configr:   r;   r<   r=   rE   s       r2   rH   z BlipVisionConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((F22%o6K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r3   )r   r   r   r   r   rW   rX   r   rY   r   rZ   rI   rS   s   @r2   rU   rU      s        . .` %J % % % % % %: 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r3   rU   c                   T     e Zd ZdZdZ	 	 	 	 	 	 d fd	Zed	ed
efd            Z	 xZ
S )
BlipConfigaO
  
    [`BlipConfig`] is the configuration class to store the configuration of a [`BlipModel`]. It is used to instantiate
    a BLIP model according to the specified arguments, defining the text model and vision model configs. Instantiating
    a configuration with the defaults will yield a similar configuration to that of the BLIP-base
    [Salesforce/blip-vqa-base](https://huggingface.co/Salesforce/blip-vqa-base) architecture.

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

    Args:
        text_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`BlipTextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`BlipVisionConfig`].
        projection_dim (`int`, *optional*, defaults to 512):
            Dimensionality of text and vision projection layers.
        logit_scale_init_value (`float`, *optional*, defaults to 2.6592):
            The initial value of the *logit_scale* parameter. Default is used as per the original BLIP implementation.
        image_text_hidden_size (`int`, *optional*, defaults to 256):
            Dimensionality of the hidden state of the image-text fusion layer.
        label_smoothing (float, optional, *optional*, defaults to 0.0):
            A float in [0.0, 1.0]. Specifies the amount of smoothing when computing the loss, where 0.0 means no smoothing. The targets
            become a mixture of the original ground truth and a uniform distribution as described in
            `Rethinking the Inception Architecture for Computer Vision <https://arxiv.org/abs/1512.00567>`__. Default: :math:`0.0`.
        kwargs (*optional*):
            Dictionary of keyword arguments.

    Example:

    ```python
    >>> from transformers import BlipConfig, BlipModel

    >>> # Initializing a BlipConfig with Salesforce/blip-vqa-base style configuration
    >>> configuration = BlipConfig()

    >>> # Initializing a BlipPModel (with random weights) from the Salesforce/blip-vqa-base style configuration
    >>> model = BlipModel(configuration)

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

    >>> # We can also initialize a BlipConfig from a BlipTextConfig and a BlipVisionConfig

    >>> # Initializing a BLIPText and BLIPVision configuration
    >>> config_text = BlipTextConfig()
    >>> config_vision = BlipVisionConfig()

    >>> config = BlipConfig.from_text_vision_configs(config_text, config_vision)
    ```r8   Nr   /L
F@   r   c                 v    t                      j        di | |i }t                              d           |i }t                              d           t	          di || _        t          di || _        | j        j        | j        _	        || _
        || _        d| _        d| _        || _        || _        d S )NzO`text_config` is `None`. Initializing the `BlipTextConfig` with default values.zS`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.g      ?r   r   )r   r   rB   infor   r9   rU   r`   r    r!   r#   logit_scale_init_valueinitializer_factorr*   image_text_hidden_sizer.   )	r/   r9   r`   r#   rg   ri   r.   r0   r1   s	           r2   r   zBlipConfig.__init__@  s     	""6"""KKKijjj MKKmnnn)88K88->>>>/3/A/M,,&<#"%!%&<#.r3   r9   r`   c                 `     | d|                                 |                                 d|S )z
        Instantiate a [`BlipConfig`] (or a derived class) from blip text model configuration and blip vision model
        configuration.

        Returns:
            [`BlipConfig`]: An instance of a configuration object
        )r9   r`   r   )to_dict)rF   r9   r`   r0   s       r2   from_text_vision_configsz#BlipConfig.from_text_vision_configs`  s:     sf{2244MDYDYD[D[ff_efffr3   )NNr   rc   rd   r   )rJ   rK   rL   rM   r7   r   rN   r   rU   rl   rR   rS   s   @r2   rb   rb     s        0 0d J %"/ / / / / /@ 	g> 	gRb 	g 	g 	g [	g 	g 	g 	g 	gr3   rb   )rM   rP   typingr   configuration_utilsr   utilsr   
get_loggerrJ   rB   r   rU   rb   r   r3   r2   <module>rq      s     				       3 3 3 3 3 3       
	H	%	%J4 J4 J4 J4 J4% J4 J4 J4Z`4 `4 `4 `4 `4' `4 `4 `4F_g _g _g _g _g! _g _g _g _g _gr3   