
    g3                         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KOSMOS-2 model configuration    N)Union   )PretrainedConfig)loggingc                        e Zd ZdZdZdgZddddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Zede	e
ej        f         ddfd            Z xZS )Kosmos2TextConfigav  
    This is the configuration class to store the configuration of a [`Kosmos2TextModel`]. It is used to instantiate a
    KOSMOS-2 text decoder according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the text decoder of the KOSMOS-2
    [microsoft/kosmos-2-patch14-224](https://huggingface.co/microsoft/kosmos-2-patch14-224) 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 65037):
            Vocabulary size of the Kosmos2 model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`Kosmos2Model`].
        max_position_embeddings (`int`, *optional*, defaults to 2048):
            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).
        embed_dim (`int`, *optional*, defaults to 2048):
            Dimensionality of the layers and the pooler layer.
        layers (`int`, *optional*, defaults to 24):
            Number of hidden layers in the Transformer encoder.
        ffn_dim (`int`, *optional*, defaults to 8192):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        attention_heads (`int`, *optional*, defaults to 32):
            Number of attention heads for each attention layer in the Transformer encoder.
        activation_function (`str` or `function`, *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.
        dropout (`float`, *optional*, defaults to 0.1):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        attention_dropout (`float`, *optional*, defaults to 0.1):
            The dropout ratio for the attention probabilities.
        activation_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for activations inside the fully connected layer.
        layerdrop (`float`, *optional*, defaults to 0.0):
            The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://arxiv.org/abs/1909.11556)
            for more details.
        layer_norm_eps (`float`, *optional*, defaults to 1e-5):
            The epsilon used by the layer normalization layers.
        init_std (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        scale_embedding (`bool`, *optional*, defaults to `True`):
            Scale embeddings by diving by sqrt(embed_dim).
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models).
    ```kosmos_2_text_modelpast_key_valuesattention_heads	embed_dimlayers)num_attention_headshidden_sizenum_hidden_layers                gelu皙?        h㈵>{Gz?T   r      c                     t                      j        d|||d| || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        || _        d S )N)pad_token_idbos_token_ideos_token_id )super__init__
vocab_sizemax_position_embeddingsr   r   ffn_dimr   activation_functiondropoutattention_dropoutactivation_dropout	layerdroplayer_norm_epsinit_stdscale_embedding	use_cache)selfr$   r%   r   r   r&   r   r'   r(   r)   r*   r+   r,   r-   r.   r/   r   r   r    kwargs	__class__s                       m/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/kosmos2/configuration_kosmos2.pyr#   zKosmos2TextConfig.__init__R   s    , 	 	
%%%	
 	
 		
 	
 	
 %'>$".#6 !2"4", ."    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kosmos-2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hasattrr8   loggerwarning	from_dictclsr5   r1   config_dicts       r3   from_pretrainedz!Kosmos2TextConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((J66%m4K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r4   )r   r   r   r   r   r   r   r   r   r   r   r   r   TTr   r   r   )__name__
__module____qualname____doc__r8   keys_to_ignore_at_inferenceattribute_mapr#   classmethodr   strosPathLikerI   __classcell__r2   s   @r3   r   r      s        , ,\ 'J#4"50"% M  $"'+# +# +# +# +# +#Z 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r4   r   c                   z     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 )Kosmos2VisionConfiga	  
    This is the configuration class to store the configuration of a [`Kosmos2VisionModel`]. It is used to instantiate a
    KOSMOS-2 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 vision encoder of the KOSMOS-2
    [microsoft/kosmos-2-patch14-224](https://huggingface.co/microsoft/kosmos-2-patch14-224) 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 1024):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 4096):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 24):
            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.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        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 `"quick_gelu"`):
            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-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 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        initializer_factor (`float`, *optional*, defaults to 1):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).
    ```kosmos_2_vision_model      r      r         
quick_gelur   r   r         ?c                      t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        || _
        |
| _        |	| _        || _        d S )Nr!   )r"   r#   r   intermediate_sizer   r   num_channels
patch_size
image_sizeinitializer_rangeinitializer_factorr)   r,   
hidden_act)r0   r   ra   r   r   rb   rd   rc   rg   r,   r)   re   rf   r1   r2   s                 r3   r#   zKosmos2VisionConfig.__init__   s      	""6"""&!2!2#6 ($$!2"4!2,$r4   r5   r6   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 )Nr8   r9   vision_configr;   r<   r=   r>   rF   s       r3   rI   z#Kosmos2VisionConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((J66%o6K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r4   )rY   rZ   r   r[   r   r\   r]   r^   r   r   r   r_   )rJ   rK   rL   rM   r8   r#   rP   r   rQ   rR   rS   rI   rT   rU   s   @r3   rW   rW      s        $ $L )J % % % % % %> 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r4   rW   c                   2     e Zd ZdZdZdZ	 	 	 d fd	Z xZS )Kosmos2Configat  
    This is the configuration class to store the configuration of a [`Kosmos2Model`]. It is used to instantiate a
    KOSMOS-2 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 KOSMOS-2
    [microsoft/kosmos-2-patch14-224](https://huggingface.co/microsoft/kosmos-2-patch14-224) architecture.

    Args:
        text_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`Kosmos2TextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`Kosmos2VisionConfig`].
        latent_query_num (`int`, *optional*, defaults to 64):
            The number of latent query tokens that represent the image features used in the text decoder component.
        kwargs (*optional*):
            Dictionary of keyword arguments.

    Example:

    ```python
    >>> from transformers import Kosmos2Config, Kosmos2Model

    >>> # Initializing a Kosmos-2 kosmos-2-patch14-224 style configuration
    >>> configuration = Kosmos2Config()

    >>> # Initializing a model (with random weights) from the kosmos-2-patch14-224 style configuration
    >>> model = Kosmos2Model(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```r9   TN@   c                     t                      j        di | |i }t                              d           |i }t                              d           t	          di || _        t          di || _        || _        d S )NzR`text_config` is `None`. Initializing the `Kosmos2TextConfig` with default values.zV`vision_config` is `None`. Initializing the `Kosmos2VisionConfig` with default values.r!   )	r"   r#   rC   infor   r:   rW   ri   latent_query_num)r0   r:   ri   ro   r1   r2   s        r3   r#   zKosmos2Config.__init__  s     	""6"""KKKlmmm MKKpqqq,;;{;;0AA=AA 0r4   )NNrl   )rJ   rK   rL   rM   r8   is_compositionr#   rT   rU   s   @r3   rk   rk      s^         > JN 	1 1 1 1 1 1 1 1 1 1r4   rk   )rM   rR   typingr   configuration_utilsr   utilsr   
get_loggerrJ   rC   r   rW   rk   r!   r4   r3   <module>ru      s    # " 				       3 3 3 3 3 3       
	H	%	%t4 t4 t4 t4 t4( t4 t4 t4nX4 X4 X4 X4 X4* X4 X4 X4v71 71 71 71 71$ 71 71 71 71 71r4   