





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 SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					A__				 =    "owlvit_text_model"





					def __init__( self	,  _lowerCAmelCase=4_9408	,  _lowerCAmelCase=512	,  _lowerCAmelCase=2048	,  _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_9406	,  _lowerCAmelCase=4_9407	,  **_lowerCAmelCase	,  ):
										super().__init__(pad_token_id=_lowerCAmelCase	,  bos_token_id=_lowerCAmelCase	,  eos_token_id=_lowerCAmelCase	,  **_lowerCAmelCase	)

										lowerCamelCase__       =       vocab_size
										lowerCamelCase__       =       hidden_size
										lowerCamelCase__       =       intermediate_size
										lowerCamelCase__       =       num_hidden_layers
										lowerCamelCase__       =       num_attention_heads
										lowerCamelCase__       =       max_position_embeddings
										lowerCamelCase__       =       hidden_act
										lowerCamelCase__       =       layer_norm_eps
										lowerCamelCase__       =       attention_dropout
										lowerCamelCase__       =       initializer_range
										lowerCamelCase__       =       initializer_factor






					@classmethod
					def 					__magic_name__ ( cls	,  _lowerCAmelCase	,  **_lowerCAmelCase	):
										cls._set_token_in_kwargs(_lowerCAmelCase	)

										lowerCamelCase__    ,		lowerCamelCase__       =       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__       =       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 SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					A__				 =    "owlvit_vision_model"





					def __init__( self	,  _lowerCAmelCase=768	,  _lowerCAmelCase=3072	,  _lowerCAmelCase=12	,  _lowerCAmelCase=12	,  _lowerCAmelCase=3	,  _lowerCAmelCase=768	,  _lowerCAmelCase=32	,  _lowerCAmelCase="quick_gelu"	,  _lowerCAmelCase=1E-5	,  _lowerCAmelCase=0.0	,  _lowerCAmelCase=0.02	,  _lowerCAmelCase=1.0	,  **_lowerCAmelCase	,  ):
										super().__init__(**_lowerCAmelCase	)

										lowerCamelCase__       =       hidden_size
										lowerCamelCase__       =       intermediate_size
										lowerCamelCase__       =       num_hidden_layers
										lowerCamelCase__       =       num_attention_heads
										lowerCamelCase__       =       num_channels
										lowerCamelCase__       =       image_size
										lowerCamelCase__       =       patch_size
										lowerCamelCase__       =       hidden_act
										lowerCamelCase__       =       layer_norm_eps
										lowerCamelCase__       =       attention_dropout
										lowerCamelCase__       =       initializer_range
										lowerCamelCase__       =       initializer_factor






					@classmethod
					def 					__magic_name__ ( cls	,  _lowerCAmelCase	,  **_lowerCAmelCase	):
										cls._set_token_in_kwargs(_lowerCAmelCase	)

										lowerCamelCase__    ,		lowerCamelCase__       =       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__       =       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 SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					A__				 =    "owlvit"
					A__				 =    True





					def __init__( self	,  _lowerCAmelCase=None	,  _lowerCAmelCase=None	,  _lowerCAmelCase=512	,  _lowerCAmelCase=2.6_592	,  _lowerCAmelCase=True	,  **_lowerCAmelCase	,  ):
										super().__init__(**_lowerCAmelCase	)

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

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

										lowerCamelCase__       =       OwlViTTextConfig(**_lowerCAmelCase	)
										lowerCamelCase__       =       OwlViTVisionConfig(**_lowerCAmelCase	)

										lowerCamelCase__       =       projection_dim
										lowerCamelCase__       =       logit_scale_init_value
										lowerCamelCase__       =       return_dict
										lowerCamelCase__       =       1.0





					@classmethod
					def 					__magic_name__ ( cls	,  _lowerCAmelCase	,  **_lowerCAmelCase	):
										cls._set_token_in_kwargs(_lowerCAmelCase	)

										lowerCamelCase__    ,		lowerCamelCase__       =       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 					__magic_name__ ( cls	,  _lowerCAmelCase	,  _lowerCAmelCase	,  **_lowerCAmelCase	):
										lowerCamelCase__       =       {}
										lowerCamelCase__       =       text_config
										lowerCamelCase__       =       vision_config

										return cls.from_dict(_lowerCAmelCase	,  **_lowerCAmelCase	)






					def 					__magic_name__ ( self	):
										lowerCamelCase__       =       copy.deepcopy(self.__dict__	)
										lowerCamelCase__       =       self.text_config.to_dict()
										lowerCamelCase__       =       self.vision_config.to_dict()
										lowerCamelCase__       =       self.__class__.model_type
										return output

class SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					@property
					def 					__magic_name__ ( self	):
										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 					__magic_name__ ( self	):
										return OrderedDict(
										    [
										        ("logits_per_image", {0: "batch"}),
										        ("logits_per_text", {0: "batch"}),
										        ("text_embeds", {0: "batch"}),
										        ("image_embeds", {0: "batch"}),
										    ]	)





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





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase = -1	,  _lowerCAmelCase = -1	,  _lowerCAmelCase = None	,  ):
										lowerCamelCase__       =       super().generate_dummy_inputs(
										    processor.tokenizer	,  batch_size=_lowerCAmelCase	,  seq_length=_lowerCAmelCase	,  framework=_lowerCAmelCase	)
										lowerCamelCase__       =       super().generate_dummy_inputs(
										    processor.image_processor	,  batch_size=_lowerCAmelCase	,  framework=_lowerCAmelCase	)
										return {**text_input_dict, **image_input_dict}






					@property
					def 					__magic_name__ ( self	):
										return 14








def    __UpperCamelCase      (    a) ->str:

					if isinstance(a,     a):
										raise TypeError("'float' object cannot be interpreted as an integer")
					if isinstance(a,     a):
										raise TypeError("'str' object cannot be interpreted as an integer")

					if num == 0:
										return "0b0"

					lowerCamelCase__       =       False

					if num < 0:
										lowerCamelCase__       =       True
										lowerCamelCase__       =       -num

					lowerCamelCase__       =       []
					while num > 0:
										binary.insert(0,     num % 2)
										num >>= 1

					if negative:
										return "-0b" + "".join(str(a) for e in binary)

					return "0b" + "".join(str(a) for e in binary)


if __name__ == "__main__":
						import doctest

						doctest.testmod()

