


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


lowerCAmelCase   : List[str]             =				logging.get_logger(__name__)

lowerCAmelCase   : Optional[int]             =				{
    """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	(    SCREAMING_SNAKE_CASE):


				'''simple docstring'''


				_snake_case						       =				'''owlvit_text_model'''

				def __init__(     self							,      a_=4_9_4_0_8							,      a_=5_1_2							,      a_=2_0_4_8							,      a_=1_2							,      a_=8							,      a_=1_6							,      a_="quick_gelu"							,      a_=1e-5							,      a_=0.0							,      a_=0.02							,      a_=1.0							,      a_=0							,      a_=4_9_4_0_6							,      a_=4_9_4_0_7							,      **a_							,      )    ->  Optional[int]:
					super().__init__(pad_token_id=a_							,      bos_token_id=a_							,      eos_token_id=a_							,      **a_							)

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


				@classmethod
				def 	a__		(     cls							,      a_							,      **a_							)    ->  "PretrainedConfig":
					cls._set_token_in_kwargs(a_							)

					lowercase					,		lowercase						:		List[Any]   					=		cls.get_config_dict(a_							,      **a_							)

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




class        _UpperCamelCase	(    SCREAMING_SNAKE_CASE):


				'''simple docstring'''


				_snake_case						       =				'''owlvit_vision_model'''

				def __init__(     self							,      a_=7_6_8							,      a_=3_0_7_2							,      a_=1_2							,      a_=1_2							,      a_=3							,      a_=7_6_8							,      a_=3_2							,      a_="quick_gelu"							,      a_=1e-5							,      a_=0.0							,      a_=0.02							,      a_=1.0							,      **a_							,      )    ->  Optional[int]:
					super().__init__(**a_							)

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


				@classmethod
				def 	a__		(     cls							,      a_							,      **a_							)    ->  "PretrainedConfig":
					cls._set_token_in_kwargs(a_							)

					lowercase					,		lowercase						:		int   					=		cls.get_config_dict(a_							,      **a_							)

					# get the vision config dict if we are loading from OwlViTConfig
					if config_dict.get("model_type"							) == "owlvit":
						lowercase						:		Optional[int]   					=		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(a_							,      **a_							)




class        _UpperCamelCase	(    SCREAMING_SNAKE_CASE):


				'''simple docstring'''


				_snake_case						       =				'''owlvit'''
				_snake_case						       =				True

				def __init__(     self							,      a_=None							,      a_=None							,      a_=5_1_2							,      a_=2.65_92							,      a_=True							,      **a_							,      )    ->  Optional[Any]:
					super().__init__(**a_							)

					if text_config is None:
						lowercase						:		Optional[int]   					=		{}
						logger.info("text_config is None. Initializing the OwlViTTextConfig with default values."							)

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

					lowercase						:		Union[str, Any]   					=		OwlViTTextConfig(**a_							)
					lowercase						:		Any   					=		OwlViTVisionConfig(**a_							)

					lowercase						:		Any   					=		projection_dim
					lowercase						:		Dict   					=		logit_scale_init_value
					lowercase						:		str   					=		return_dict
					lowercase						:		Union[str, Any]   					=		1.0

				@classmethod
				def 	a__		(     cls							,      a_							,      **a_							)    ->  "PretrainedConfig":
					cls._set_token_in_kwargs(a_							)

					lowercase					,		lowercase						:		Union[str, Any]   					=		cls.get_config_dict(a_							,      **a_							)

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

				@classmethod
				def 	a__		(     cls							,      a_							,      a_							,      **a_							)    ->  Optional[Any]:
					lowercase						:		Dict   					=		{}
					lowercase						:		Optional[Any]   					=		text_config
					lowercase						:		Optional[Any]   					=		vision_config

					return cls.from_dict(a_							,      **a_							)


				def 	a__		(     self							)    ->  Union[str, Any]:
					lowercase						:		Optional[int]   					=		copy.deepcopy(self.__dict__							)
					lowercase						:		Any   					=		self.text_config.to_dict()
					lowercase						:		Union[str, Any]   					=		self.vision_config.to_dict()
					lowercase						:		Optional[Any]   					=		self.__class__.model_type
					return output




class        _UpperCamelCase	(    SCREAMING_SNAKE_CASE):


				'''simple docstring'''


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

				@property
				def 	a__		(     self							)    ->  float:
					return 1e-4

				def 	a__		(     self							,      a_							,      a_ = -1							,      a_ = -1							,      a_ = None							,      )    ->  Mapping[str, Any]:
					lowercase						:		Any   					=		super().generate_dummy_inputs(
					    processor.tokenizer							,      batch_size=a_							,      seq_length=a_							,      framework=a_							)
					lowercase						:		List[str]   					=		super().generate_dummy_inputs(
					    processor.image_processor							,      batch_size=a_							,      framework=a_							)
					return {**text_input_dict, **image_input_dict}


				@property
				def 	a__		(     self							)    ->  int:
					return 1_4






'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase   : List[Any]             =				{
    """configuration_albert""": ["""ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """AlbertConfig""", """AlbertOnnxConfig"""],
}

