o
    òÜÓh«@  ã                	   @   s„   d Z ddlZddlmZ ddlmZ ddlmZ e e	¡Z
ddd	d
dddddœZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )z Blip model configurationé    N)ÚUnioné   )ÚPretrainedConfig)ÚloggingzHhttps://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.jsonzOhttps://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.jsonzUhttps://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.jsonzVhttps://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.jsonzMhttps://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.jsonzNhttps://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.jsonzNhttps://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.jsonzOhttps://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json)zSalesforce/blip-vqa-basez Salesforce/blip-vqa-capfit-largez%Salesforce/blip-image-captioning-basez&Salesforce/blip-image-captioning-largezSalesforce/blip-itm-base-cocozSalesforce/blip-itm-large-cocozSalesforce/blip-itm-base-flikrzSalesforce/blip-itm-large-flikrc                       sl   e Zd ZdZdZ											
									d‡ fdd„	Zedeee	j
f ddfdd„ƒZ‡  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).

    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=ç        ç{®Gáz”?é:w  é   r   éf   Tc                    sz   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)Úselfr   r   r   r   r    r"   r#   r$   r&   r%   r!   r(   r'   r   r   r   r   r)   r*   Úkwargs©Ú	__class__r   úa/var/www/html/ai/venv/lib/python3.10/site-packages/transformers/models/blip/configuration_blip.pyr   s   s.   üû
zBlipTextConfig.__init__Úpretrained_model_name_or_pathÚreturnr   c                 K   ó†   |   |¡ | j|fi |¤Ž\}}| d¡dkr|d }d|v r:t| 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Úhasattrr3   ÚloggerÚwarningÚ	from_dict©Úclsr0   r,   Úconfig_dictr   r   r/   Úfrom_pretrained¢   ó   
 ÿÿzBlipTextConfig.from_pretrained)r   r	   r	   r
   r	   r   r   r   r   r   r   r   r   r   r   r   r   TT©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r   Úclassmethodr   ÚstrÚosÚPathLikerD   Ú__classcell__r   r   r-   r/   r   .   s2    Bì/&r   c                       s\   e Zd ZdZdZ										
		d‡ fdd„	Zedeee	j
f ddfdd„ƒZ‡  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                    sX   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#   rW   rV   r&   r%   rX   r'   r,   r-   r   r/   r   è   s   
zBlipVisionConfig.__init__r0   r1   r   c                 K   r2   )Nr3   r4   Úvision_configr6   r7   r8   r9   rA   r   r   r/   rD     rE   z BlipVisionConfig.from_pretrained)r	   r
   r   r   r   rR   rS   r   rT   r   rU   rF   r   r   r-   r/   rP   µ   s"    0ô&rP   c                       sF   e Zd ZdZdZ					d‡ fdd„	Zed	ed
efdd„ƒZ	‡  Z
S )Ú
BlipConfiga”  
    [`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):
            Dimentionality of text and vision projection layers.
        logit_scale_init_value (`float`, *optional*, defaults to 2.6592):
            The inital value of the *logit_scale* paramter. Default is used as per the original BLIP implementation.
        image_text_hidden_size (`int`, *optional*, defaults to 256):
            Dimentionality of the hidden state of the image-text fusion layer.
        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)
    ```r4   Nr   çƒ/L¦
F@é   c                    sŒ   t ƒ jdi |¤Ž |d u ri }t d¡ |d u r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   r>   Úinfor   r5   rP   rY   r   r   r    Úlogit_scale_init_valueÚinitializer_factorr'   Úimage_text_hidden_size)r+   r5   rY   r    r^   r`   r,   r-   r   r/   r   I  s   	


zBlipConfig.__init__r5   rY   c                 K   s   | 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
        )r5   rY   Nr   )Úto_dict)rB   r5   rY   r,   r   r   r/   Úfrom_text_vision_configsg  s   
z#BlipConfig.from_text_vision_configs)NNr   r[   r\   )rG   rH   rI   rJ   r3   r   rK   r   rP   rb   rO   r   r   r-   r/   rZ     s    .úrZ   )rJ   rM   Útypingr   Úconfiguration_utilsr   Úutilsr   Ú
get_loggerrG   r>   Ú"BLIP_PRETRAINED_CONFIG_ARCHIVE_MAPr   rP   rZ   r   r   r   r/   Ú<module>   s&   
ñ c