



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


lowerCAmelCase_  :							Tuple             =    logging.get_logger(__name__)

lowerCAmelCase_  :							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_      ):
						_lowerCAmelCase  : Dict						  =					'owlvit_text_model'







						def __init__(	self :   int					,     lowerCAmelCase__ :   Union[str, Any]=4_94_08					,     lowerCAmelCase__ :   int=5_12					,     lowerCAmelCase__ :   Union[str, Any]=20_48					,     lowerCAmelCase__ :   Optional[int]=12					,     lowerCAmelCase__ :   List[Any]=8					,     lowerCAmelCase__ :   str=16					,     lowerCAmelCase__ :   str="quick_gelu"					,     lowerCAmelCase__ :   Dict=1e-5					,     lowerCAmelCase__ :   int=0.0					,     lowerCAmelCase__ :   Optional[Any]=0.02					,     lowerCAmelCase__ :   Tuple=1.0					,     lowerCAmelCase__ :   Any=0					,     lowerCAmelCase__ :   Union[str, Any]=4_94_06					,     lowerCAmelCase__ :   Optional[Any]=4_94_07					,     **lowerCAmelCase__ :   int					,     ):

													"""simple docstring"""
													super().__init__(pad_token_id=lowerCAmelCase__					,     bos_token_id=lowerCAmelCase__					,     eos_token_id=lowerCAmelCase__					,     **lowerCAmelCase__					)

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







						@classmethod
						def        __lowercase     (	cls :   Optional[int]					,     lowerCAmelCase__ :   Union[str, os.PathLike]					,     **lowerCAmelCase__ :   Union[str, Any]					):

													"""simple docstring"""
													cls._set_token_in_kwargs(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       ,SCREAMING_SNAKE_CASE       :   Optional[int]         =      cls.get_config_dict(lowerCAmelCase__					,     **lowerCAmelCase__					)

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


class 						lowerCamelCase_				(       snake_case_      ):
						_lowerCAmelCase  : Any						  =					'owlvit_vision_model'







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

													"""simple docstring"""
													super().__init__(**lowerCAmelCase__					)

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







						@classmethod
						def        __lowercase     (	cls :   int					,     lowerCAmelCase__ :   Union[str, os.PathLike]					,     **lowerCAmelCase__ :   Tuple					):

													"""simple docstring"""
													cls._set_token_in_kwargs(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       ,SCREAMING_SNAKE_CASE       :   Dict         =      cls.get_config_dict(lowerCAmelCase__					,     **lowerCAmelCase__					)

													# get the vision config dict if we are loading from OwlViTConfig
													if config_dict.get('''model_type'''					) == "owlvit":
																				SCREAMING_SNAKE_CASE       :   str         =      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_				(       snake_case_      ):
						_lowerCAmelCase  : Union[str, Any]						  =					'owlvit'
						_lowerCAmelCase  : Any						  =					True







						def __init__(	self :   str					,     lowerCAmelCase__ :   int=None					,     lowerCAmelCase__ :   List[str]=None					,     lowerCAmelCase__ :   int=5_12					,     lowerCAmelCase__ :   Union[str, Any]=2.6592					,     lowerCAmelCase__ :   int=True					,     **lowerCAmelCase__ :   int					,     ):

													"""simple docstring"""
													super().__init__(**lowerCAmelCase__					)

													if text_config is None:
																				SCREAMING_SNAKE_CASE       :   Optional[int]         =      {}
																				logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.'''					)

													if vision_config is None:
																				SCREAMING_SNAKE_CASE       :   List[Any]         =      {}
																				logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.'''					)

													SCREAMING_SNAKE_CASE       :   Tuple         =      OwlViTTextConfig(**lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Tuple         =      OwlViTVisionConfig(**lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   List[Any]         =      projection_dim
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      logit_scale_init_value
													SCREAMING_SNAKE_CASE       :   Dict         =      return_dict
													SCREAMING_SNAKE_CASE       :   List[Any]         =      1.0







						@classmethod
						def        __lowercase     (	cls :   Optional[Any]					,     lowerCAmelCase__ :   Union[str, os.PathLike]					,     **lowerCAmelCase__ :   int					):

													"""simple docstring"""
													cls._set_token_in_kwargs(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       ,SCREAMING_SNAKE_CASE       :   str         =      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        __lowercase     (	cls :   int					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   Dict					,     **lowerCAmelCase__ :   Tuple					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   List[Any]         =      {}
													SCREAMING_SNAKE_CASE       :   List[Any]         =      text_config
													SCREAMING_SNAKE_CASE       :   List[str]         =      vision_config

													return cls.from_dict(lowerCAmelCase__					,     **lowerCAmelCase__					)







						def        __lowercase     (	self :   Any					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   List[str]         =      copy.deepcopy(self.__dict__					)
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      self.text_config.to_dict()
													SCREAMING_SNAKE_CASE       :   int         =      self.vision_config.to_dict()
													SCREAMING_SNAKE_CASE       :   str         =      self.__class__.model_type
													return output


class 						lowerCamelCase_				(       snake_case_      ):







						@property
						def        __lowercase     (	self :   Dict					):

													"""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 :   Any					):

													"""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 :   str					):

													"""simple docstring"""
													return 1e-4







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

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Any         =      super().generate_dummy_inputs(
													    processor.tokenizer					,     batch_size=lowerCAmelCase__					,     seq_length=lowerCAmelCase__					,     framework=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   List[str]         =      super().generate_dummy_inputs(
													    processor.image_processor					,     batch_size=lowerCAmelCase__					,     framework=lowerCAmelCase__					)
													return {**text_input_dict, **image_input_dict}







						@property
						def        __lowercase     (	self :   Optional[int]					):

													"""simple docstring"""
													return 14









'''simple docstring'''



def        UpperCAmelCase (    A	:					int					):
							if not isinstance(A       ,		A					):
														SCREAMING_SNAKE_CASE       :   List[str]         =      F"""Input value of [number={number}] must be an integer"""
														raise TypeError(A					)
							if number < 0:
														return False
							SCREAMING_SNAKE_CASE       :   List[str]         =      number * number
							while number > 0:
														if number % 10 != number_square % 10:
																					return False
														number //= 10
														number_square //= 10
							return True


if __name__ == "__main__":
							import doctest

							doctest.testmod()




