






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      lowercase__     (			a__	):
	a_         ="""owlvit_text_model"""

	def __init__(							self		,    __UpperCAmelCase=49408		,    __UpperCAmelCase=512		,    __UpperCAmelCase=2048		,    __UpperCAmelCase=12		,    __UpperCAmelCase=8		,    __UpperCAmelCase=16		,    __UpperCAmelCase="quick_gelu"		,    __UpperCAmelCase=1E-5		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=0.02		,    __UpperCAmelCase=1.0		,    __UpperCAmelCase=0		,    __UpperCAmelCase=49406		,    __UpperCAmelCase=49407		,    **__UpperCAmelCase		,    )->					Optional[int]:







							'''simple docstring'''





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

							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 		UpperCAmelCase  (							cls		,    __UpperCAmelCase		,    **__UpperCAmelCase       )->					"PretrainedConfig":







							'''simple docstring'''





							cls._set_token_in_kwargs(lowercase__       )

							lowerCAmelCase__       =						cls.get_config_dict(lowercase__		,    **lowercase__       )

							# 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(lowercase__		,    **lowercase__       )





class      lowercase__     (			a__	):
	a_         ="""owlvit_vision_model"""

	def __init__(							self		,    __UpperCAmelCase=768		,    __UpperCAmelCase=3072		,    __UpperCAmelCase=12		,    __UpperCAmelCase=12		,    __UpperCAmelCase=3		,    __UpperCAmelCase=768		,    __UpperCAmelCase=32		,    __UpperCAmelCase="quick_gelu"		,    __UpperCAmelCase=1E-5		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=0.02		,    __UpperCAmelCase=1.0		,    **__UpperCAmelCase		,    )->					Tuple:







							'''simple docstring'''





							super().__init__(**lowercase__       )

							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 		UpperCAmelCase  (							cls		,    __UpperCAmelCase		,    **__UpperCAmelCase       )->					"PretrainedConfig":







							'''simple docstring'''





							cls._set_token_in_kwargs(lowercase__       )

							lowerCAmelCase__       =						cls.get_config_dict(lowercase__		,    **lowercase__       )

							# 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(lowercase__		,    **lowercase__       )





class      lowercase__     (			a__	):
	a_         ="""owlvit"""
	a_         =True

	def __init__(							self		,    __UpperCAmelCase=None		,    __UpperCAmelCase=None		,    __UpperCAmelCase=512		,    __UpperCAmelCase=2.6_592		,    __UpperCAmelCase=True		,    **__UpperCAmelCase		,    )->					List[str]:







							'''simple docstring'''





							super().__init__(**lowercase__       )

							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(**lowercase__       )
							lowerCAmelCase__       =						OwlViTVisionConfig(**lowercase__       )

							lowerCAmelCase__       =						projection_dim
							lowerCAmelCase__       =						logit_scale_init_value
							lowerCAmelCase__       =						return_dict
							lowerCAmelCase__       =						1.0

	@classmethod
	def 		UpperCAmelCase  (							cls		,    __UpperCAmelCase		,    **__UpperCAmelCase       )->					"PretrainedConfig":







							'''simple docstring'''





							cls._set_token_in_kwargs(lowercase__       )

							lowerCAmelCase__       =						cls.get_config_dict(lowercase__		,    **lowercase__       )

							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(lowercase__		,    **lowercase__       )

	@classmethod
	def 		UpperCAmelCase  (							cls		,    __UpperCAmelCase		,    __UpperCAmelCase		,    **__UpperCAmelCase       )->					Union[str, Any]:







							'''simple docstring'''





							lowerCAmelCase__       =						{}
							lowerCAmelCase__       =						text_config
							lowerCAmelCase__       =						vision_config

							return cls.from_dict(lowercase__		,    **lowercase__       )


	def 		UpperCAmelCase  (							self       )->					Tuple:







							'''simple docstring'''





							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      lowercase__     (			a__	):

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







							'''simple docstring'''





							return 1E-4

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







							'''simple docstring'''





							lowerCAmelCase__       =						super().generate_dummy_inputs(
							    processor.tokenizer		,    batch_size=lowercase__		,    seq_length=lowercase__		,    framework=lowercase__       )
							lowerCAmelCase__       =						super().generate_dummy_inputs(
							    processor.image_processor		,    batch_size=lowercase__		,    framework=lowercase__       )
							return {**text_input_dict, **image_input_dict}


	@property
	def 		UpperCAmelCase  (							self       )->					int:







							'''simple docstring'''





							return 14














from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a_							=    {'''configuration_ibert''': ['''IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''IBertConfig''', '''IBertOnnxConfig''']}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a_							=    [
	    '''IBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''IBertForMaskedLM''',
	    '''IBertForMultipleChoice''',
	    '''IBertForQuestionAnswering''',
	    '''IBertForSequenceClassification''',
	    '''IBertForTokenClassification''',
	    '''IBertModel''',
	    '''IBertPreTrainedModel''',
	]

if TYPE_CHECKING:
	from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_ibert import (
		    IBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    IBertForMaskedLM,
		    IBertForMultipleChoice,
		    IBertForQuestionAnswering,
		    IBertForSequenceClassification,
		    IBertForTokenClassification,
		    IBertModel,
		    IBertPreTrainedModel,
		)

else:
	import sys

	a_							=    _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






