




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


_lowercase  =			logging.get_logger(__name__)

_lowercase  =			{
    """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 						a_				(			UpperCAmelCase__						):
	lowercase_       :     Dict			  =      '''owlvit_text_model'''




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

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




	@classmethod
	def   lowercase__   (       cls     :  Tuple       ,		__lowerCAmelCase     :  Union[str, os.PathLike]       ,		**__lowerCAmelCase     :  Dict      ):
							cls._set_token_in_kwargs(__lowerCAmelCase      )

							__snake_case ,       __snake_case						 =   cls.get_config_dict(__lowerCAmelCase       ,		**__lowerCAmelCase      )

							# get the text config dict if we are loading from OwlViTConfig
							if config_dict.get('model_type'      ) == "owlvit":
													__snake_case						 =   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 						a_				(			UpperCAmelCase__						):
	lowercase_       :     str			  =      '''owlvit_vision_model'''




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

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




	@classmethod
	def   lowercase__   (       cls     :  Optional[int]       ,		__lowerCAmelCase     :  Union[str, os.PathLike]       ,		**__lowerCAmelCase     :  str      ):
							cls._set_token_in_kwargs(__lowerCAmelCase      )

							__snake_case ,       __snake_case						 =   cls.get_config_dict(__lowerCAmelCase       ,		**__lowerCAmelCase      )

							# get the vision config dict if we are loading from OwlViTConfig
							if config_dict.get('model_type'      ) == "owlvit":
													__snake_case						 =   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 						a_				(			UpperCAmelCase__						):
	lowercase_       :     Optional[Any]			  =      '''owlvit'''
	lowercase_       :     Dict			  =      True




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

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

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

							__snake_case						 =   OwlViTTextConfig(**__lowerCAmelCase      )
							__snake_case						 =   OwlViTVisionConfig(**__lowerCAmelCase      )

							__snake_case						 =   projection_dim
							__snake_case						 =   logit_scale_init_value
							__snake_case						 =   return_dict
							__snake_case						 =   1.0




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

							__snake_case ,       __snake_case						 =   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     :  Any       ,		__lowerCAmelCase     :  Dict       ,		__lowerCAmelCase     :  Dict       ,		**__lowerCAmelCase     :  int      ):
							__snake_case						 =   {}
							__snake_case						 =   text_config
							__snake_case						 =   vision_config

							return cls.from_dict(__lowerCAmelCase       ,		**__lowerCAmelCase      )




	def   lowercase__   (       self     :  Union[str, Any]      ):
							__snake_case						 =   copy.deepcopy(self.__dict__      )
							__snake_case						 =   self.text_config.to_dict()
							__snake_case						 =   self.vision_config.to_dict()
							__snake_case						 =   self.__class__.model_type
							return output





class 						a_				(			UpperCAmelCase__						):




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




	@property
	def   lowercase__   (       self     :  Union[str, Any]      ):
							return 1E-4




	def   lowercase__   (       self     :  Dict       ,		__lowerCAmelCase     :  "ProcessorMixin"       ,		__lowerCAmelCase     :  int = -1       ,		__lowerCAmelCase     :  int = -1       ,		__lowerCAmelCase     :  Optional["TensorType"] = None       ,		):
							__snake_case						 =   super().generate_dummy_inputs(
							    processor.tokenizer       ,		batch_size=__lowerCAmelCase       ,		seq_length=__lowerCAmelCase       ,		framework=__lowerCAmelCase      )
							__snake_case						 =   super().generate_dummy_inputs(
							    processor.image_processor       ,		batch_size=__lowerCAmelCase       ,		framework=__lowerCAmelCase      )
							return {**text_input_dict, **image_input_dict}




	@property
	def   lowercase__   (       self     :  List[Any]      ):
							return 1_4







'''simple docstring'''


from .configuration_bert_masked import MaskedBertConfig
from .modeling_bert_masked import (
    MaskedBertForMultipleChoice,
    MaskedBertForQuestionAnswering,
    MaskedBertForSequenceClassification,
    MaskedBertForTokenClassification,
    MaskedBertModel,
)
from .modules import *

