


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					:		Dict            =						{
    """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__			(    _UpperCAmelCase					):
       _lowerCAmelCase   ='owlvit_text_model'




       def __init__( self				:    str    ,				_lowerCamelCase				:    List[Any]=4_9_4_0_8    ,				_lowerCamelCase				:    Union[str, Any]=5_1_2    ,				_lowerCamelCase				:    Dict=2_0_4_8    ,				_lowerCamelCase				:    Dict=1_2    ,				_lowerCamelCase				:    Tuple=8    ,				_lowerCamelCase				:    Dict=1_6    ,				_lowerCamelCase				:    Any="quick_gelu"    ,				_lowerCamelCase				:    Any=1E-5    ,				_lowerCamelCase				:    Union[str, Any]=0.0    ,				_lowerCamelCase				:    Tuple=0.02    ,				_lowerCamelCase				:    str=1.0    ,				_lowerCamelCase				:    str=0    ,				_lowerCamelCase				:    List[str]=4_9_4_0_6    ,				_lowerCamelCase				:    Dict=4_9_4_0_7    ,				**_lowerCamelCase				:    List[Any]    ,				):
              super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_    ,				bos_token_id=SCREAMING_SNAKE_CASE_    ,				eos_token_id=SCREAMING_SNAKE_CASE_    ,				**SCREAMING_SNAKE_CASE_			)

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




       @classmethod
       def     UpperCAmelCase__    ( cls				:    List[Any]    ,				_lowerCamelCase				:    int    ,				**_lowerCamelCase				:    Union[str, Any]			):
              cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_			)

              snake_case__ :       Any	   =							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":
                     snake_case__ :       str	   =							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 snake_case__			(    _UpperCAmelCase					):
       _lowerCAmelCase   ='owlvit_vision_model'




       def __init__( self				:    int    ,				_lowerCamelCase				:    Any=7_6_8    ,				_lowerCamelCase				:    Union[str, Any]=3_0_7_2    ,				_lowerCamelCase				:    Union[str, Any]=1_2    ,				_lowerCamelCase				:    List[Any]=1_2    ,				_lowerCamelCase				:    Optional[Any]=3    ,				_lowerCamelCase				:    Dict=7_6_8    ,				_lowerCamelCase				:    List[Any]=3_2    ,				_lowerCamelCase				:    List[Any]="quick_gelu"    ,				_lowerCamelCase				:    Dict=1E-5    ,				_lowerCamelCase				:    str=0.0    ,				_lowerCamelCase				:    List[str]=0.02    ,				_lowerCamelCase				:    str=1.0    ,				**_lowerCamelCase				:    Optional[int]    ,				):
              super().__init__(**SCREAMING_SNAKE_CASE_			)

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




       @classmethod
       def     UpperCAmelCase__    ( cls				:    Any    ,				_lowerCamelCase				:    Optional[Any]    ,				**_lowerCamelCase				:    Optional[Any]			):
              cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_			)

              snake_case__ :       Optional[Any]	   =							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":
                     snake_case__ :       Tuple	   =							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 snake_case__			(    _UpperCAmelCase					):
       _lowerCAmelCase   ='owlvit'
       _lowerCAmelCase   =True




       def __init__( self				:    List[Any]    ,				_lowerCamelCase				:    int=None    ,				_lowerCamelCase				:    Tuple=None    ,				_lowerCamelCase				:    str=5_1_2    ,				_lowerCamelCase				:    Tuple=2.6592    ,				_lowerCamelCase				:    Tuple=True    ,				**_lowerCamelCase				:    Union[str, Any]    ,				):
              super().__init__(**SCREAMING_SNAKE_CASE_			)

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

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

              snake_case__ :       List[str]	   =							OwlViTTextConfig(**SCREAMING_SNAKE_CASE_			)
              snake_case__ :       List[Any]	   =							OwlViTVisionConfig(**SCREAMING_SNAKE_CASE_			)

              snake_case__ :       Any	   =							projection_dim
              snake_case__ :       List[str]	   =							logit_scale_init_value
              snake_case__ :       List[Any]	   =							return_dict
              snake_case__ :       str	   =							1.0




       @classmethod
       def     UpperCAmelCase__    ( cls				:    Any    ,				_lowerCamelCase				:    Optional[int]    ,				**_lowerCamelCase				:    List[Any]			):
              cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_			)

              snake_case__ :       str	   =							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     UpperCAmelCase__    ( cls				:    Union[str, Any]    ,				_lowerCamelCase				:    Any    ,				_lowerCamelCase				:    Union[str, Any]    ,				**_lowerCamelCase				:    Optional[Any]			):
              snake_case__ :       Tuple	   =							{}
              snake_case__ :       Optional[int]	   =							text_config
              snake_case__ :       Dict	   =							vision_config

              return cls.from_dict(SCREAMING_SNAKE_CASE_    ,				**SCREAMING_SNAKE_CASE_			)




       def     UpperCAmelCase__    ( self				:    Optional[int]			):
              snake_case__ :       int	   =							copy.deepcopy(self.__dict__			)
              snake_case__ :       Optional[Any]	   =							self.text_config.to_dict()
              snake_case__ :       Any	   =							self.vision_config.to_dict()
              snake_case__ :       str	   =							self.__class__.model_type
              return output


class snake_case__			(    _UpperCAmelCase					):




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




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




       def     UpperCAmelCase__    ( self				:    Dict    ,				_lowerCamelCase				:    Dict    ,				_lowerCamelCase				:    Tuple = -1    ,				_lowerCamelCase				:    Optional[int] = -1    ,				_lowerCamelCase				:    List[Any] = None    ,				):
              snake_case__ :       Optional[int]	   =							super().generate_dummy_inputs(
                  processor.tokenizer    ,				batch_size=SCREAMING_SNAKE_CASE_    ,				seq_length=SCREAMING_SNAKE_CASE_    ,				framework=SCREAMING_SNAKE_CASE_			)
              snake_case__ :       str	   =							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     UpperCAmelCase__    ( self				:    List[str]			):
              return 1_4









'''simple docstring'''



from collections.abc import Generator
from math import sin



def      UpperCAmelCase__   (      UpperCAmelCase_       :							bytes				)	->						bytes:
     if len(UpperCAmelCase_				) != 32:
          raise ValueError('Input must be of length 32'				)

     __lowerCamelCase  :      Dict														=						B''
     for i in [3, 2, 1, 0]:
          little_endian += string_aa[8 * i : 8 * i + 8]
     return little_endian



def      UpperCAmelCase__   (      UpperCAmelCase_       :							int				)	->						bytes:
     if i < 0:
          raise ValueError('Input must be non-negative'				)

     __lowerCamelCase  :      Union[str, Any]														=						format(UpperCAmelCase_ ,       '08x'				)[-8:]
     __lowerCamelCase  :      str														=						B''
     for i in [3, 2, 1, 0]:
          little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('utf-8'				)
     return little_endian_hex



def      UpperCAmelCase__   (      UpperCAmelCase_       :							bytes				)	->						bytes:
     __lowerCamelCase  :      Optional[Any]														=						B''
     for char in message:
          bit_string += format(UpperCAmelCase_ ,       '08b'				).encode('utf-8'				)
     __lowerCamelCase  :      List[str]														=						format(len(UpperCAmelCase_				) ,       '064b'				).encode('utf-8'				)

     # Pad bit_string to a multiple of 512 chars
     bit_string += b"1"
     while len(UpperCAmelCase_				) % 5_12 != 4_48:
          bit_string += b"0"
     bit_string += to_little_endian(start_len[32:]				) + to_little_endian(start_len[:32]				)

     return bit_string



def      UpperCAmelCase__   (      UpperCAmelCase_       :							bytes				)	->						Generator[list[int], None, None]:
     if len(UpperCAmelCase_				) % 5_12 != 0:
          raise ValueError('Input must have length that\'s a multiple of 512'				)

     for pos in range(0 ,       len(UpperCAmelCase_				) ,       5_12				):
          __lowerCamelCase  :      Any														=						bit_string[pos : pos + 5_12]
          __lowerCamelCase  :      Optional[int]														=						[]
          for i in range(0 ,       5_12 ,       32				):
               block_words.append(int(to_little_endian(block[i : i + 32]				) ,       2				)				)
          yield block_words



def      UpperCAmelCase__   (      UpperCAmelCase_       :							int				)	->						int:
     if i < 0:
          raise ValueError('Input must be non-negative'				)

     __lowerCamelCase  :      List[Any]														=						format(UpperCAmelCase_ ,       '032b'				)
     __lowerCamelCase  :      Optional[int]														=						''
     for c in i_str:
          new_str += "1" if c == "0" else "0"
     return int(UpperCAmelCase_ ,       2				)



def      UpperCAmelCase__   (      UpperCAmelCase_       :							int ,       UpperCAmelCase_       :							int				)	->						int:
     return (a + b) % 2**32



def      UpperCAmelCase__   (      UpperCAmelCase_       :							int ,       UpperCAmelCase_       :							int				)	->						int:
     if i < 0:
          raise ValueError('Input must be non-negative'				)
     if shift < 0:
          raise ValueError('Shift must be non-negative'				)
     return ((i << shift) ^ (i >> (32 - shift))) % 2**32



def      UpperCAmelCase__   (      UpperCAmelCase_       :							bytes				)	->						bytes:
     __lowerCamelCase  :      Optional[Any]														=						preprocess(UpperCAmelCase_				)

     __lowerCamelCase  :      Union[str, Any]														=						[int(2**32 * abs(sin(i + 1				)				)				) for i in range(64				)]

     # Starting states
     __lowerCamelCase  :      Dict														=						0x67_45_23_01
     __lowerCamelCase  :      Union[str, Any]														=						0xef_cd_ab_89
     __lowerCamelCase  :      Optional[Any]														=						0x98_ba_dc_fe
     __lowerCamelCase  :      Union[str, Any]														=						0x10_32_54_76

     __lowerCamelCase  :      List[str]														=						[
         7,
         12,
         17,
         22,
         7,
         12,
         17,
         22,
         7,
         12,
         17,
         22,
         7,
         12,
         17,
         22,
         5,
         9,
         14,
         20,
         5,
         9,
         14,
         20,
         5,
         9,
         14,
         20,
         5,
         9,
         14,
         20,
         4,
         11,
         16,
         23,
         4,
         11,
         16,
         23,
         4,
         11,
         16,
         23,
         4,
         11,
         16,
         23,
         6,
         10,
         15,
         21,
         6,
         10,
         15,
         21,
         6,
         10,
         15,
         21,
         6,
         10,
         15,
         21,
     ]

     # Process bit string in chunks, each with 16 32-char words
     for block_words in get_block_words(UpperCAmelCase_				):
          __lowerCamelCase  :      Dict														=						aa
          __lowerCamelCase  :      Tuple														=						ba
          __lowerCamelCase  :      List[Any]														=						ca
          __lowerCamelCase  :      Dict														=						da

          # Hash current chunk
          for i in range(64				):
               if i <= 15:
                    # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
                    __lowerCamelCase  :      List[str]														=						d ^ (b & (c ^ d))
                    __lowerCamelCase  :      Optional[int]														=						i
               elif i <= 31:
                    # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
                    __lowerCamelCase  :      Optional[int]														=						c ^ (d & (b ^ c))
                    __lowerCamelCase  :      Tuple														=						(5 * i + 1) % 16
               elif i <= 47:
                    __lowerCamelCase  :      str														=						b ^ c ^ d
                    __lowerCamelCase  :      Any														=						(3 * i + 5) % 16
               else:
                    __lowerCamelCase  :      Union[str, Any]														=						c ^ (b | not_aa(UpperCAmelCase_				))
                    __lowerCamelCase  :      int														=						(7 * i) % 16
               __lowerCamelCase  :      Optional[int]														=						(f + a + added_consts[i] + block_words[g]) % 2**32
               __lowerCamelCase  :      Optional[Any]														=						d
               __lowerCamelCase  :      Tuple														=						c
               __lowerCamelCase  :      Optional[int]														=						b
               __lowerCamelCase  :      List[str]														=						sum_aa(UpperCAmelCase_ ,       left_rotate_aa(UpperCAmelCase_ ,       shift_amounts[i]				)				)

          # Add hashed chunk to running total
          __lowerCamelCase  :      int														=						sum_aa(UpperCAmelCase_ ,       UpperCAmelCase_				)
          __lowerCamelCase  :      str														=						sum_aa(UpperCAmelCase_ ,       UpperCAmelCase_				)
          __lowerCamelCase  :      List[Any]														=						sum_aa(UpperCAmelCase_ ,       UpperCAmelCase_				)
          __lowerCamelCase  :      List[str]														=						sum_aa(UpperCAmelCase_ ,       UpperCAmelCase_				)

     __lowerCamelCase  :      Dict														=						reformat_hex(UpperCAmelCase_				) + reformat_hex(UpperCAmelCase_				) + reformat_hex(UpperCAmelCase_				) + reformat_hex(UpperCAmelCase_				)
     return digest


if __name__ == "__main__":
      import doctest

      doctest.testmod()






