
    gQ?                         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BridgeTower model configuration    N)Union   )PretrainedConfig)loggingc                   v     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 )BridgeTowerVisionConfiga  
    This is the configuration class to store the vision configuration of a [`BridgeTowerModel`]. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the bridgetower-base
    [BridgeTower/bridgetower-base](https://huggingface.co/BridgeTower/bridgetower-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.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in visual encoder model.
        patch_size (`int`, *optional*, defaults to 16):
            The size (resolution) of each patch.
        image_size (`int`, *optional*, defaults to 288):
            The size (resolution) of each image.
        initializer_factor (`float`, *optional*, defaults to 1):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).
        layer_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the layer normalization layers.
        stop_gradient (`bool`, *optional*, defaults to `False`):
            Whether to stop gradient for training.
        share_layernorm (`bool`, *optional*, defaults to `True`):
            Whether LayerNorm layers are shared.
        remove_last_layer (`bool`, *optional*, defaults to `False`):
            Whether to remove the last layer from the vision encoder.


    Example:

    ```python
    >>> from transformers import BridgeTowerVisionConfig

    >>> # Initializing a BridgeTower BridgeTower/bridgetower-base style configuration for the vision model
    >>> configuration = BridgeTowerVisionConfig()

    >>> # Accessing the configuration
    >>> configuration
    ```bridgetower_vision_model      r            h㈵>FTc                      t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        d S N )super__init__hidden_sizenum_hidden_layersnum_channels
patch_size
image_sizeinitializer_factorlayer_norm_epsstop_gradientshare_layernormremove_last_layer)selfr   r   r   r   r   r   r   r   r   r   kwargs	__class__s               u/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/bridgetower/configuration_bridgetower.pyr   z BridgeTowerVisionConfig.__init__H   sv     	""6"""&!2($$"4,*.!2    pretrained_model_name_or_pathreturnr   c                 $    | 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bridgetowertext_configzYou are using a model of type z  to instantiate a model of type zN. This is not supported for all configurations of models and can yield errors.get_config_dictgethasattrr(   loggerwarning	from_dictclsr$   r    config_dicts       r"   from_pretrainedz'BridgeTowerVisionConfig.from_pretrainedb       1c12OZZSYZZV??<((M99%m4K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r#   )
r
   r   r   r   r   r   r   FTF__name__
__module____qualname____doc__r(   r   classmethodr   strosPathLiker5   __classcell__r!   s   @r"   r   r      s        ( (T ,J 3 3 3 3 3 34 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r#   r   c                        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 )BridgeTowerTextConfiga  
    This is the configuration class to store the text configuration of a [`BridgeTowerModel`]. The default values here
    are copied from RoBERTa. Instantiating a configuration with the defaults will yield a similar configuration to that
    of the bridgetower-base [BridegTower/bridgetower-base](https://huggingface.co/BridgeTower/bridgetower-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:
        vocab_size (`int`, *optional*, defaults to 50265):
            Vocabulary size of the text part of the model. Defines the number of different tokens that can be
            represented by the `inputs_ids` passed when calling [`BridgeTowerModel`].
        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 514):
            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).
        type_vocab_size (`int`, *optional*, defaults to 2):
            The vocabulary size of the `token_type_ids`.
        initializer_factor (`float`, *optional*, defaults to 1):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).
        layer_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the layer normalization layers.
        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).
        is_decoder (`bool`, *optional*, defaults to `False`):
            Whether the model is used as a decoder or not. If `False`, the model is used as an encoder.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models). Only
            relevant if `config.is_decoder=True`.

    Example:

    ```python
    >>> from transformers import BridgeTowerTextConfig

    >>> # Initializing a BridgeTower BridgeTower/bridgetower-base style configuration for the text model
    >>> configuration = BridgeTowerTextConfig()

    >>> # Accessing the configuration
    >>> configuration
    ```bridgetower_text_modelY  r
   r   r      gelu皙?  r   r      absoluteTc                 (    t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        || _        || _        || _        d S r   )r   r   
vocab_sizer   r   num_attention_heads
hidden_actr   intermediate_sizehidden_dropout_probattention_probs_dropout_probmax_position_embeddingstype_vocab_sizer   position_embedding_type	use_cachepad_token_idbos_token_ideos_token_id)r   rM   r   r   rN   r   rP   rO   rQ   rR   rS   rT   r   rW   rX   rY   rU   rV   r    r!   s                      r"   r   zBridgeTowerTextConfig.__init__   s    * 	""6"""$&!2#6 $"4!2#6 ,H)'>$.,'>$"(((r#   r$   r%   r   c                 $    | 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 r'   r+   r2   s       r"   r5   z%BridgeTowerTextConfig.from_pretrained   r6   r#   )rE   r
   r   r   r   rF   rG   rH   rH   rI   r   r   r   r   rJ   rK   Tr7   rA   s   @r"   rC   rC   r   s        < <| *J %( # *%') ') ') ') ') ')R 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r#   rC   c                   b     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Zededefd            Z	 xZ
