





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             =							logging.get_logger(__name__)

_UpperCAmelCase             =							{
    '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        snake_case_    (		__lowercase						):
  A_      							=   'owlvit_text_model'






  def __init__(							self			:					Optional[Any]       ,  _snake_case			:					List[Any]=49408       ,  _snake_case			:					Optional[int]=512       ,  _snake_case			:					Union[str, Any]=2048       ,  _snake_case			:					Any=12       ,  _snake_case			:					Union[str, Any]=8       ,  _snake_case			:					int=16       ,  _snake_case			:					Dict="quick_gelu"       ,  _snake_case			:					Optional[int]=1E-5       ,  _snake_case			:					Any=0.0       ,  _snake_case			:					Dict=0.02       ,  _snake_case			:					Optional[Any]=1.0       ,  _snake_case			:					str=0       ,  _snake_case			:					str=49406       ,  _snake_case			:					Optional[int]=49407       ,  **_snake_case			:					Any       ,  )->Optional[int]:






   '''simple docstring'''

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

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






  @classmethod
  def 				UpperCAmelCase__						(							cls			:					str       ,  _snake_case			:					Union[str, os.PathLike]       ,  **_snake_case			:					List[str]      )->"PretrainedConfig":






   '''simple docstring'''

   cls._set_token_in_kwargs(_snake_case      )

   __lowerCAmelCase ,					__lowerCAmelCase					:	Dict      =       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":
    __lowerCAmelCase					:	int      =       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        snake_case_    (		__lowercase						):
  A_      							=   'owlvit_vision_model'






  def __init__(							self			:					Optional[int]       ,  _snake_case			:					List[Any]=768       ,  _snake_case			:					str=3072       ,  _snake_case			:					str=12       ,  _snake_case			:					List[str]=12       ,  _snake_case			:					int=3       ,  _snake_case			:					Optional[int]=768       ,  _snake_case			:					Dict=32       ,  _snake_case			:					Dict="quick_gelu"       ,  _snake_case			:					List[str]=1E-5       ,  _snake_case			:					Any=0.0       ,  _snake_case			:					List[Any]=0.02       ,  _snake_case			:					Dict=1.0       ,  **_snake_case			:					Union[str, Any]       ,  )->Optional[Any]:






   '''simple docstring'''

   super().__init__(**_snake_case      )

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






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






   '''simple docstring'''

   cls._set_token_in_kwargs(_snake_case      )

   __lowerCAmelCase ,					__lowerCAmelCase					:	List[Any]      =       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":
    __lowerCAmelCase					:	Tuple      =       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        snake_case_    (		__lowercase						):
  A_      							=   'owlvit'
  A_      							=   True






  def __init__(							self			:					Any       ,  _snake_case			:					Any=None       ,  _snake_case			:					int=None       ,  _snake_case			:					Tuple=512       ,  _snake_case			:					Union[str, Any]=2.6_592       ,  _snake_case			:					Optional[Any]=True       ,  **_snake_case			:					Union[str, Any]       ,  )->Dict:






   '''simple docstring'''

   super().__init__(**_snake_case      )

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

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

   __lowerCAmelCase					:	List[str]      =       OwlViTTextConfig(**_snake_case      )
   __lowerCAmelCase					:	Optional[Any]      =       OwlViTVisionConfig(**_snake_case      )

   __lowerCAmelCase					:	List[Any]      =       projection_dim
   __lowerCAmelCase					:	Any      =       logit_scale_init_value
   __lowerCAmelCase					:	str      =       return_dict
   __lowerCAmelCase					:	Union[str, Any]      =       1.0






  @classmethod
  def 				UpperCAmelCase__						(							cls			:					List[str]       ,  _snake_case			:					Union[str, os.PathLike]       ,  **_snake_case			:					Tuple      )->"PretrainedConfig":






   '''simple docstring'''

   cls._set_token_in_kwargs(_snake_case      )

   __lowerCAmelCase ,					__lowerCAmelCase					:	List[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 				UpperCAmelCase__						(							cls			:					Union[str, Any]       ,  _snake_case			:					Dict       ,  _snake_case			:					Dict       ,  **_snake_case			:					Tuple      )->Dict:






   '''simple docstring'''

   __lowerCAmelCase					:	Dict      =       {}
   __lowerCAmelCase					:	Union[str, Any]      =       text_config
   __lowerCAmelCase					:	int      =       vision_config

   return cls.from_dict(_snake_case       ,  **_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Any      )->Dict:






   '''simple docstring'''

   __lowerCAmelCase					:	Optional[Any]      =       copy.deepcopy(self.__dict__      )
   __lowerCAmelCase					:	Optional[int]      =       self.text_config.to_dict()
   __lowerCAmelCase					:	Tuple      =       self.vision_config.to_dict()
   __lowerCAmelCase					:	str      =       self.__class__.model_type
   return output






class        snake_case_    (		__lowercase						):






  @property
  def 				UpperCAmelCase__						(							self			:					List[str]      )->Mapping[str, Mapping[int, str]]:






   '''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 				UpperCAmelCase__						(							self			:					Any      )->Mapping[str, Mapping[int, str]]:






   '''simple docstring'''

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






  @property
  def 				UpperCAmelCase__						(							self			:					Any      )->float:






   '''simple docstring'''

   return 1E-4






  def 				UpperCAmelCase__						(							self			:					List[Any]       ,  _snake_case			:					"ProcessorMixin"       ,  _snake_case			:					int = -1       ,  _snake_case			:					int = -1       ,  _snake_case			:					Optional["TensorType"] = None       ,  )->Mapping[str, Any]:






   '''simple docstring'''

   __lowerCAmelCase					:	Tuple      =       super().generate_dummy_inputs(
       processor.tokenizer       ,  batch_size=_snake_case       ,  seq_length=_snake_case       ,  framework=_snake_case      )
   __lowerCAmelCase					:	Optional[int]      =       super().generate_dummy_inputs(
       processor.image_processor       ,  batch_size=_snake_case       ,  framework=_snake_case      )
   return {**text_input_dict, **image_input_dict}






  @property
  def 				UpperCAmelCase__						(							self			:					Union[str, Any]      )->int:






   '''simple docstring'''

   return 14






import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class        snake_case_    (		__lowercase						):
  A_      							=   ['image_processor', 'tokenizer']
  A_      							=   'ChineseCLIPImageProcessor'
  A_      							=   ('BertTokenizer', 'BertTokenizerFast')






  def __init__(							self			:					Optional[Any]       ,  _snake_case			:					List[Any]=None       ,  _snake_case			:					str=None       ,  **_snake_case			:					int      )->List[str]:






   '''simple docstring'''

   __lowerCAmelCase					:	str      =       None
   if "feature_extractor" in kwargs:
    warnings.warn(
        """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
        """ instead."""       ,  _snake_case       ,  )
    __lowerCAmelCase					:	List[str]      =       kwargs.pop("""feature_extractor"""      )

   __lowerCAmelCase					:	Union[str, Any]      =       image_processor if image_processor is not None else feature_extractor
   if image_processor is None:
    raise ValueError("""You need to specify an `image_processor`."""      )
   if tokenizer is None:
    raise ValueError("""You need to specify a `tokenizer`."""      )

   super().__init__(_snake_case       ,  _snake_case      )
   __lowerCAmelCase					:	Any      =       self.image_processor






  def __call__(							self			:					Optional[Any]       ,  _snake_case			:					Tuple=None       ,  _snake_case			:					Tuple=None       ,  _snake_case			:					List[str]=None       ,  **_snake_case			:					Any      )->Union[str, Any]:






   '''simple docstring'''

   if text is None and images is None:
    raise ValueError("""You have to specify either text or images. Both cannot be none."""      )

   if text is not None:
    __lowerCAmelCase					:	List[Any]      =       self.tokenizer(_snake_case       ,  return_tensors=_snake_case       ,  **_snake_case      )

   if images is not None:
    __lowerCAmelCase					:	Tuple      =       self.image_processor(_snake_case       ,  return_tensors=_snake_case       ,  **_snake_case      )

   if text is not None and images is not None:
    __lowerCAmelCase					:	Optional[Any]      =       image_features.pixel_values
    return encoding
   elif text is not None:
    return encoding
   else:
    return BatchEncoding(data=dict(**_snake_case      )       ,  tensor_type=_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Optional[int]       ,  *_snake_case			:					Union[str, Any]       ,  **_snake_case			:					int      )->Optional[Any]:






   '''simple docstring'''

   return self.tokenizer.batch_decode(*_snake_case       ,  **_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Dict       ,  *_snake_case			:					Dict       ,  **_snake_case			:					Any      )->Dict:






   '''simple docstring'''

   return self.tokenizer.decode(*_snake_case       ,  **_snake_case      )






  @property
  def 				UpperCAmelCase__						(							self			:					Optional[int]      )->str:






   '''simple docstring'''

   __lowerCAmelCase					:	Tuple      =       self.tokenizer.model_input_names
   __lowerCAmelCase					:	Tuple      =       self.image_processor.model_input_names
   return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )






  @property
  def 				UpperCAmelCase__						(							self			:					Dict      )->Union[str, Any]:






   '''simple docstring'''

   warnings.warn(
       """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""       ,  _snake_case       ,  )
   return self.image_processor_class