






import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
       from ...processing_utils import ProcessorMixin
       from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__magic_name__   :  List[Any]        =							logging.get_logger(__name__)

__magic_name__   :  Union[str, Any]        =							{
    '''google/owlvit-base-patch32''': '''https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json''',
    '''google/owlvit-base-patch16''': '''https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json''',
    '''google/owlvit-large-patch14''': '''https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json''',
}





class 					A__     (     __snake_case ):

     '''simple docstring'''






     snake_case__					=					"""owlvit_text_model"""







     def __init__( self      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=4_9408   ,						_SCREAMING_SNAKE_CASE      :    List[Any]=512   ,						_SCREAMING_SNAKE_CASE      :    Dict=2048   ,						_SCREAMING_SNAKE_CASE      :    Any=12   ,						_SCREAMING_SNAKE_CASE      :    str=8   ,						_SCREAMING_SNAKE_CASE      :    Any=16   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]="quick_gelu"   ,						_SCREAMING_SNAKE_CASE      :    List[Any]=1E-5   ,						_SCREAMING_SNAKE_CASE      :    int=0.0   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=0.0_2   ,						_SCREAMING_SNAKE_CASE      :    Tuple=1.0   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=0   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=4_9406   ,						_SCREAMING_SNAKE_CASE      :    Any=4_9407   ,						**_SCREAMING_SNAKE_CASE      :    Optional[int]   ,						):






           """simple docstring"""




           super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE   ,						bos_token_id=_SCREAMING_SNAKE_CASE   ,						eos_token_id=_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  vocab_size
           UpperCamelCase					       =  hidden_size
           UpperCamelCase					       =  intermediate_size
           UpperCamelCase					       =  num_hidden_layers
           UpperCamelCase					       =  num_attention_heads
           UpperCamelCase					       =  max_position_embeddings
           UpperCamelCase					       =  hidden_act
           UpperCamelCase					       =  layer_norm_eps
           UpperCamelCase					       =  attention_dropout
           UpperCamelCase					       =  initializer_range
           UpperCamelCase					       =  initializer_factor







     @classmethod
     def   _SCREAMING_SNAKE_CASE     ( cls      :    Union[str, Any]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, os.PathLike]   ,						**_SCREAMING_SNAKE_CASE      :    List[Any] ):






           """simple docstring"""




           cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE )

           UpperCamelCase       ,  UpperCamelCase					       =  cls.get_config_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )

           # get the text config dict if we are loading from OwlViTConfig
           if config_dict.get('model_type' ) == "owlvit":
                 UpperCamelCase					       =  config_dict['text_config']

           if "model_type" in config_dict and hasattr(cls   ,						'model_type' ) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                     f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.' )

           return cls.from_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )





class 					A__     (     __snake_case ):

     '''simple docstring'''






     snake_case__					=					"""owlvit_vision_model"""







     def __init__( self      :    Optional[int]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]=768   ,						_SCREAMING_SNAKE_CASE      :    str=3072   ,						_SCREAMING_SNAKE_CASE      :    Dict=12   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]=12   ,						_SCREAMING_SNAKE_CASE      :    str=3   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=768   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=32   ,						_SCREAMING_SNAKE_CASE      :    Any="quick_gelu"   ,						_SCREAMING_SNAKE_CASE      :    int=1E-5   ,						_SCREAMING_SNAKE_CASE      :    str=0.0   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]=0.0_2   ,						_SCREAMING_SNAKE_CASE      :    Tuple=1.0   ,						**_SCREAMING_SNAKE_CASE      :    List[str]   ,						):






           """simple docstring"""




           super().__init__(**_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  hidden_size
           UpperCamelCase					       =  intermediate_size
           UpperCamelCase					       =  num_hidden_layers
           UpperCamelCase					       =  num_attention_heads
           UpperCamelCase					       =  num_channels
           UpperCamelCase					       =  image_size
           UpperCamelCase					       =  patch_size
           UpperCamelCase					       =  hidden_act
           UpperCamelCase					       =  layer_norm_eps
           UpperCamelCase					       =  attention_dropout
           UpperCamelCase					       =  initializer_range
           UpperCamelCase					       =  initializer_factor







     @classmethod
     def   _SCREAMING_SNAKE_CASE     ( cls      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, os.PathLike]   ,						**_SCREAMING_SNAKE_CASE      :    Dict ):






           """simple docstring"""




           cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE )

           UpperCamelCase       ,  UpperCamelCase					       =  cls.get_config_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )

           # get the vision config dict if we are loading from OwlViTConfig
           if config_dict.get('model_type' ) == "owlvit":
                 UpperCamelCase					       =  config_dict['vision_config']

           if "model_type" in config_dict and hasattr(cls   ,						'model_type' ) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                     f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.' )

           return cls.from_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )





