





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


__A							:			str         =			logging.get_logger(__name__)

__A							:			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      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     __magic_name__   =			'owlvit_text_model'




     def __init__(    self				,     snake_case_=4_9408				,     snake_case_=512				,     snake_case_=2048				,     snake_case_=12				,     snake_case_=8				,     snake_case_=16				,     snake_case_="quick_gelu"				,     snake_case_=1E-5				,     snake_case_=0.0				,     snake_case_=0.02				,     snake_case_=1.0				,     snake_case_=0				,     snake_case_=4_9406				,     snake_case_=4_9407				,     **snake_case_				,     ):
         super().__init__(pad_token_id=snake_case_				,     bos_token_id=snake_case_				,     eos_token_id=snake_case_				,     **snake_case_							)

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




     @classmethod
     def        lowerCAmelCase__		(    cls				,     snake_case_				,     **snake_case_							):
         cls._set_token_in_kwargs(snake_case_							)

         _A,			_A     =							cls.get_config_dict(snake_case_				,     **snake_case_							)

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







class      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     __magic_name__   =			'owlvit_vision_model'




     def __init__(    self				,     snake_case_=768				,     snake_case_=3072				,     snake_case_=12				,     snake_case_=12				,     snake_case_=3				,     snake_case_=768				,     snake_case_=32				,     snake_case_="quick_gelu"				,     snake_case_=1E-5				,     snake_case_=0.0				,     snake_case_=0.02				,     snake_case_=1.0				,     **snake_case_				,     ):
         super().__init__(**snake_case_							)

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




     @classmethod
     def        lowerCAmelCase__		(    cls				,     snake_case_				,     **snake_case_							):
         cls._set_token_in_kwargs(snake_case_							)

         _A,			_A     =							cls.get_config_dict(snake_case_				,     **snake_case_							)

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







class      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     __magic_name__   =			'owlvit'
     __magic_name__   =			True




     def __init__(    self				,     snake_case_=None				,     snake_case_=None				,     snake_case_=512				,     snake_case_=2.6592				,     snake_case_=True				,     **snake_case_				,     ):
         super().__init__(**snake_case_							)

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

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

         _A     =							OwlViTTextConfig(**snake_case_							)
         _A     =							OwlViTVisionConfig(**snake_case_							)

         _A     =							projection_dim
         _A     =							logit_scale_init_value
         _A     =							return_dict
         _A     =							1.0




     @classmethod
     def        lowerCAmelCase__		(    cls				,     snake_case_				,     **snake_case_							):
         cls._set_token_in_kwargs(snake_case_							)

         _A,			_A     =							cls.get_config_dict(snake_case_				,     **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(snake_case_				,     **snake_case_							)




     @classmethod
     def        lowerCAmelCase__		(    cls				,     snake_case_				,     snake_case_				,     **snake_case_							):
         _A     =							{}
         _A     =							text_config
         _A     =							vision_config

         return cls.from_dict(snake_case_				,     **snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							copy.deepcopy(self.__dict__							)
         _A     =							self.text_config.to_dict()
         _A     =							self.vision_config.to_dict()
         _A     =							self.__class__.model_type
         return output







class      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     @property
     def        lowerCAmelCase__		(    self							):
         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        lowerCAmelCase__		(    self							):
         return OrderedDict(
             [
                 ('logits_per_image', {0: 'batch'}),
                 ('logits_per_text', {0: 'batch'}),
                 ('text_embeds', {0: 'batch'}),
                 ('image_embeds', {0: 'batch'}),
             ]							)




     @property
     def        lowerCAmelCase__		(    self							):
         return 1E-4




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_ = -1				,     snake_case_ = -1				,     snake_case_ = None				,     ):
         _A     =							super().generate_dummy_inputs(
             processor.tokenizer				,     batch_size=snake_case_				,     seq_length=snake_case_				,     framework=snake_case_							)
         _A     =							super().generate_dummy_inputs(
             processor.image_processor				,     batch_size=snake_case_				,     framework=snake_case_							)
         return {**text_input_dict, **image_input_dict}




     @property
     def        lowerCAmelCase__		(    self							):
         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

__A							:			List[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(       _SCREAMING_SNAKE_CASE							,     _SCREAMING_SNAKE_CASE=None				)							-> Union[str, Any]:




    """simple docstring"""




    require_version(deps[pkg]							,     _SCREAMING_SNAKE_CASE				)





