






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(       __lowerCamelCase		):
		__SCREAMING_SNAKE_CASE  :       Union[str, Any]							=							'''owlvit_text_model'''

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



					'''simple docstring'''



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

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



		@classmethod
		def    __lowerCAmelCase  (					cls		:    int    ,       SCREAMING_SNAKE_CASE__		:    Union[str, os.PathLike]    ,       **SCREAMING_SNAKE_CASE__		:    Any    ):



					'''simple docstring'''



					cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE__    )

					__a						,					__a						:  Dict									=     cls.get_config_dict(SCREAMING_SNAKE_CASE__    ,       **SCREAMING_SNAKE_CASE__    )

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






class 			_UpperCamelCase(       __lowerCamelCase		):
		__SCREAMING_SNAKE_CASE  :       str							=							'''owlvit_vision_model'''

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



					'''simple docstring'''



					super().__init__(**SCREAMING_SNAKE_CASE__    )

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



		@classmethod
		def    __lowerCAmelCase  (					cls		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, os.PathLike]    ,       **SCREAMING_SNAKE_CASE__		:    Dict    ):



					'''simple docstring'''



					cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE__    )

					__a						,					__a						:  int									=     cls.get_config_dict(SCREAMING_SNAKE_CASE__    ,       **SCREAMING_SNAKE_CASE__    )

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






class 			_UpperCamelCase(       __lowerCamelCase		):
		__SCREAMING_SNAKE_CASE  :       Any							=							'''owlvit'''
		__SCREAMING_SNAKE_CASE  :       str							=							True

		def __init__(					self		:    str    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=None    ,       SCREAMING_SNAKE_CASE__		:    List[str]=None    ,       SCREAMING_SNAKE_CASE__		:    Any=5_1_2    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=2.6_592    ,       SCREAMING_SNAKE_CASE__		:    Dict=True    ,       **SCREAMING_SNAKE_CASE__		:    str    ,       ):



					'''simple docstring'''



					super().__init__(**SCREAMING_SNAKE_CASE__    )

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

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

					__a						:  int									=     OwlViTTextConfig(**SCREAMING_SNAKE_CASE__    )
					__a						:  str									=     OwlViTVisionConfig(**SCREAMING_SNAKE_CASE__    )

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

		@classmethod
		def    __lowerCAmelCase  (					cls		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Union[str, os.PathLike]    ,       **SCREAMING_SNAKE_CASE__		:    Tuple    ):



					'''simple docstring'''



					cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE__    )

					__a						,					__a						:  int									=     cls.get_config_dict(SCREAMING_SNAKE_CASE__    ,       **SCREAMING_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(SCREAMING_SNAKE_CASE__    ,       **SCREAMING_SNAKE_CASE__    )

		@classmethod
		def    __lowerCAmelCase  (					cls		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       **SCREAMING_SNAKE_CASE__		:    Optional[int]    ):



					'''simple docstring'''



					__a						:  Union[str, Any]									=     {}
					__a						:  List[str]									=     text_config
					__a						:  Tuple									=     vision_config

					return cls.from_dict(SCREAMING_SNAKE_CASE__    ,       **SCREAMING_SNAKE_CASE__    )



		def    __lowerCAmelCase  (					self		:    Optional[int]    ):



					'''simple docstring'''



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






class 			_UpperCamelCase(       __lowerCamelCase		):

		@property
		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''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		:    Dict    ):



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



					'''simple docstring'''



					return 1e-4

		def    __lowerCAmelCase  (					self		:    Optional[int]    ,       SCREAMING_SNAKE_CASE__		:    "ProcessorMixin"    ,       SCREAMING_SNAKE_CASE__		:    int = -1    ,       SCREAMING_SNAKE_CASE__		:    int = -1    ,       SCREAMING_SNAKE_CASE__		:    Optional["TensorType"] = None    ,       ):



					'''simple docstring'''



					__a						:  Tuple									=     super().generate_dummy_inputs(
					    processor.tokenizer    ,       batch_size=SCREAMING_SNAKE_CASE__    ,       seq_length=SCREAMING_SNAKE_CASE__    ,       framework=SCREAMING_SNAKE_CASE__    )
					__a						:  Dict									=     super().generate_dummy_inputs(
					    processor.image_processor    ,       batch_size=SCREAMING_SNAKE_CASE__    ,       framework=SCREAMING_SNAKE_CASE__    )
					return {**text_input_dict, **image_input_dict}



		@property
		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					return 1_4












def      A__       (    SCREAMING_SNAKE_CASE_   :      int				,	SCREAMING_SNAKE_CASE_   :      int						)  ->  str:






   """simple docstring"""







   if a < 0 or b < 0:
      raise ValueError('''the value of both inputs must be positive'''						)

   _UpperCAmelCase           =   str(bin(SCREAMING_SNAKE_CASE_						)						)[2:]  # remove the leading "0b"
   _UpperCAmelCase           =   str(bin(SCREAMING_SNAKE_CASE_						)						)[2:]  # remove the leading "0b"

   _UpperCAmelCase           =   max(len(SCREAMING_SNAKE_CASE_						)				,	len(SCREAMING_SNAKE_CASE_						)						)

   return "0b" + "".join(
       str(int(char_a == '''1''' and char_b == '''1'''						)						)
       for char_a, char_b in zip(a_binary.zfill(SCREAMING_SNAKE_CASE_						)				,	b_binary.zfill(SCREAMING_SNAKE_CASE_						)						)						)


if __name__ == "__main__":
   import doctest

   doctest.testmod()