

"""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


__A						   =			logging.get_logger(__name__)

__A						   =			{
    "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     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Any         =  """owlvit_text_model"""

				def __init__(	self							:				Optional[int]     ,  UpperCamelCase__							:				Tuple=4_9_4_0_8     ,  UpperCamelCase__							:				Any=5_1_2     ,  UpperCamelCase__							:				Optional[int]=2_0_4_8     ,  UpperCamelCase__							:				Dict=1_2     ,  UpperCamelCase__							:				List[str]=8     ,  UpperCamelCase__							:				Union[str, Any]=1_6     ,  UpperCamelCase__							:				str="quick_gelu"     ,  UpperCamelCase__							:				Dict=1e-5     ,  UpperCamelCase__							:				str=0.0     ,  UpperCamelCase__							:				int=0.02     ,  UpperCamelCase__							:				List[Any]=1.0     ,  UpperCamelCase__							:				Tuple=0     ,  UpperCamelCase__							:				Optional[int]=4_9_4_0_6     ,  UpperCamelCase__							:				Optional[Any]=4_9_4_0_7     ,  **UpperCamelCase__							:				List[str]     ,  )->   Tuple:



						'''simple docstring'''


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

						__lowerCAmelCase:       Any          =			vocab_size
						__lowerCAmelCase:       List[str]          =			hidden_size
						__lowerCAmelCase:       Any          =			intermediate_size
						__lowerCAmelCase:       Tuple          =			num_hidden_layers
						__lowerCAmelCase:       List[Any]          =			num_attention_heads
						__lowerCAmelCase:       int          =			max_position_embeddings
						__lowerCAmelCase:       str          =			hidden_act
						__lowerCAmelCase:       Dict          =			layer_norm_eps
						__lowerCAmelCase:       int          =			attention_dropout
						__lowerCAmelCase:       str          =			initializer_range
						__lowerCAmelCase:       Any          =			initializer_factor




				@classmethod
				def 							lowercase_     (	cls							:				Optional[Any]     ,  UpperCamelCase__							:				Union[str, os.PathLike]     ,  **UpperCamelCase__							:				List[str])->   "PretrainedConfig":



						'''simple docstring'''


						cls._set_token_in_kwargs(UpperCamelCase__)

						__lowerCAmelCase      , __lowerCAmelCase:       int          =			cls.get_config_dict(UpperCamelCase__     ,  **UpperCamelCase__)

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





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Dict         =  """owlvit_vision_model"""

				def __init__(	self							:				Any     ,  UpperCamelCase__							:				str=7_6_8     ,  UpperCamelCase__							:				Tuple=3_0_7_2     ,  UpperCamelCase__							:				int=1_2     ,  UpperCamelCase__							:				str=1_2     ,  UpperCamelCase__							:				Union[str, Any]=3     ,  UpperCamelCase__							:				List[Any]=7_6_8     ,  UpperCamelCase__							:				Any=3_2     ,  UpperCamelCase__							:				List[str]="quick_gelu"     ,  UpperCamelCase__							:				Tuple=1e-5     ,  UpperCamelCase__							:				Optional[Any]=0.0     ,  UpperCamelCase__							:				int=0.02     ,  UpperCamelCase__							:				List[str]=1.0     ,  **UpperCamelCase__							:				List[str]     ,  )->   Tuple:



						'''simple docstring'''


						super().__init__(**UpperCamelCase__)

						__lowerCAmelCase:       Optional[Any]          =			hidden_size
						__lowerCAmelCase:       int          =			intermediate_size
						__lowerCAmelCase:       Tuple          =			num_hidden_layers
						__lowerCAmelCase:       Tuple          =			num_attention_heads
						__lowerCAmelCase:       str          =			num_channels
						__lowerCAmelCase:       int          =			image_size
						__lowerCAmelCase:       List[Any]          =			patch_size
						__lowerCAmelCase:       Tuple          =			hidden_act
						__lowerCAmelCase:       List[str]          =			layer_norm_eps
						__lowerCAmelCase:       Tuple          =			attention_dropout
						__lowerCAmelCase:       int          =			initializer_range
						__lowerCAmelCase:       str          =			initializer_factor




				@classmethod
				def 							lowercase_     (	cls							:				Tuple     ,  UpperCamelCase__							:				Union[str, os.PathLike]     ,  **UpperCamelCase__							:				List[str])->   "PretrainedConfig":



						'''simple docstring'''


						cls._set_token_in_kwargs(UpperCamelCase__)

						__lowerCAmelCase      , __lowerCAmelCase:       List[Any]          =			cls.get_config_dict(UpperCamelCase__     ,  **UpperCamelCase__)

						# get the vision config dict if we are loading from OwlViTConfig
						if config_dict.get("model_type") == "owlvit":
								__lowerCAmelCase:       Optional[Any]          =			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(UpperCamelCase__     ,  **UpperCamelCase__)





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Dict         =  """owlvit"""
				SCREAMING_SNAKE_CASE_   :      List[str]         =  True

				def __init__(	self							:				Union[str, Any]     ,  UpperCamelCase__							:				Any=None     ,  UpperCamelCase__							:				Any=None     ,  UpperCamelCase__							:				List[Any]=5_1_2     ,  UpperCamelCase__							:				Optional[int]=2.6592     ,  UpperCamelCase__							:				Tuple=True     ,  **UpperCamelCase__							:				Union[str, Any]     ,  )->   int:



						'''simple docstring'''


						super().__init__(**UpperCamelCase__)

						if text_config is None:
								__lowerCAmelCase:       int          =			{}
								logger.info("text_config is None. Initializing the OwlViTTextConfig with default values.")

						if vision_config is None:
								__lowerCAmelCase:       Tuple          =			{}
								logger.info("vision_config is None. initializing the OwlViTVisionConfig with default values.")

						__lowerCAmelCase:       Union[str, Any]          =			OwlViTTextConfig(**UpperCamelCase__)
						__lowerCAmelCase:       List[Any]          =			OwlViTVisionConfig(**UpperCamelCase__)

						__lowerCAmelCase:       Any          =			projection_dim
						__lowerCAmelCase:       Union[str, Any]          =			logit_scale_init_value
						__lowerCAmelCase:       Optional[int]          =			return_dict
						__lowerCAmelCase:       List[Any]          =			1.0

				@classmethod
				def 							lowercase_     (	cls							:				Optional[Any]     ,  UpperCamelCase__							:				Union[str, os.PathLike]     ,  **UpperCamelCase__							:				List[str])->   "PretrainedConfig":



						'''simple docstring'''


						cls._set_token_in_kwargs(UpperCamelCase__)

						__lowerCAmelCase      , __lowerCAmelCase:       List[str]          =			cls.get_config_dict(UpperCamelCase__     ,  **UpperCamelCase__)

						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(UpperCamelCase__     ,  **UpperCamelCase__)

				@classmethod
				def 							lowercase_     (	cls							:				List[Any]     ,  UpperCamelCase__							:				Dict     ,  UpperCamelCase__							:				Dict     ,  **UpperCamelCase__							:				Any)->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			{}
						__lowerCAmelCase:       List[Any]          =			text_config
						__lowerCAmelCase:       Union[str, Any]          =			vision_config

						return cls.from_dict(UpperCamelCase__     ,  **UpperCamelCase__)




				def 							lowercase_     (	self							:				Union[str, Any])->   Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase:       Any          =			copy.deepcopy(self.__dict__)
						__lowerCAmelCase:       Any          =			self.text_config.to_dict()
						__lowerCAmelCase:       Tuple          =			self.vision_config.to_dict()
						__lowerCAmelCase:       str          =			self.__class__.model_type
						return output





class     snake_case	(				__snake_case  ):

				@property
				def 							lowercase_     (	self							:				int)->   Mapping[str, Mapping[int, str]]:



						'''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 							lowercase_     (	self							:				List[Any])->   Mapping[str, Mapping[int, 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 							lowercase_     (	self							:				Any)->   float:



						'''simple docstring'''


						return 1e-4

				def 							lowercase_     (	self							:				Any     ,  UpperCamelCase__							:				"ProcessorMixin"     ,  UpperCamelCase__							:				int = -1     ,  UpperCamelCase__							:				int = -1     ,  UpperCamelCase__							:				Optional["TensorType"] = None     ,  )->   Mapping[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			super().generate_dummy_inputs(
						    processor.tokenizer     ,  batch_size=UpperCamelCase__     ,  seq_length=UpperCamelCase__     ,  framework=UpperCamelCase__)
						__lowerCAmelCase:       str          =			super().generate_dummy_inputs(
						    processor.image_processor     ,  batch_size=UpperCamelCase__     ,  framework=UpperCamelCase__)
						return {**text_input_dict, **image_input_dict}




				@property
				def 							lowercase_     (	self							:				List[Any])->   int:



						'''simple docstring'''


						return 1_4





"""simple docstring"""


from numpy import exp, pi, sqrt






def     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE = 0.0					, __SCREAMING_SNAKE_CASE = 1.0 )	->	int:
		return 1 / sqrt(2 * pi * sigma**2 ) * exp(-((x - mu) ** 2) / (2 * sigma**2) )


if __name__ == "__main__":
			import doctest

			doctest.testmod()


