a
    ½ÀhN3  ã                   @   sb   d Z ddlmZ ddlmZ e e¡ZG dd„ deƒZG dd„ deƒZ	G dd	„ d	eƒZ
g d
¢ZdS )zOWLv2 model configurationé   )ÚPretrainedConfig)Úloggingc                       s*   e Zd ZdZdZdZd‡ fdd„	Z‡  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
    ```Zowlv2_text_modelÚtext_configé Á  é   é   é   é   é   Ú
quick_geluçñhãˆµøä>ç        ç{®Gáz”?ç      ð?é    éþÀ  éÿÀ  c                    s`   t ƒ jf |||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__© úi/var/www/html/assistant/venv/lib/python3.9/site-packages/transformers/models/owlv2/configuration_owlv2.pyr   X   s    zOwlv2TextConfig.__init__)r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeZbase_config_keyr   Ú__classcell__r(   r(   r&   r)   r      s$   ;              ñr   c                       s*   e Zd ZdZdZdZd‡ fdd„	Z‡  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
    ```Zowlv2_vision_modelÚvision_configé   é   r	   r   r   r   r   r   r   r   c                    s^   t ƒ jf i |¤Ž || _|| _|| _|| _|| _|| _|| _|| _	|	| _
|
| _|| _|| _d S )N)r   r   r   r   r   r   Únum_channelsÚ
image_sizeÚ
patch_sizer   r    r!   r"   r#   )r$   r   r   r   r   r5   r6   r7   r   r    r!   r"   r#   r%   r&   r(   r)   r   ²   s    zOwlv2VisionConfig.__init__)r3   r4   r	   r	   r   r3   r   r   r   r   r   r   r*   r(   r(   r&   r)   r1   z   s    4            ór1   c                       sD   e Zd ZdZdZeedœZd‡ fdd	„	Ze	e
e
dœd
d„ƒZ‡  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.
    Zowlv2)r   r2   Nr   çƒ/L¦
F@Tc                    sz   t ƒ jf i |¤Ž |d u r(i }t d¡ |d u r>i }t d¡ tf i |¤Ž| _tf 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   ÚloggerÚinfor   r   r1   r2   Úprojection_dimÚlogit_scale_init_valueÚreturn_dictr#   )r$   r   r2   r<   r=   r>   r%   r&   r(   r)   r   ð   s    	

zOwlv2Config.__init__c                 K   s&   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
        r   r2   )Ú	from_dict)Úclsr   r2   r%   Zconfig_dictr(   r(   r)   Úfrom_text_vision_configs  s    	z$Owlv2Config.from_text_vision_configs)NNr   r9   T)r+   r,   r-   r.   r/   r   r1   Zsub_configsr   ÚclassmethodÚdictrA   r0   r(   r(   r&   r)   r8   Ó   s   
     úr8   )r8   r   r1   N)r.   Zconfiguration_utilsr   Úutilsr   Z
get_loggerr+   r:   r   r1   r8   Ú__all__r(   r(   r(   r)   Ú<module>   s   
aYH