






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

A_						:						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 							_lowerCAmelCase(			_lowercase   ):





       """simple docstring"""







       a							:						Any										='''owlvit_text_model'''





       def __init__(   self    ,     _lowerCamelCase=4_9_4_0_8    ,     _lowerCamelCase=5_1_2    ,     _lowerCamelCase=2_0_4_8    ,     _lowerCamelCase=1_2    ,     _lowerCamelCase=8    ,     _lowerCamelCase=1_6    ,     _lowerCamelCase="quick_gelu"    ,     _lowerCamelCase=1e-5    ,     _lowerCamelCase=0.0    ,     _lowerCamelCase=0.0_2    ,     _lowerCamelCase=1.0    ,     _lowerCamelCase=0    ,     _lowerCamelCase=4_9_4_0_6    ,     _lowerCamelCase=4_9_4_0_7    ,     **_lowerCamelCase    ,     ):
         super().__init__(pad_token_id=A_    ,     bos_token_id=A_    ,     eos_token_id=A_    ,     **A_				)

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





       @classmethod
       def      _a       (   cls    ,     _lowerCamelCase    ,     **_lowerCamelCase				):
         cls._set_token_in_kwargs(A_				)

         UpperCamelCase_ ,UpperCamelCase_:   Any        =							cls.get_config_dict(A_    ,     **A_				)

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







class 							_lowerCAmelCase(			_lowercase   ):





       """simple docstring"""







       a							:						List[Any]										='''owlvit_vision_model'''





       def __init__(   self    ,     _lowerCamelCase=7_6_8    ,     _lowerCamelCase=3_0_7_2    ,     _lowerCamelCase=1_2    ,     _lowerCamelCase=1_2    ,     _lowerCamelCase=3    ,     _lowerCamelCase=7_6_8    ,     _lowerCamelCase=3_2    ,     _lowerCamelCase="quick_gelu"    ,     _lowerCamelCase=1e-5    ,     _lowerCamelCase=0.0    ,     _lowerCamelCase=0.0_2    ,     _lowerCamelCase=1.0    ,     **_lowerCamelCase    ,     ):
         super().__init__(**A_				)

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





       @classmethod
       def      _a       (   cls    ,     _lowerCamelCase    ,     **_lowerCamelCase				):
         cls._set_token_in_kwargs(A_				)

         UpperCamelCase_ ,UpperCamelCase_:   Any        =							cls.get_config_dict(A_    ,     **A_				)

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







class 							_lowerCAmelCase(			_lowercase   ):





       """simple docstring"""







       a							:						Optional[Any]										='''owlvit'''
       a							:						List[str]										=True





       def __init__(   self    ,     _lowerCamelCase=None    ,     _lowerCamelCase=None    ,     _lowerCamelCase=5_1_2    ,     _lowerCamelCase=2.6_5_9_2    ,     _lowerCamelCase=True    ,     **_lowerCamelCase    ,     ):
         super().__init__(**A_				)

         if text_config is None:
           UpperCamelCase_:   Optional[Any]        =							{}
           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_:   Optional[Any]        =							OwlViTTextConfig(**A_				)
         UpperCamelCase_:   List[Any]        =							OwlViTVisionConfig(**A_				)

         UpperCamelCase_:   Union[str, Any]        =							projection_dim
         UpperCamelCase_:   List[str]        =							logit_scale_init_value
         UpperCamelCase_:   Any        =							return_dict
         UpperCamelCase_:   Optional[int]        =							1.0





       @classmethod
       def      _a       (   cls    ,     _lowerCamelCase    ,     **_lowerCamelCase				):
         cls._set_token_in_kwargs(A_				)

         UpperCamelCase_ ,UpperCamelCase_:   Optional[Any]        =							cls.get_config_dict(A_    ,     **A_				)

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





       @classmethod
       def      _a       (   cls    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     **_lowerCamelCase				):
         UpperCamelCase_:   Any        =							{}
         UpperCamelCase_:   Tuple        =							text_config
         UpperCamelCase_:   Dict        =							vision_config

         return cls.from_dict(A_    ,     **A_				)





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







class 							_lowerCAmelCase(			_lowercase   ):





       """simple docstring"""







       @property
       def      _a       (   self				):
         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				):
         return OrderedDict(
             [
                 ('logits_per_image', {0: 'batch'}),
                 ('logits_per_text', {0: 'batch'}),
                 ('text_embeds', {0: 'batch'}),
                 ('image_embeds', {0: 'batch'}),
             ]				)





       @property
       def      _a       (   self				):
         return 1e-4





       def      _a       (   self    ,     _lowerCamelCase    ,     _lowerCamelCase = -1    ,     _lowerCamelCase = -1    ,     _lowerCamelCase = None    ,     ):
         UpperCamelCase_:   Optional[Any]        =							super().generate_dummy_inputs(
             processor.tokenizer    ,     batch_size=A_    ,     seq_length=A_    ,     framework=A_				)
         UpperCamelCase_:   Any        =							super().generate_dummy_inputs(
             processor.image_processor    ,     batch_size=A_    ,     framework=A_				)
         return {**text_input_dict, **image_input_dict}





       @property
       def      _a       (   self				):
         return 1_4

"""simple docstring"""


from torch import nn






def    _snake_case					(		snake_case__ :  Union[str, Any]  ):
	if act_fn in ["swish", "silu"]:
		return nn.SiLU()
	elif act_fn == "mish":
		return nn.Mish()
	elif act_fn == "gelu":
		return nn.GELU()
	else:
		raise ValueError(F'Unsupported activation function: {act_fn}'  )