S )BridgeTowerConfiga~  
    This is the configuration class to store the configuration of a [`BridgeTowerModel`]. It is used to instantiate a
    BridgeTower 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 bridgetower-base
    [BridgeTower/bridgetower-base](https://huggingface.co/BridgeTower/bridgetower-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:
        share_cross_modal_transformer_layers (`bool`, *optional*, defaults to `True`):
            Whether cross modal transformer layers are shared.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler.
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers and the pooler layer.
        initializer_factor (`float`, *optional*, defaults to 1):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).
        layer_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the layer normalization layers.
        share_link_tower_layers (`bool`, *optional*, defaults to `False`):
            Whether the bride/link tower layers are shared.
        link_tower_type (`str`, *optional*, defaults to `"add"`):
            Type of the bridge/link layer.
        num_attention_heads (`int`, *optional*, defaults to 12):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 6):
            Number of hidden layers in the Transformer encoder.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether to tie input and output embeddings.
        init_layernorm_from_vision_encoder (`bool`, *optional*, defaults to `False`):
            Whether to init LayerNorm from the vision encoder.
        text_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`BridgeTowerTextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`BridgeTowerVisionConfig`].

    Example:

    ```python
    >>> from transformers import BridgeTowerModel, BridgeTowerConfig

    >>> # Initializing a BridgeTower BridgeTower/bridgetower-base style configuration
    >>> configuration = BridgeTowerConfig()

    >>> # Initializing a model from the BridgeTower/bridgetower-base style configuration
    >>> model = BridgeTowerModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```r)   TrG   r
   r   r   Faddr      Nc                    |                     dd           }|                     dd           } t                      j        di | || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        |
| _        || _        |i }t                              d           |i }t                              d           t!          di || _        t%          di || _        d S )Ntext_config_dictvision_config_dictzV`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.zZ`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values.r   )popr   r   $share_cross_modal_transformer_layersrO   r   r   r   share_link_tower_layerslink_tower_typerN   r   tie_word_embeddings"init_layernorm_from_vision_encoderr/   inforC   r*   r   vision_config)r   rc   rO   r   r   r   rd   re   rN   r   rf   rg   r*   ri   r    _r!   s                   r"   r   zBridgeTowerConfig.__init__$  s   $ JJ)400JJ+T22""6"""4X1$&"4,'>$.#6 !2#6 2T/KKKpqqq MKKtuuu0??;??4EE}EEr#   r*   ri   c                 `     | d|                                 |                                 d|S )z
        Instantiate a [`BridgeTowerConfig`] (or a derived class) from BridgeTower text model configuration. Returns:
            [`BridgeTowerConfig`]: An instance of a configuration object
        )r*   ri   r   )to_dict)r3   r*   ri   r    s       r"   from_text_vision_configsz*BridgeTowerConfig.from_text_vision_configsQ  s:     sf{2244MDYDYD[D[ff_efffr#   )TrG   r
   r   r   Fr]   r   r^   FFNN)r8   r9   r:   r;   r(   r   r<   rC   r   rm   r@   rA   s   @r"   r\   r\      s        3 3j J .2 %!+0+F +F +F +F +F +FZ g/g@Wg g g [g g g g gr#   r\   )r;   r>   typingr   configuration_utilsr   utilsr   
get_loggerr8   r/   r   rC   r\   r   r#   r"   <module>rr      s   & % 				       3 3 3 3 3 3       
	H	%	%T4 T4 T4 T4 T4. T4 T4 T4nw4 w4 w4 w4 w4, w4 w4 w4tng ng ng ng ng( ng ng ng ng ngr#   