try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase   : Any             =				["""AlbertTokenizer"""]

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase   : Optional[Any]             =				["""AlbertTokenizerFast"""]

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase   : List[str]             =				[
					    """ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """AlbertForMaskedLM""",
					    """AlbertForMultipleChoice""",
					    """AlbertForPreTraining""",
					    """AlbertForQuestionAnswering""",
					    """AlbertForSequenceClassification""",
					    """AlbertForTokenClassification""",
					    """AlbertModel""",
					    """AlbertPreTrainedModel""",
					    """load_tf_weights_in_albert""",
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase   : Tuple             =				[
					    """TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """TFAlbertForMaskedLM""",
					    """TFAlbertForMultipleChoice""",
					    """TFAlbertForPreTraining""",
					    """TFAlbertForQuestionAnswering""",
					    """TFAlbertForSequenceClassification""",
					    """TFAlbertForTokenClassification""",
					    """TFAlbertMainLayer""",
					    """TFAlbertModel""",
					    """TFAlbertPreTrainedModel""",
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase   : Optional[int]             =				[
					    """FlaxAlbertForMaskedLM""",
					    """FlaxAlbertForMultipleChoice""",
					    """FlaxAlbertForPreTraining""",
					    """FlaxAlbertForQuestionAnswering""",
					    """FlaxAlbertForSequenceClassification""",
					    """FlaxAlbertForTokenClassification""",
					    """FlaxAlbertModel""",
					    """FlaxAlbertPreTrainedModel""",
					]

if TYPE_CHECKING:
					from .configuration_albert import ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, AlbertConfig, AlbertOnnxConfig

					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_albert import AlbertTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_albert_fast import AlbertTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_albert import (
										    ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    AlbertForMaskedLM,
										    AlbertForMultipleChoice,
										    AlbertForPreTraining,
										    AlbertForQuestionAnswering,
										    AlbertForSequenceClassification,
										    AlbertForTokenClassification,
										    AlbertModel,
										    AlbertPreTrainedModel,
										    load_tf_weights_in_albert,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_albert import (
										    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFAlbertForMaskedLM,
										    TFAlbertForMultipleChoice,
										    TFAlbertForPreTraining,
										    TFAlbertForQuestionAnswering,
										    TFAlbertForSequenceClassification,
										    TFAlbertForTokenClassification,
										    TFAlbertMainLayer,
										    TFAlbertModel,
										    TFAlbertPreTrainedModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_albert import (
										    FlaxAlbertForMaskedLM,
										    FlaxAlbertForMultipleChoice,
										    FlaxAlbertForPreTraining,
										    FlaxAlbertForQuestionAnswering,
										    FlaxAlbertForSequenceClassification,
										    FlaxAlbertForTokenClassification,
										    FlaxAlbertModel,
										    FlaxAlbertPreTrainedModel,
										)
else:
					import sys

					lowerCAmelCase   : Union[str, Any]             =				_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


