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


A__      :	Optional[int]          =    logging.get_logger(__name__)

A__      :	Dict          =    {
    """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						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							'owlvit_text_model'



     def __init__(      self ,			__UpperCamelCase=4_94_08 ,			__UpperCamelCase=5_12 ,			__UpperCamelCase=20_48 ,			__UpperCamelCase=12 ,			__UpperCamelCase=8 ,			__UpperCamelCase=16 ,			__UpperCamelCase="quick_gelu" ,			__UpperCamelCase=1E-5 ,			__UpperCamelCase=0.0 ,			__UpperCamelCase=0.02 ,			__UpperCamelCase=1.0 ,			__UpperCamelCase=0 ,			__UpperCamelCase=4_94_06 ,			__UpperCamelCase=4_94_07 ,			**__UpperCamelCase ,			)->					Any:
          super().__init__(pad_token_id=__UpperCamelCase ,			bos_token_id=__UpperCamelCase ,			eos_token_id=__UpperCamelCase ,			**__UpperCamelCase  )

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



     @classmethod
     def  lowerCAmelCase__       (      cls ,			__UpperCamelCase ,			**__UpperCamelCase  )->					"PretrainedConfig":
          cls._set_token_in_kwargs(__UpperCamelCase  )

          UpperCAmelCase__							: Optional[int] 							=						cls.get_config_dict(__UpperCamelCase ,			**__UpperCamelCase  )

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







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							'owlvit_vision_model'



     def __init__(      self ,			__UpperCamelCase=7_68 ,			__UpperCamelCase=30_72 ,			__UpperCamelCase=12 ,			__UpperCamelCase=12 ,			__UpperCamelCase=3 ,			__UpperCamelCase=7_68 ,			__UpperCamelCase=32 ,			__UpperCamelCase="quick_gelu" ,			__UpperCamelCase=1E-5 ,			__UpperCamelCase=0.0 ,			__UpperCamelCase=0.02 ,			__UpperCamelCase=1.0 ,			**__UpperCamelCase ,			)->					List[Any]:
          super().__init__(**__UpperCamelCase  )

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



     @classmethod
     def  lowerCAmelCase__       (      cls ,			__UpperCamelCase ,			**__UpperCamelCase  )->					"PretrainedConfig":
          cls._set_token_in_kwargs(__UpperCamelCase  )

          UpperCAmelCase__							: Tuple 							=						cls.get_config_dict(__UpperCamelCase ,			**__UpperCamelCase  )

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







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							'owlvit'
     _A								=							True



     def __init__(      self ,			__UpperCamelCase=None ,			__UpperCamelCase=None ,			__UpperCamelCase=5_12 ,			__UpperCamelCase=2.6592 ,			__UpperCamelCase=True ,			**__UpperCamelCase ,			)->					str:
          super().__init__(**__UpperCamelCase  )

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

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

          UpperCAmelCase__							: Optional[int] 							=						OwlViTTextConfig(**__UpperCamelCase  )
          UpperCAmelCase__							: Tuple 							=						OwlViTVisionConfig(**__UpperCamelCase  )

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



     @classmethod
     def  lowerCAmelCase__       (      cls ,			__UpperCamelCase ,			**__UpperCamelCase  )->					"PretrainedConfig":
          cls._set_token_in_kwargs(__UpperCamelCase  )

          UpperCAmelCase__							: Tuple 							=						cls.get_config_dict(__UpperCamelCase ,			**__UpperCamelCase  )

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



     @classmethod
     def  lowerCAmelCase__       (      cls ,			__UpperCamelCase ,			__UpperCamelCase ,			**__UpperCamelCase  )->					Tuple:
          UpperCAmelCase__							: Optional[Any] 							=						{}
          UpperCAmelCase__							: Union[str, Any] 							=						text_config
          UpperCAmelCase__							: Optional[Any] 							=						vision_config

          return cls.from_dict(__UpperCamelCase ,			**__UpperCamelCase  )



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







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     @property
     def  lowerCAmelCase__       (      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  lowerCAmelCase__       (      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  lowerCAmelCase__       (      self  )->					float:
          return 1E-4



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



     @property
     def  lowerCAmelCase__       (      self  )->					int:
          return 14





"""simple docstring"""




from typing import TYPE_CHECKING

from ....utils import _LazyModule


A__      :	List[str]          =    {"""tokenization_tapex""": ["""TapexTokenizer"""]}


if TYPE_CHECKING:
    from .tokenization_tapex import TapexTokenizer


else:
    import sys

    A__      :	Any          =    _LazyModule(__name__, globals()["""__file__"""], _import_structure)



