
    gA                        d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
 erddlmZ ddlm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 G d de          ZdS )zOWL-ViT model configuration    NOrderedDict)TYPE_CHECKINGAnyDictMappingOptionalUnion   )ProcessorMixin)
TensorType)PretrainedConfig)
OnnxConfig)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 )OwlViTTextConfiga  
    This is the configuration class to store the configuration of an [`OwlViTTextModel`]. It is used to instantiate an
    OwlViT 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 OwlViT
    [google/owlvit-base-patch32](https://huggingface.co/google/owlvit-base-patch32) 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 OWL-ViT text model. Defines the number of different tokens that can be represented
            by the `inputs_ids` passed when calling [`OwlViTTextModel`].
        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 OwlViTTextConfig, OwlViTTextModel

    >>> # Initializing a OwlViTTextModel with google/owlvit-base-patch32 style configuration
    >>> configuration = OwlViTTextConfig()

    >>> # Initializing a OwlViTTextConfig from the google/owlvit-base-patch32 style configuration
    >>> model = OwlViTTextModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```owlvit_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/   r0   r1   r2   r"   r#   r$   kwargs	__class__s                   k/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/owlvit/configuration_owlvit.pyr'   zOwlViTTextConfig.__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owlvit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hasattrr;   loggerwarning	from_dictclsr8   r4   config_dicts       r6   from_pretrainedz OwlViTTextConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((H44%m4K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r7   )r   r   r   r   r   r   r   r   r   r   r   r   r   r    __name__
__module____qualname____doc__r;   r'   classmethodr
   strosPathLikerL   __classcell__r5   s   @r6   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 4r7   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 )OwlViTVisionConfigah  
    This is the configuration class to store the configuration of an [`OwlViTVisionModel`]. It is used to instantiate
    an OWL-ViT 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 OWL-ViT
    [google/owlvit-base-patch32](https://huggingface.co/google/owlvit-base-patch32) 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 32):
            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 OwlViTVisionConfig, OwlViTVisionModel

    >>> # Initializing a OwlViTVisionModel with google/owlvit-base-patch32 style configuration
    >>> configuration = OwlViTVisionConfig()

    >>> # Initializing a OwlViTVisionModel model from the google/owlvit-base-patch32 style configuration
    >>> model = OwlViTVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```owlvit_vision_model      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/   r0   r1   r2   )r3   r)   r*   r+   r,   r_   r`   ra   r.   r/   r0   r1   r2   r4   r5   s                 r6   r'   zOwlViTVisionConfig.__init__   s      	""6"""&!2!2#6 ($$$,!2!2"4r7   r8   r9   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 )Nr;   r<   vision_configr>   r?   r@   rA   rI   s       r6   rL   z"OwlViTVisionConfig.from_pretrained   s      (((1c12OZZSYZZV ??<((H44%o6K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r7   )r[   r\   r   r   r   r[   r]   r   r   r   r   r   rM   rW   s   @r6   rY   rY      s        2 2h 'J 5 5 5 5 5 5> 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r7   rY   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 )OwlViTConfiga  
    [`OwlViTConfig`] is the configuration class to store the configuration of an [`OwlViTModel`]. It is used to
    instantiate an OWL-ViT 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 OWL-ViT
    [google/owlvit-base-patch32](https://huggingface.co/google/owlvit-base-patch32) 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 [`OwlViTTextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`OwlViTVisionConfig`].
        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 OWL-ViT
            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.
    r<   Nr   /L
