



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


__snake_case    :		Any  =logging.get_logger(__name__)

__snake_case    :		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__      (							lowerCamelCase__):




		'''simple docstring'''



		snake_case_     ="""owlvit_text_model"""



		def __init__(self		,__lowerCamelCase=4_94_08		,__lowerCamelCase=5_12		,__lowerCamelCase=20_48		,__lowerCamelCase=12		,__lowerCamelCase=8		,__lowerCamelCase=16		,__lowerCamelCase="quick_gelu"		,__lowerCamelCase=1e-5		,__lowerCamelCase=0.0		,__lowerCamelCase=0.02		,__lowerCamelCase=1.0		,__lowerCamelCase=0		,__lowerCamelCase=4_94_06		,__lowerCamelCase=4_94_07		,**__lowerCamelCase		,)					->      List[str]:

						"""simple docstring"""






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

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



		@classmethod
		def 		lowerCAmelCase__				(cls		,__lowerCamelCase		,**__lowerCamelCase			)					->      "PretrainedConfig":

						"""simple docstring"""






						cls._set_token_in_kwargs(__lowerCamelCase			)

						lowerCAmelCase__					:    List[str]												=					cls.get_config_dict(__lowerCamelCase		,**__lowerCamelCase			)

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




		'''simple docstring'''



		snake_case_     ="""owlvit_vision_model"""



		def __init__(self		,__lowerCamelCase=7_68		,__lowerCamelCase=30_72		,__lowerCamelCase=12		,__lowerCamelCase=12		,__lowerCamelCase=3		,__lowerCamelCase=7_68		,__lowerCamelCase=32		,__lowerCamelCase="quick_gelu"		,__lowerCamelCase=1e-5		,__lowerCamelCase=0.0		,__lowerCamelCase=0.02		,__lowerCamelCase=1.0		,**__lowerCamelCase		,)					->      List[str]:

						"""simple docstring"""






						super().__init__(**__lowerCamelCase			)

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



		@classmethod
		def 		lowerCAmelCase__				(cls		,__lowerCamelCase		,**__lowerCamelCase			)					->      "PretrainedConfig":

						"""simple docstring"""






						cls._set_token_in_kwargs(__lowerCamelCase			)

						lowerCAmelCase__					:    Optional[Any]												=					cls.get_config_dict(__lowerCamelCase		,**__lowerCamelCase			)

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




		'''simple docstring'''



		snake_case_     ="""owlvit"""
		snake_case_     =True



		def __init__(self		,__lowerCamelCase=None		,__lowerCamelCase=None		,__lowerCamelCase=5_12		,__lowerCamelCase=2.6592		,__lowerCamelCase=True		,**__lowerCamelCase		,)					->      str:

						"""simple docstring"""






						super().__init__(**__lowerCamelCase			)

						if text_config is None:
										lowerCAmelCase__					:    List[Any]												=					{}
										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__					:    List[str]												=					OwlViTTextConfig(**__lowerCamelCase			)
						lowerCAmelCase__					:    Tuple												=					OwlViTVisionConfig(**__lowerCamelCase			)

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



		@classmethod
		def 		lowerCAmelCase__				(cls		,__lowerCamelCase		,**__lowerCamelCase			)					->      "PretrainedConfig":

						"""simple docstring"""






						cls._set_token_in_kwargs(__lowerCamelCase			)

						lowerCAmelCase__					:    Tuple												=					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 		lowerCAmelCase__				(cls		,__lowerCamelCase		,__lowerCamelCase		,**__lowerCamelCase			)					->      str:

						"""simple docstring"""






						lowerCAmelCase__					:    str												=					{}
						lowerCAmelCase__					:    List[str]												=					text_config
						lowerCAmelCase__					:    Optional[int]												=					vision_config

						return cls.from_dict(__lowerCamelCase		,**__lowerCamelCase			)



		def 		lowerCAmelCase__				(self			)					->      Optional[int]:

						"""simple docstring"""






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



class 	lowerCamelCase__      (							lowerCamelCase__):




		'''simple docstring'''



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

						"""simple docstring"""






						return 1e-4



		def 		lowerCAmelCase__				(self		,__lowerCamelCase		,__lowerCamelCase = -1		,__lowerCamelCase = -1		,__lowerCamelCase = None		,)					->      Mapping[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Optional[int]												=					super().generate_dummy_inputs(
						    processor.tokenizer		,batch_size=__lowerCamelCase		,seq_length=__lowerCamelCase		,framework=__lowerCamelCase			)
						lowerCAmelCase__					:    List[str]												=					super().generate_dummy_inputs(
						    processor.image_processor		,batch_size=__lowerCamelCase		,framework=__lowerCamelCase			)
						return {**text_input_dict, **image_input_dict}



		@property
		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						return 14






def      lowerCAmelCase__		(   lowerCamelCase_		:		str = "The quick brown fox jumps over the lazy dog"	,):





				'''simple docstring'''

				lowerCAmelCase__					:    Any												=					set()

				# Replace all the whitespace in our sentence
				lowerCAmelCase__					:    List[Any]												=					input_str.replace(''' '''	,'''''')
				for alpha in input_str:
								if "a" <= alpha.lower() <= "z":
												frequency.add(alpha.lower())
				return len(lowerCamelCase_) == 26






def      lowerCAmelCase__		(   lowerCamelCase_		:		str = "The quick brown fox jumps over the lazy dog"	,):





				'''simple docstring'''

				lowerCAmelCase__					:    List[str]												=					[False] * 26
				for char in input_str:
								if char.islower():
												lowerCAmelCase__					:    Union[str, Any]												=					True
								elif char.isupper():
												lowerCAmelCase__					:    str												=					True
				return all(lowerCamelCase_)






def      lowerCAmelCase__		(   lowerCamelCase_		:		str = "The quick brown fox jumps over the lazy dog"	,):





				'''simple docstring'''

				return len({char for char in input_str.lower() if char.isalpha()}) == 26






def      lowerCAmelCase__		(   ):





				'''simple docstring'''

				from timeit import timeit

				lowerCAmelCase__					:    Optional[Any]												=					'''from __main__ import is_pangram, is_pangram_faster, is_pangram_fastest'''
				print(timeit('''is_pangram()'''	,setup=lowerCamelCase_))
				print(timeit('''is_pangram_faster()'''	,setup=lowerCamelCase_))
				print(timeit('''is_pangram_fastest()'''	,setup=lowerCamelCase_))
				# 5.348480500048026, 2.6477354579837993, 1.8470395830227062
				# 5.036091582966037, 2.644472333951853,  1.8869528750656173


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							benchmark()

