"""simple docstring"""







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


__SCREAMING_SNAKE_CASE    	=logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE    	={
    '''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        UpperCamelCase		(			_snake_case  ):
   lowercase							=  'owlvit_text_model'
   def __init__(			self     ,__UpperCamelCase=4_9408     ,__UpperCamelCase=512     ,__UpperCamelCase=2048     ,__UpperCamelCase=12     ,__UpperCamelCase=8     ,__UpperCamelCase=16     ,__UpperCamelCase="quick_gelu"     ,__UpperCamelCase=1e-5     ,__UpperCamelCase=0.0     ,__UpperCamelCase=0.02     ,__UpperCamelCase=1.0     ,__UpperCamelCase=0     ,__UpperCamelCase=4_9406     ,__UpperCamelCase=4_9407     ,**__UpperCamelCase     ,)	->      List[str]:


        '''simple docstring'''


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

        lowercase_	:				Tuple													=	vocab_size
        lowercase_	:				Optional[Any]													=	hidden_size
        lowercase_	:				Dict													=	intermediate_size
        lowercase_	:				str													=	num_hidden_layers
        lowercase_	:				Optional[int]													=	num_attention_heads
        lowercase_	:				Union[str, Any]													=	max_position_embeddings
        lowercase_	:				Any													=	hidden_act
        lowercase_	:				Tuple													=	layer_norm_eps
        lowercase_	:				str													=	attention_dropout
        lowercase_	:				Union[str, Any]													=	initializer_range
        lowercase_	:				Union[str, Any]													=	initializer_factor







   @classmethod
   def 			_UpperCAmelCase   (			cls     ,__UpperCamelCase     ,**__UpperCamelCase			)	->      Any:


        '''simple docstring'''


        cls._set_token_in_kwargs(_lowerCamelCase			)

        lowercase_	:				Optional[Any]													=	cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase			)

        # get the text config dict if we are loading from OwlViTConfig
        if config_dict.get('model_type'			) == "owlvit":
             lowercase_	:				Tuple													=	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(_lowerCamelCase     ,**_lowerCamelCase			)







class        UpperCamelCase		(			_snake_case  ):
   lowercase							=  'owlvit_vision_model'
   def __init__(			self     ,__UpperCamelCase=768     ,__UpperCamelCase=3072     ,__UpperCamelCase=12     ,__UpperCamelCase=12     ,__UpperCamelCase=3     ,__UpperCamelCase=768     ,__UpperCamelCase=32     ,__UpperCamelCase="quick_gelu"     ,__UpperCamelCase=1e-5     ,__UpperCamelCase=0.0     ,__UpperCamelCase=0.02     ,__UpperCamelCase=1.0     ,**__UpperCamelCase     ,)	->      Tuple:


        '''simple docstring'''


        super().__init__(**_lowerCamelCase			)

        lowercase_	:				Tuple													=	hidden_size
        lowercase_	:				Any													=	intermediate_size
        lowercase_	:				int													=	num_hidden_layers
        lowercase_	:				Union[str, Any]													=	num_attention_heads
        lowercase_	:				Optional[Any]													=	num_channels
        lowercase_	:				Tuple													=	image_size
        lowercase_	:				Any													=	patch_size
        lowercase_	:				Any													=	hidden_act
        lowercase_	:				Dict													=	layer_norm_eps
        lowercase_	:				int													=	attention_dropout
        lowercase_	:				Tuple													=	initializer_range
        lowercase_	:				Any													=	initializer_factor







   @classmethod
   def 			_UpperCAmelCase   (			cls     ,__UpperCamelCase     ,**__UpperCamelCase			)	->      List[Any]:


        '''simple docstring'''


        cls._set_token_in_kwargs(_lowerCamelCase			)

        lowercase_	:				List[str]													=	cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase			)

        # get the vision config dict if we are loading from OwlViTConfig
        if config_dict.get('model_type'			) == "owlvit":
             lowercase_	:				Tuple													=	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(_lowerCamelCase     ,**_lowerCamelCase			)







class        UpperCamelCase		(			_snake_case  ):
   lowercase							=  'owlvit'
   lowercase							=  True
   def __init__(			self     ,__UpperCamelCase=None     ,__UpperCamelCase=None     ,__UpperCamelCase=512     ,__UpperCamelCase=2.6592     ,__UpperCamelCase=True     ,**__UpperCamelCase     ,)	->      Optional[Any]:


        '''simple docstring'''


        super().__init__(**_lowerCamelCase			)

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

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

        lowercase_	:				Union[str, Any]													=	OwlViTTextConfig(**_lowerCamelCase			)
        lowercase_	:				List[Any]													=	OwlViTVisionConfig(**_lowerCamelCase			)

        lowercase_	:				List[Any]													=	projection_dim
        lowercase_	:				Union[str, Any]													=	logit_scale_init_value
        lowercase_	:				List[str]													=	return_dict
        lowercase_	:				Dict													=	1.0
   @classmethod
   def 			_UpperCAmelCase   (			cls     ,__UpperCamelCase     ,**__UpperCamelCase			)	->      Optional[Any]:


        '''simple docstring'''


        cls._set_token_in_kwargs(_lowerCamelCase			)

        lowercase_	:				int													=	cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase			)

        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(_lowerCamelCase     ,**_lowerCamelCase			)
   @classmethod
   def 			_UpperCAmelCase   (			cls     ,__UpperCamelCase     ,__UpperCamelCase     ,**__UpperCamelCase			)	->      Union[str, Any]:


        '''simple docstring'''


        lowercase_	:				Any													=	{}
        lowercase_	:				Union[str, Any]													=	text_config
        lowercase_	:				Dict													=	vision_config

        return cls.from_dict(_lowerCamelCase     ,**_lowerCamelCase			)







   def 			_UpperCAmelCase   (			self			)	->      str:


        '''simple docstring'''


        lowercase_	:				List[Any]													=	copy.deepcopy(self.__dict__			)
        lowercase_	:				Tuple													=	self.text_config.to_dict()
        lowercase_	:				str													=	self.vision_config.to_dict()
        lowercase_	:				Dict													=	self.__class__.model_type
        return output







class        UpperCamelCase		(			_snake_case  ):
   @property
   def 			_UpperCAmelCase   (			self			)	->      Optional[int]:


        '''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 			_UpperCAmelCase   (			self			)	->      Optional[int]:


        '''simple docstring'''


        return OrderedDict(
            [
                ('logits_per_image', {0: 'batch'}),
                ('logits_per_text', {0: 'batch'}),
                ('text_embeds', {0: 'batch'}),
                ('image_embeds', {0: 'batch'}),
            ]			)
   @property
   def 			_UpperCAmelCase   (			self			)	->      Optional[int]:


        '''simple docstring'''


        return 1e-4
   def 			_UpperCAmelCase   (			self     ,__UpperCamelCase     ,__UpperCamelCase = -1     ,__UpperCamelCase = -1     ,__UpperCamelCase = None     ,)	->      str:


        '''simple docstring'''


        lowercase_	:				List[str]													=	super().generate_dummy_inputs(
            processor.tokenizer     ,batch_size=_lowerCamelCase     ,seq_length=_lowerCamelCase     ,framework=_lowerCamelCase			)
        lowercase_	:				Tuple													=	super().generate_dummy_inputs(
            processor.image_processor     ,batch_size=_lowerCamelCase     ,framework=_lowerCamelCase			)
        return {**text_input_dict, **image_input_dict}







   @property
   def 			_UpperCAmelCase   (			self			)	->      Tuple:


        '''simple docstring'''


        return 14





import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

snake_case				:    Union[str, Any]       				=     '''python tqdm regex requests packaging filelock numpy tokenizers'''.split()
if sys.version_info < (3, 7):
     pkgs_to_check_at_runtime.append('''dataclasses''')
if sys.version_info < (3, 8):
     pkgs_to_check_at_runtime.append('''importlib_metadata''')

for pkg in pkgs_to_check_at_runtime:
     if pkg in deps:
          if pkg == "tokenizers":
               # must be loaded here, or else tqdm check may fail
               from .utils import is_tokenizers_available

               if not is_tokenizers_available():
                    continue  # not required, check version only if installed

          require_version_core(deps[pkg])
     else:
          raise ValueError(F"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")
def 				__lowerCamelCase						( UpperCAmelCase_						:		Any ,  UpperCAmelCase_						:		Optional[int]=None						):




      """simple docstring"""





      require_version(deps[pkg] ,  UpperCAmelCase_						)





