



"""simple docstring"""
import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a      =				logging.get_logger(__name__)

__a      =				{
    "BAAI/AltCLIP": "https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class 				lowerCamelCase  (			_lowerCAmelCase				):






					'''simple docstring'''





					_A		:			Dict						=     """altclip_text_model"""






					def __init__(       self:							Tuple						,     snake_case:							List[Any]=250_002						,     snake_case:							Dict=1_024						,     snake_case:							Tuple=24						,     snake_case:							int=16						,     snake_case:							Any=4_096						,     snake_case:							Optional[int]="gelu"						,     snake_case:							List[Any]=0.1						,     snake_case:							Union[str, Any]=0.1						,     snake_case:							List[str]=514						,     snake_case:							List[Any]=1						,     snake_case:							Any=0.0_2						,     snake_case:							Optional[int]=0.0_2						,     snake_case:							Union[str, Any]=1E-05						,     snake_case:							List[Any]=1						,     snake_case:							Tuple=0						,     snake_case:							int=2						,     snake_case:							Dict="absolute"						,     snake_case:							Optional[int]=True						,     snake_case:							Tuple=768						,     **snake_case:							Union[str, Any]						,     )   ->	Union[str, Any]:
											super().__init__(pad_token_id=snake_case						,     bos_token_id=snake_case						,     eos_token_id=snake_case						,     **snake_case						)

											snake_case_ :Dict						=			vocab_size
											snake_case_ :str						=			hidden_size
											snake_case_ :List[Any]						=			num_hidden_layers
											snake_case_ :List[Any]						=			num_attention_heads
											snake_case_ :Union[str, Any]						=			hidden_act
											snake_case_ :Tuple						=			intermediate_size
											snake_case_ :List[str]						=			hidden_dropout_prob
											snake_case_ :int						=			attention_probs_dropout_prob
											snake_case_ :int						=			max_position_embeddings
											snake_case_ :Optional[int]						=			type_vocab_size
											snake_case_ :Union[str, Any]						=			initializer_range
											snake_case_ :str						=			initializer_factor
											snake_case_ :List[str]						=			layer_norm_eps
											snake_case_ :Tuple						=			position_embedding_type
											snake_case_ :str						=			use_cache
											snake_case_ :List[str]						=			project_dim

class 				lowerCamelCase  (			_lowerCAmelCase				):






					'''simple docstring'''





					_A		:			Optional[Any]						=     """altclip_vision_model"""






					def __init__(       self:							Dict						,     snake_case:							Dict=768						,     snake_case:							List[Any]=3_072						,     snake_case:							int=512						,     snake_case:							List[Any]=12						,     snake_case:							List[str]=12						,     snake_case:							Optional[int]=3						,     snake_case:							int=224						,     snake_case:							Optional[Any]=32						,     snake_case:							Optional[int]="quick_gelu"						,     snake_case:							Tuple=1E-5						,     snake_case:							Tuple=0.0						,     snake_case:							List[str]=0.0_2						,     snake_case:							Union[str, Any]=1.0						,     **snake_case:							str						,     )   ->	Optional[Any]:
											super().__init__(**snake_case						)

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






					@classmethod
					def    lowerCAmelCase_				(       cls:							List[str]						,     snake_case:							Union[str, os.PathLike]						,     **snake_case:							List[Any]						)   ->	"PretrainedConfig":
											cls._set_token_in_kwargs(snake_case						)

											snake_case_,       snake_case_ :List[str]						=			cls.get_config_dict(snake_case						,     **snake_case						)

											# get the vision config dict if we are loading from AltCLIPConfig
											if config_dict.get("""model_type"""						) == "altclip":
																	snake_case_ :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 				lowerCamelCase  (			_lowerCAmelCase				):






					'''simple docstring'''





					_A		:			str						=     """altclip"""
					_A		:			Any						=     True






					def __init__(       self:							int						,     snake_case:							Any=None						,     snake_case:							Optional[Any]=None						,     snake_case:							str=768						,     snake_case:							int=2.6_5_9_2						,     **snake_case:							Union[str, Any]						)   ->	str:
											# If `_config_dict` exist, we use them for the backward compatibility.
											# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
											# of confusion!).
											snake_case_ :str						=			kwargs.pop("""text_config_dict"""						,     snake_case						)
											snake_case_ :List[str]						=			kwargs.pop("""vision_config_dict"""						,     snake_case						)

											super().__init__(**snake_case						)

											# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
											# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
											# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
											if text_config_dict is not None:
																	if text_config is None:
																							snake_case_ :Tuple						=			{}

																	# This is the complete result when using `text_config_dict`.
																	snake_case_ :str						=			AltCLIPTextConfig(**snake_case						).to_dict()

																	# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
																	for key, value in _text_config_dict.items():
																							if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
																													# If specified in `text_config_dict`
																													if key in text_config_dict:
																																			snake_case_ :List[str]						=			(
																																			    f"""`{key}` is found in both `text_config_dict` and `text_config` but with different values. """
																																			    f"""The value `text_config_dict[\"{key}\"]` will be used instead."""
																																			)
																													# If inferred from default argument values (just to be super careful)
																													else:
																																			snake_case_ :str						=			(
																																			    f"""`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The """
																																			    f"""value `text_config[\"{key}\"]` will be overriden."""
																																			)
																													logger.warning(snake_case						)

            # Update all values in `text_config` with the ones in `_text_config_dict`.
																	text_config.update(_text_config_dict						)

											if vision_config_dict is not None:
																	if vision_config is None:
																							snake_case_ :Tuple						=			{}

																	# This is the complete result when using `vision_config_dict`.
																	snake_case_ :Dict						=			AltCLIPVisionConfig(**snake_case						).to_dict()
																	# convert keys to string instead of integer
																	if "id2label" in _vision_config_dict:
																							snake_case_ :Union[str, Any]						=			{
																							    str(snake_case						): value for key, value in _vision_config_dict["""id2label"""].items()
																							}

																	# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
																	for key, value in _vision_config_dict.items():
																							if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
																													# If specified in `vision_config_dict`
																													if key in vision_config_dict:
																																			snake_case_ :Dict						=			(
																																			    f"""`{key}` is found in both `vision_config_dict` and `vision_config` but with different """
																																			    f"""values. The value `vision_config_dict[\"{key}\"]` will be used instead."""
																																			)
																													# If inferred from default argument values (just to be super careful)
																													else:
																																			snake_case_ :Dict						=			(
																																			    f"""`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. """
																																			    f"""The value `vision_config[\"{key}\"]` will be overriden."""
																																			)
																													logger.warning(snake_case						)

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
																	vision_config.update(_vision_config_dict						)

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

											if vision_config is None:
																	snake_case_ :List[str]						=			{}
																	logger.info("""`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."""						)

											snake_case_ :Tuple						=			AltCLIPTextConfig(**snake_case						)
											snake_case_ :str						=			AltCLIPVisionConfig(**snake_case						)

											snake_case_ :int						=			projection_dim
											snake_case_ :Union[str, Any]						=			logit_scale_init_value
											snake_case_ :Dict						=			1.0






					@classmethod
					def    lowerCAmelCase_				(       cls:							str						,     snake_case:							AltCLIPTextConfig						,     snake_case:							AltCLIPVisionConfig						,     **snake_case:							int						)   ->	Union[str, Any]:
											return cls(text_config=text_config.to_dict()						,     vision_config=vision_config.to_dict()						,     **snake_case						)






					def    lowerCAmelCase_				(       self:							int						)   ->	Tuple:
											snake_case_ :str						=			copy.deepcopy(self.__dict__						)
											snake_case_ :Any						=			self.text_config.to_dict()
											snake_case_ :Optional[int]						=			self.vision_config.to_dict()
											snake_case_ :List[Any]						=			self.__class__.model_type
											return output








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	:							Optional[Any]				=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 			__a  (    A__       ):
 _lowerCAmelCase       :       Optional[int]        = '''owlvit_text_model'''







 def __init__(		self					:   Any							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]=4_94_08							,   SCREAMING_SNAKE_CASE					:   List[str]=5_12							,   SCREAMING_SNAKE_CASE					:   List[Any]=20_48							,   SCREAMING_SNAKE_CASE					:   Any=12							,   SCREAMING_SNAKE_CASE					:   Any=8							,   SCREAMING_SNAKE_CASE					:   Dict=16							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]="quick_gelu"							,   SCREAMING_SNAKE_CASE					:   List[str]=1e-5							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]=0.0							,   SCREAMING_SNAKE_CASE					:   Any=0.0_2							,   SCREAMING_SNAKE_CASE					:   int=1.0							,   SCREAMING_SNAKE_CASE					:   Any=0							,   SCREAMING_SNAKE_CASE					:   int=4_94_06							,   SCREAMING_SNAKE_CASE					:   List[str]=4_94_07							,   **SCREAMING_SNAKE_CASE					:   Optional[Any]							,   ):


      '''simple docstring'''






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

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







 @classmethod
 def 					__lowercase					(		cls					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Union[str, os.PathLike]							,   **SCREAMING_SNAKE_CASE					:   Optional[Any]						):


      '''simple docstring'''






      cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE						)

      UpperCamelCase__				,     UpperCamelCase__			:   Any       				=  cls.get_config_dict(SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)

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







