
    gn<                         d Z ddlZddlmZmZmZ er	 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OWLv2 model configuration    N)TYPE_CHECKINGDict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 )Owlv2TextConfigaw  
    This is the configuration class to store the configuration of an [`Owlv2TextModel`]. It is used to instantiate an
    Owlv2 text 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 Owlv2
    [google/owlv2-base-patch16](https://huggingface.co/google/owlv2-base-patch16) 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 49408):
            Vocabulary size of the OWLv2 text model. Defines the number of different tokens that can be represented
            by the `inputs_ids` passed when calling [`Owlv2TextModel`].
        hidden_size (`int`, *optional*, defaults to 512):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 2048):
            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 16):
            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 `"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-05):
            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.0):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).
        pad_token_id (`int`, *optional*, defaults to 0):
            The id of the padding token in the input sequences.
        bos_token_id (`int`, *optional*, defaults to 49406):
            The id of the beginning-of-sequence token in the input sequences.
        eos_token_id (`int`, *optional*, defaults to 49407):
            The id of the end-of-sequence token in the input sequences.

    Example:

    ```python
    >>> from transformers import Owlv2TextConfig, Owlv2TextModel

    >>> # Initializing a Owlv2TextModel with google/owlv2-base-patch16 style configuration
    >>> configuration = Owlv2TextConfig()

    >>> # Initializing a Owlv2TextConfig from the google/owlv2-base-patch16 style configuration
    >>> model = Owlv2TextModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```owlv2_text_model                  
quick_geluh㈵>        {Gz?      ?r       c                      t                      j        d|||d| || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        d S )N)pad_token_idbos_token_ideos_token_id )super__init__
vocab_sizehidden_sizeintermediate_sizenum_hidden_layersnum_attention_headsmax_position_embeddings
hidden_actlayer_norm_epsattention_dropoutinitializer_rangeinitializer_factor)selfr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r   r   r   kwargs	__class__s                   i/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/owlv2/configuration_owlv2.pyr   zOwlv2TextConfig.__init__^   s    $ 	sl\hsslrsss$&!2!2#6 '>$$,!2!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owlv2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_dicts       r.   from_pretrainedzOwlv2TextConfig.from_pretrained~   s      (((1c12OZZSYZZV ??<((G33%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   r   r   r   r   r   r   r   __name__
__module____qualname____doc__r3   r   classmethodr   strosPathLikerD   __classcell__r-   s   @r.   r
   r
       s        9 9v $J  "5 5 5 5 5 5@ 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r/   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 )Owlv2VisionConfigaY  
    This is the configuration class to store the configuration of an [`Owlv2VisionModel`]. It is used to instantiate
    an OWLv2 image 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 OWLv2
    [google/owlv2-base-patch16](https://huggingface.co/google/owlv2-base-patch16) 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.
        num_channels (`int`, *optional*, defaults to 3):
            Number of channels in the input images.
        image_size (`int`, *optional*, defaults to 768):
            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 `"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-05):
            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.0):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).

    Example:

    ```python
    >>> from transformers import Owlv2VisionConfig, Owlv2VisionModel

    >>> # Initializing a Owlv2VisionModel with google/owlv2-base-patch16 style configuration
    >>> configuration = Owlv2VisionConfig()

    >>> # Initializing a Owlv2VisionModel model from the google/owlv2-base-patch16 style configuration
    >>> model = Owlv2VisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```owlv2_vision_model      r   r   r   r   r   r   r   r   c                      t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        d S )Nr   )r   r   r!   r"   r#   r$   num_channels
image_size
patch_sizer&   r'   r(   r)   r*   )r+   r!   r"   r#   r$   rV   rW   rX   r&   r'   r(   r)   r*   r,   r-   s                 r.   r   zOwlv2VisionConfig.__init__   s      	""6"""&!2!2#6 ($$$,!2!2"4r/   r0   r1   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 )Nr3   r4   vision_configr6   r7   r8   r9   rA   s       r.   rD   z!Owlv2VisionConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((G33%o6K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r/   )rS   rT   r   r   r   rS   r   r   r   r   r   r   rE   rO   s   @r.   rQ   rQ      s        2 2h &J 5 5 5 5 5 5> 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r/   rQ   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ededefd            Z xZS )Owlv2Configa  
    [`Owlv2Config`] is the configuration class to store the configuration of an [`Owlv2Model`]. It is used to
    instantiate an OWLv2 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 OWLv2
    [google/owlv2-base-patch16](https://huggingface.co/google/owlv2-base-patch16) 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 [`Owlv2TextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`Owlv2VisionConfig`].
        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 OWLv2
            implementation.
        return_dict (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return a dictionary. If `False`, returns a tuple.
        kwargs (*optional*):
            Dictionary of keyword arguments.
    r4   Nr   /L
F@Tc                 .    t                      j        di | |i }t                              d           |i }t                              d           t	          di || _        t          di || _        || _        || _	        || _
        d| _        d S )NzJtext_config is None. Initializing the Owlv2TextConfig with default values.zNvision_config is None. initializing the Owlv2VisionConfig with default values.r   r   )r   r   r>   infor
   r5   rQ   rZ   projection_dimlogit_scale_init_valuereturn_dictr*   )r+   r5   rZ   r`   ra   rb   r,   r-   s          r.   r   zOwlv2Config.__init__  s     	""6"""KKKdeee MKKhiii*99[99.????,&<#&"%r/   r0   r1   r   c                    |                      |            | j        |fi |\  }}d|v rMt          | d          r=|d         | j        k    r,t                              d|d          d| j         d            | j        |fi |S )Nr3   r6   r7   r8   )r:   r;   r=   r3   r>   r?   r@   rA   s       r.   rD   zOwlv2Config.from_pretrained3  s      (((1c12OZZSYZZV;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r/   r5   rZ   c                 6    i }||d<   ||d<    | j         |fi |S )z
        Instantiate a [`Owlv2Config`] (or a derived class) from owlv2 text model configuration and owlv2 vision
        model configuration.

        Returns:
            [`Owlv2Config`]: An instance of a configuration object
        r5   rZ   )r@   )rB   r5   rZ   r,   rC   s        r.   from_text_vision_configsz$Owlv2Config.from_text_vision_configsA  s7     %0M"'4O$s}[33F333r/   )NNr   r]   T)rF   rG   rH   rI   r3   r   rJ   r   rK   rL   rM   rD   r   re   rN   rO   s   @r.   r\   r\      s         2 J %& & & & & &6 4E#r{BR<S 4bt 4 4 4 [4 44 4 4 4 4 [4 4 4 4 4r/   r\   )rI   rL   typingr   r   r   configuration_utilsr   utilsr   
get_loggerrF   r>   r
   rQ   r\   r   r/   r.   <module>rj      s       				 - - - - - - - - - -  	 3 3 3 3 3 3       
	H	%	%n4 n4 n4 n4 n4& n4 n4 n4df4 f4 f4 f4 f4( f4 f4 f4TR4 R4 R4 R4 R4" R4 R4 R4 R4 R4r/   