class 					A__     (     __snake_case ):

     '''simple docstring'''






     snake_case__					=					"""owlvit"""
     snake_case__					=					True







     def __init__( self      :    Union[str, Any]   ,						_SCREAMING_SNAKE_CASE      :    str=None   ,						_SCREAMING_SNAKE_CASE      :    int=None   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=512   ,						_SCREAMING_SNAKE_CASE      :    Any=2.6_5_9_2   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=True   ,						**_SCREAMING_SNAKE_CASE      :    Union[str, Any]   ,						):






           """simple docstring"""




           super().__init__(**_SCREAMING_SNAKE_CASE )

           if text_config is None:
                 UpperCamelCase					       =  {}
                 logger.info('text_config is None. Initializing the OwlViTTextConfig with default values.' )

           if vision_config is None:
                 UpperCamelCase					       =  {}
                 logger.info('vision_config is None. initializing the OwlViTVisionConfig with default values.' )

           UpperCamelCase					       =  OwlViTTextConfig(**_SCREAMING_SNAKE_CASE )
           UpperCamelCase					       =  OwlViTVisionConfig(**_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  projection_dim
           UpperCamelCase					       =  logit_scale_init_value
           UpperCamelCase					       =  return_dict
           UpperCamelCase					       =  1.0







     @classmethod
     def   _SCREAMING_SNAKE_CASE     ( cls      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, os.PathLike]   ,						**_SCREAMING_SNAKE_CASE      :    Tuple ):






           """simple docstring"""




           cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE )

           UpperCamelCase       ,  UpperCamelCase					       =  cls.get_config_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )

           if "model_type" in config_dict and hasattr(cls   ,						'model_type' ) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                     f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.' )

           return cls.from_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )







     @classmethod
     def   _SCREAMING_SNAKE_CASE     ( cls      :    str   ,						_SCREAMING_SNAKE_CASE      :    Dict   ,						_SCREAMING_SNAKE_CASE      :    Dict   ,						**_SCREAMING_SNAKE_CASE      :    Union[str, Any] ):






           """simple docstring"""




           UpperCamelCase					       =  {}
           UpperCamelCase					       =  text_config
           UpperCamelCase					       =  vision_config

           return cls.from_dict(_SCREAMING_SNAKE_CASE   ,						**_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    List[Any] ):






           """simple docstring"""




           UpperCamelCase					       =  copy.deepcopy(self.__dict__ )
           UpperCamelCase					       =  self.text_config.to_dict()
           UpperCamelCase					       =  self.vision_config.to_dict()
           UpperCamelCase					       =  self.__class__.model_type
           return output





class 					A__     (     __snake_case ):

     '''simple docstring'''






     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[Any] ):






           """simple docstring"""




           return OrderedDict(
               [
                   ('input_ids', {0: 'batch', 1: 'sequence'}),
                   ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
                   ('attention_mask', {0: 'batch', 1: 'sequence'}),
               ] )







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    str ):






           """simple docstring"""




           return OrderedDict(
               [
                   ('logits_per_image', {0: 'batch'}),
                   ('logits_per_text', {0: 'batch'}),
                   ('text_embeds', {0: 'batch'}),
                   ('image_embeds', {0: 'batch'}),
               ] )







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           return 1E-4







     def   _SCREAMING_SNAKE_CASE     ( self      :    int   ,						_SCREAMING_SNAKE_CASE      :    "ProcessorMixin"   ,						_SCREAMING_SNAKE_CASE      :    int = -1   ,						_SCREAMING_SNAKE_CASE      :    int = -1   ,						_SCREAMING_SNAKE_CASE      :    Optional["TensorType"] = None   ,						):






           """simple docstring"""




           UpperCamelCase					       =  super().generate_dummy_inputs(
               processor.tokenizer   ,						batch_size=_SCREAMING_SNAKE_CASE   ,						seq_length=_SCREAMING_SNAKE_CASE   ,						framework=_SCREAMING_SNAKE_CASE )
           UpperCamelCase					       =  super().generate_dummy_inputs(
               processor.image_processor   ,						batch_size=_SCREAMING_SNAKE_CASE   ,						framework=_SCREAMING_SNAKE_CASE )
           return {**text_input_dict, **image_input_dict}







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           return 14











def 		lowercase__  (				_UpperCamelCase       ,							_UpperCamelCase) ->			bool:
      """simple docstring"""

      return numa ^ numa < 0


if __name__ == "__main__":
       import doctest

       doctest.testmod()