class 			__a  (    A__       ):
 _lowerCAmelCase       :       str        = '''owlvit_vision_model'''







 def __init__(		self					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   str=7_68							,   SCREAMING_SNAKE_CASE					:   Dict=30_72							,   SCREAMING_SNAKE_CASE					:   int=12							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]=12							,   SCREAMING_SNAKE_CASE					:   Dict=3							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]=7_68							,   SCREAMING_SNAKE_CASE					:   Optional[int]=32							,   SCREAMING_SNAKE_CASE					:   Dict="quick_gelu"							,   SCREAMING_SNAKE_CASE					:   Optional[Any]=1e-5							,   SCREAMING_SNAKE_CASE					:   List[str]=0.0							,   SCREAMING_SNAKE_CASE					:   Dict=0.0_2							,   SCREAMING_SNAKE_CASE					:   Optional[int]=1.0							,   **SCREAMING_SNAKE_CASE					:   Tuple							,   ):


      '''simple docstring'''






      super().__init__(**SCREAMING_SNAKE_CASE						)

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







 @classmethod
 def 					__lowercase					(		cls					:   Dict							,   SCREAMING_SNAKE_CASE					:   Union[str, os.PathLike]							,   **SCREAMING_SNAKE_CASE					:   List[Any]						):


      '''simple docstring'''






      cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE						)

      UpperCamelCase__				,     UpperCamelCase__			:   List[Any]       				=  cls.get_config_dict(SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)

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