F@Tc                 .    t                      j        di | |i }t                              d           |i }t                              d           t	          di || _        t          di || _        || _        || _	        || _
        d| _        d S )NzKtext_config is None. Initializing the OwlViTTextConfig with default values.zOvision_config is None. initializing the OwlViTVisionConfig with default values.r   r%   )r&   r'   rF   infor   r=   rY   rc   projection_dimlogit_scale_init_valuereturn_dictr2   )r3   r=   rc   ri   rj   rk   r4   r5   s          r6   r'   zOwlViTConfig.__init__  s     	""6"""KKKefff MKKijjj+::k::/@@-@@,&<#&"%r7   r8   r9   r   c                    |                      |            | j        |fi |\  }}d|v rMt          | d          r=|d         | j        k    r,t                              d|d          d| j         d            | j        |fi |S )Nr;   r>   r?   r@   )rB   rC   rE   r;   rF   rG   rH   rI   s       r6   rL   zOwlViTConfig.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3r7   r=   rc   c                 6    i }||d<   ||d<    | j         |fi |S )z
        Instantiate a [`OwlViTConfig`] (or a derived class) from owlvit text model configuration and owlvit vision
        model configuration.

        Returns:
            [`OwlViTConfig`]: An instance of a configuration object
        r=   rc   )rH   )rJ   r=   rc   r4   rK   s        r6   from_text_vision_configsz%OwlViTConfig.from_text_vision_configsA  s7     %0M"'4O$s}[33F333r7   )NNr   rf   T)rN   rO   rP   rQ   r;   r'   rR   r
   rS   rT   rU   rL   r   rn   rV   rW   s   @r6   re   re      s         2 J %& & & & & &6 4E#r{BR<S 4bt 4 4 4 [4 44 4 4 4 4 [4 4 4 4 4r7   re   c                       e Zd Zedeeeeef         f         fd            Zedeeeeef         f         fd            Zede	fd            Z
	 	 	 dddd	ed
eded         deeef         f
 fdZedefd            Z xZS )OwlViTOnnxConfigr9   c           	      H    t          ddddfdddddd	fd
dddfg          S )N	input_idsbatchsequence)r      pixel_valuesr_   heightwidth)r   ru      r   attention_maskr   r3   s    r6   inputszOwlViTOnnxConfig.inputsR  sN    'j99:WHQX!Y!YZ!w:#>#>?
 
 	
r7   c                 H    t          dddifdddifdddifdddifg          S )Nlogits_per_imager   rs   logits_per_texttext_embedsimage_embedsr   r{   s    r6   outputszOwlViTOnnxConfig.outputs\  sI    #a\2"QL1G-!W.	
 
 	
r7   c                     dS )Ng-C6?r%   r{   s    r6   atol_for_validationz$OwlViTOnnxConfig.atol_for_validationg  s    tr7   N	processorr   
batch_size
seq_length	frameworkr   c                     t                                          |j        |||          }t                                          |j        ||          }i ||S )N)r   r   r   )r   r   )r&   generate_dummy_inputs	tokenizerimage_processor)r3   r   r   r   r   text_input_dictimage_input_dictr5   s          r6   r   z&OwlViTOnnxConfig.generate_dummy_inputsk  sn      ''77J:Yb 8 
 
 !7788%*	 9 
 
 7/6%566r7   c                     dS )N   r%   r{   s    r6   default_onnx_opsetz#OwlViTOnnxConfig.default_onnx_opsetz  s    rr7   )r   r   N)rN   rO   rP   propertyr   rS   intr|   r   floatr   r	   r   r   r   rV   rW   s   @r6   rp   rp   Q  sK       
WS#X%6 67 
 
 
 X
 
gc3h&7!78 
 
 
 X
 U    X ,07 7#7 7 	7
 L)7 
c	7 7 7 7 7 7 C    X    r7   rp   )rQ   rT   collectionsr   typingr   r   r   r   r	   r
   processing_utilsr   utilsr   configuration_utilsr   onnxr   r   
get_loggerrN   rF   r   rY   re   rp   r%   r7   r6   <module>r      s   " ! 				 # # # # # # E E E E E E E E E E E E E E E E  $222222###### 3 3 3 3 3 3             
	H	%	%n4 n4 n4 n4 n4' n4 n4 n4bf4 f4 f4 f4 f4) f4 f4 f4RR4 R4 R4 R4 R4# R4 R4 R4j+ + + + +z + + + + +r7   