





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

lowerCAmelCase_						   =    {
    '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        _lowerCAmelCase    (			__lowercase							):


  '''simple docstring'''
  a_							:       int      					="""owlvit_text_model"""







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


    '''simple docstring'''





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

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







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


    '''simple docstring'''





    cls._set_token_in_kwargs(UpperCamelCase							)

    _snake_case   :				List[str]														=	cls.get_config_dict(UpperCamelCase      ,				**UpperCamelCase							)

    # get the text config dict if we are loading from OwlViTConfig
    if config_dict.get('model_type'							) == "owlvit":
      _snake_case   :				Any														=	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        _lowerCAmelCase    (			__lowercase							):


  '''simple docstring'''
  a_							:       str      					="""owlvit_vision_model"""







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


    '''simple docstring'''





    super().__init__(**UpperCamelCase							)

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







  @classmethod
  def UpperCamelCase_ (      cls      :					List[str]      ,				UpperCamelCase      :					Union[str, os.PathLike]      ,				**UpperCamelCase      :					Union[str, Any]							):


    '''simple docstring'''





    cls._set_token_in_kwargs(UpperCamelCase							)

    _snake_case   :				Union[str, Any]														=	cls.get_config_dict(UpperCamelCase      ,				**UpperCamelCase							)

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




class        _lowerCAmelCase    (			__lowercase							):


  '''simple docstring'''
  a_							:       Tuple      					="""owlvit"""
  a_							:       List[str]      					=True







  def __init__(      self      :					str      ,				UpperCamelCase      :					Optional[int]=None      ,				UpperCamelCase      :					List[str]=None      ,				UpperCamelCase      :					Tuple=5_12      ,				UpperCamelCase      :					Union[str, Any]=2.65_92      ,				UpperCamelCase      :					str=True      ,				**UpperCamelCase      :					int      ,				):


    '''simple docstring'''





    super().__init__(**UpperCamelCase							)

    if text_config is None:
      _snake_case   :				Union[str, Any]														=	{}
      logger.info('text_config is None. Initializing the OwlViTTextConfig with default values.'							)

    if vision_config is None:
      _snake_case   :				str														=	{}
      logger.info('vision_config is None. initializing the OwlViTVisionConfig with default values.'							)

    _snake_case   :				List[str]														=	OwlViTTextConfig(**UpperCamelCase							)
    _snake_case   :				str														=	OwlViTVisionConfig(**UpperCamelCase							)

    _snake_case   :				Tuple														=	projection_dim
    _snake_case   :				int														=	logit_scale_init_value
    _snake_case   :				List[str]														=	return_dict
    _snake_case   :				Optional[int]														=	1.0







  @classmethod
  def UpperCamelCase_ (      cls      :					Optional[Any]      ,				UpperCamelCase      :					Union[str, os.PathLike]      ,				**UpperCamelCase      :					List[Any]							):


    '''simple docstring'''





    cls._set_token_in_kwargs(UpperCamelCase							)

    _snake_case   :				Optional[Any]														=	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 UpperCamelCase_ (      cls      :					Union[str, Any]      ,				UpperCamelCase      :					Dict      ,				UpperCamelCase      :					Dict      ,				**UpperCamelCase      :					List[Any]							):


    '''simple docstring'''





    _snake_case   :				List[str]														=	{}
    _snake_case   :				List[str]														=	text_config
    _snake_case   :				str														=	vision_config

    return cls.from_dict(UpperCamelCase      ,				**UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Optional[Any]							):


    '''simple docstring'''





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




class        _lowerCAmelCase    (			__lowercase							):


  '''simple docstring'''







  @property
  def UpperCamelCase_ (      self      :					List[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      :					List[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      :					int							):


    '''simple docstring'''





    return 1e-4







  def UpperCamelCase_ (      self      :					Tuple      ,				UpperCamelCase      :					"ProcessorMixin"      ,				UpperCamelCase      :					int = -1      ,				UpperCamelCase      :					int = -1      ,				UpperCamelCase      :					Optional["TensorType"] = None      ,				):


    '''simple docstring'''





    _snake_case   :				Dict														=	super().generate_dummy_inputs(
        processor.tokenizer      ,				batch_size=UpperCamelCase      ,				seq_length=UpperCamelCase      ,				framework=UpperCamelCase							)
    _snake_case   :				List[Any]														=	super().generate_dummy_inputs(
        processor.image_processor      ,				batch_size=UpperCamelCase      ,				framework=UpperCamelCase							)
    return {**text_input_dict, **image_input_dict}







  @property
  def UpperCamelCase_ (      self      :					str							):


    '''simple docstring'''





    return 14











def     lowerCamelCase_	(      lowerCAmelCase:	bytes				)->		str:
  return "".join([hex(lowerCAmelCase				)[2:].zfill(2				).upper() for byte in list(lowerCAmelCase				)]				)


def     lowerCamelCase_	(      lowerCAmelCase:	str				)->		bytes:
  # Check data validity, following RFC3548
  # https://www.ietf.org/rfc/rfc3548.txt
  if (len(lowerCAmelCase				) % 2) != 0:
    raise ValueError(
        'Base16 encoded data is invalid:\nData does not have an even number of hex digits.'				)
  # Check the character set - the standard base16 alphabet
  # is uppercase according to RFC3548 section 6
  if not set(lowerCAmelCase				) <= set('0123456789ABCDEF'				):
    raise ValueError(
        'Base16 encoded data is invalid:\nData is not uppercase hex or it contains invalid characters.'				)
  # For every two hexadecimal digits (= a byte), turn it into an integer.
  # Then, string the result together into bytes, and return it.
  return bytes(int(data[i] + data[i + 1]    ,							16				) for i in range(0    ,							len(lowerCAmelCase				)    ,							2				)				)


if __name__ == "__main__":
      import doctest

      doctest.testmod()