class 			__a  (    A__       ):
 _lowerCAmelCase       :       str        = '''owlvit'''
 _lowerCAmelCase       :       Tuple        = True







 def __init__(		self					:   Any							,   SCREAMING_SNAKE_CASE					:   Optional[Any]=None							,   SCREAMING_SNAKE_CASE					:   int=None							,   SCREAMING_SNAKE_CASE					:   str=5_12							,   SCREAMING_SNAKE_CASE					:   Any=2.6_5_9_2							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]=True							,   **SCREAMING_SNAKE_CASE					:   List[Any]							,   ):


      '''simple docstring'''






      super().__init__(**SCREAMING_SNAKE_CASE						)

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

      if vision_config is None:
           UpperCamelCase__			:   List[str]       				=  {}
           logger.info("vision_config is None. initializing the OwlViTVisionConfig with default values."						)

      UpperCamelCase__			:   Dict       				=  OwlViTTextConfig(**SCREAMING_SNAKE_CASE						)
      UpperCamelCase__			:   Dict       				=  OwlViTVisionConfig(**SCREAMING_SNAKE_CASE						)

      UpperCamelCase__			:   Dict       				=  projection_dim
      UpperCamelCase__			:   Union[str, Any]       				=  logit_scale_init_value
      UpperCamelCase__			:   int       				=  return_dict
      UpperCamelCase__			:   Tuple       				=  1.0







 @classmethod
 def 					__lowercase					(		cls					:   Any							,   SCREAMING_SNAKE_CASE					:   Union[str, os.PathLike]							,   **SCREAMING_SNAKE_CASE					:   Dict						):


      '''simple docstring'''






      cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE						)

      UpperCamelCase__				,     UpperCamelCase__			:   Dict       				=  cls.get_config_dict(SCREAMING_SNAKE_CASE							,   **SCREAMING_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(SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)







 @classmethod
 def 					__lowercase					(		cls					:   int							,   SCREAMING_SNAKE_CASE					:   Dict							,   SCREAMING_SNAKE_CASE					:   Dict							,   **SCREAMING_SNAKE_CASE					:   Optional[int]						):


      '''simple docstring'''






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

      return cls.from_dict(SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)







 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      UpperCamelCase__			:   Optional[int]       				=  copy.deepcopy(self.__dict__						)
      UpperCamelCase__			:   Union[str, Any]       				=  self.text_config.to_dict()
      UpperCamelCase__			:   List[str]       				=  self.vision_config.to_dict()
      UpperCamelCase__			:   Optional[int]       				=  self.__class__.model_type
      return output







class 			__a  (    A__       ):







 @property
 def 					__lowercase					(		self					:   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 					__lowercase					(		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 					__lowercase					(		self					:   Dict						):


      '''simple docstring'''






      return 1e-4







 def 					__lowercase					(		self					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   "ProcessorMixin"							,   SCREAMING_SNAKE_CASE					:   int = -1							,   SCREAMING_SNAKE_CASE					:   int = -1							,   SCREAMING_SNAKE_CASE					:   Optional["TensorType"] = None							,   ):


      '''simple docstring'''






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







 @property
 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      return 14