




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


UpperCAmelCase_		:				Any									=     logging.get_logger(__name__)

UpperCAmelCase_		:				List[Any]									=     {
    "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      (			_snake_case			):
						UpperCamelCase     						=					'owlvit_text_model'

						def __init__(		self   :Dict    , __snake_case   :Optional[int]=4_94_08    , __snake_case   :List[Any]=5_12    , __snake_case   :Dict=20_48    , __snake_case   :str=12    , __snake_case   :Tuple=8    , __snake_case   :int=16    , __snake_case   :Optional[int]="quick_gelu"    , __snake_case   :int=1E-5    , __snake_case   :str=0.0    , __snake_case   :Tuple=0.02    , __snake_case   :str=1.0    , __snake_case   :Union[str, Any]=0    , __snake_case   :Optional[int]=4_94_06    , __snake_case   :Dict=4_94_07    , **__snake_case   :Tuple    , ):
										'''simple docstring'''

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

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


						@classmethod
						def     A__						(		cls   :List[Any]    , __snake_case   :Union[str, os.PathLike]    , **__snake_case   :Optional[int] ):
										'''simple docstring'''

										cls._set_token_in_kwargs(__snake_case )

										__magic_name__				, __magic_name__	:	Tuple								=cls.get_config_dict(__snake_case    , **__snake_case )

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




class 		__A      (			_snake_case			):
						UpperCamelCase     						=					'owlvit_vision_model'

						def __init__(		self   :Optional[Any]    , __snake_case   :List[str]=7_68    , __snake_case   :Any=30_72    , __snake_case   :Dict=12    , __snake_case   :str=12    , __snake_case   :Union[str, Any]=3    , __snake_case   :Dict=7_68    , __snake_case   :List[Any]=32    , __snake_case   :int="quick_gelu"    , __snake_case   :int=1E-5    , __snake_case   :str=0.0    , __snake_case   :str=0.02    , __snake_case   :Union[str, Any]=1.0    , **__snake_case   :Any    , ):
										'''simple docstring'''

										super().__init__(**__snake_case )

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


						@classmethod
						def     A__						(		cls   :str    , __snake_case   :Union[str, os.PathLike]    , **__snake_case   :List[Any] ):
										'''simple docstring'''

										cls._set_token_in_kwargs(__snake_case )

										__magic_name__				, __magic_name__	:	Optional[int]								=cls.get_config_dict(__snake_case    , **__snake_case )

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




class 		__A      (			_snake_case			):
						UpperCamelCase     						=					'owlvit'
						UpperCamelCase     						=					True

						def __init__(		self   :Optional[int]    , __snake_case   :Tuple=None    , __snake_case   :Optional[Any]=None    , __snake_case   :int=5_12    , __snake_case   :Union[str, Any]=2.6592    , __snake_case   :List[Any]=True    , **__snake_case   :List[str]    , ):
										'''simple docstring'''

										super().__init__(**__snake_case )

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

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

										__magic_name__	:	Optional[int]								=OwlViTTextConfig(**__snake_case )
										__magic_name__	:	List[str]								=OwlViTVisionConfig(**__snake_case )

										__magic_name__	:	Tuple								=projection_dim
										__magic_name__	:	Optional[int]								=logit_scale_init_value
										__magic_name__	:	List[Any]								=return_dict
										__magic_name__	:	Tuple								=1.0

						@classmethod
						def     A__						(		cls   :Any    , __snake_case   :Union[str, os.PathLike]    , **__snake_case   :Optional[Any] ):
										'''simple docstring'''

										cls._set_token_in_kwargs(__snake_case )

										__magic_name__				, __magic_name__	:	Optional[Any]								=cls.get_config_dict(__snake_case    , **__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(__snake_case    , **__snake_case )

						@classmethod
						def     A__						(		cls   :int    , __snake_case   :Dict    , __snake_case   :Dict    , **__snake_case   :Any ):
										'''simple docstring'''

										__magic_name__	:	Union[str, Any]								={}
										__magic_name__	:	int								=text_config
										__magic_name__	:	List[str]								=vision_config

										return cls.from_dict(__snake_case    , **__snake_case )


						def     A__						(		self   :Any ):
										'''simple docstring'''

										__magic_name__	:	str								=copy.deepcopy(self.__dict__ )
										__magic_name__	:	Tuple								=self.text_config.to_dict()
										__magic_name__	:	Dict								=self.vision_config.to_dict()
										__magic_name__	:	List[Any]								=self.__class__.model_type
										return output




class 		__A      (			_snake_case			):

						@property
						def     A__						(		self   :List[Any] ):
										'''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     A__						(		self   :Optional[int] ):
										'''simple docstring'''

										return OrderedDict(
										    [
										        ("""logits_per_image""", {0: """batch"""}),
										        ("""logits_per_text""", {0: """batch"""}),
										        ("""text_embeds""", {0: """batch"""}),
										        ("""image_embeds""", {0: """batch"""}),
										    ] )

						@property
						def     A__						(		self   :Optional[int] ):
										'''simple docstring'''

										return 1E-4

						def     A__						(		self   :int    , __snake_case   :"ProcessorMixin"    , __snake_case   :int = -1    , __snake_case   :int = -1    , __snake_case   :Optional["TensorType"] = None    , ):
										'''simple docstring'''

										__magic_name__	:	List[str]								=super().generate_dummy_inputs(
										    processor.tokenizer    , batch_size=__snake_case    , seq_length=__snake_case    , framework=__snake_case )
										__magic_name__	:	str								=super().generate_dummy_inputs(
										    processor.image_processor    , batch_size=__snake_case    , framework=__snake_case )
										return {**text_input_dict, **image_input_dict}


						@property
						def     A__						(		self   :str ):
										'''simple docstring'''

										return 14










import inspect
import warnings
from typing import Any, Dict, Optional, Union

from packaging import version




def 		lowerCAmelCase_   (	*lowerCamelCase	,     lowerCamelCase = None	,     lowerCamelCase=True	,     lowerCamelCase=2   ):
				from .. import __version__

				__magic_name__	:	Optional[int]								=take_from
				__magic_name__	:	Tuple								=()
				if not isinstance(args[0]	,     lowerCamelCase   ):
								__magic_name__	:	List[Any]								=(args,)

				for attribute, version_name, message in args:
								if version.parse(version.parse(lowerCamelCase   ).base_version   ) >= version.parse(lowerCamelCase   ):
												raise ValueError(
												    F"The deprecation tuple {(attribute, version_name, message)} should be removed since diffusers'"
												    F" version {__version__} is >= {version_name}"   )

								__magic_name__	:	List[str]								=None
								if isinstance(lowerCamelCase	,     lowerCamelCase   ) and attribute in deprecated_kwargs:
												values += (deprecated_kwargs.pop(lowerCamelCase   ),)
												__magic_name__	:	List[str]								=F"The `{attribute}` argument is deprecated and will be removed in version {version_name}."
								elif hasattr(lowerCamelCase	,     lowerCamelCase   ):
												values += (getattr(lowerCamelCase	,     lowerCamelCase   ),)
												__magic_name__	:	List[str]								=F"The `{attribute}` attribute is deprecated and will be removed in version {version_name}."
								elif deprecated_kwargs is None:
												__magic_name__	:	List[str]								=F"`{attribute}` is deprecated and will be removed in version {version_name}."

								if warning is not None:
												__magic_name__	:	List[Any]								=warning + """ """ if standard_warn else """"""
												warnings.warn(warning + message	,     lowerCamelCase	,     stacklevel=lowerCamelCase   )

				if isinstance(lowerCamelCase	,     lowerCamelCase   ) and len(lowerCamelCase   ) > 0:
								__magic_name__	:	List[Any]								=inspect.getouterframes(inspect.currentframe()   )[1]
								__magic_name__	:	Optional[int]								=call_frame.filename
								__magic_name__	:	Tuple								=call_frame.lineno
								__magic_name__	:	str								=call_frame.function
								__magic_name__				, __magic_name__	:	Optional[int]								=next(iter(deprecated_kwargs.items()   )   )
								raise TypeError(F"{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`"   )

				if len(lowerCamelCase   ) == 0:
								return
				elif len(lowerCamelCase   ) == 1:
								return values[0]
				return values




