


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


snake_case				:    Tuple       				=     logging.get_logger(__name__)

snake_case				:    Any       				=     {
    '''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  (      _snake_case							):
 SCREAMING_SNAKE_CASE__      =       'owlvit_text_model'




 def __init__(		self					,  _lowerCamelCase=4_9408					,  _lowerCamelCase=512					,  _lowerCamelCase=2048					,  _lowerCamelCase=12					,  _lowerCamelCase=8					,  _lowerCamelCase=16					,  _lowerCamelCase="quick_gelu"					,  _lowerCamelCase=1e-5					,  _lowerCamelCase=0.0					,  _lowerCamelCase=0.02					,  _lowerCamelCase=1.0					,  _lowerCamelCase=0					,  _lowerCamelCase=4_9406					,  _lowerCamelCase=4_9407					,  **_lowerCamelCase					,  ):
       super().__init__(pad_token_id=_lowerCamelCase					,  bos_token_id=_lowerCamelCase					,  eos_token_id=_lowerCamelCase					,  **_lowerCamelCase    )

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




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

       a							,				a						:Optional[Any] 							=       cls.get_config_dict(_lowerCamelCase					,  **_lowerCamelCase    )

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







class 		_snake_case  (      _snake_case							):
 SCREAMING_SNAKE_CASE__      =       'owlvit_vision_model'




 def __init__(		self					,  _lowerCamelCase=768					,  _lowerCamelCase=3072					,  _lowerCamelCase=12					,  _lowerCamelCase=12					,  _lowerCamelCase=3					,  _lowerCamelCase=768					,  _lowerCamelCase=32					,  _lowerCamelCase="quick_gelu"					,  _lowerCamelCase=1e-5					,  _lowerCamelCase=0.0					,  _lowerCamelCase=0.02					,  _lowerCamelCase=1.0					,  **_lowerCamelCase					,  ):
       super().__init__(**_lowerCamelCase    )

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




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

       a							,				a						:List[str] 							=       cls.get_config_dict(_lowerCamelCase					,  **_lowerCamelCase    )

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







class 		_snake_case  (      _snake_case							):
 SCREAMING_SNAKE_CASE__      =       'owlvit'
 SCREAMING_SNAKE_CASE__      =       True




 def __init__(		self					,  _lowerCamelCase=None					,  _lowerCamelCase=None					,  _lowerCamelCase=512					,  _lowerCamelCase=2.6592					,  _lowerCamelCase=True					,  **_lowerCamelCase					,  ):
       super().__init__(**_lowerCamelCase    )

       if text_config is None:
             a						:Dict 							=       {}
             logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.'''    )

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

       a						:Union[str, Any] 							=       OwlViTTextConfig(**_lowerCamelCase    )
       a						:List[Any] 							=       OwlViTVisionConfig(**_lowerCamelCase    )

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




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

       a							,				a						:int 							=       cls.get_config_dict(_lowerCamelCase					,  **_lowerCamelCase    )

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




 @classmethod
 def        SCREAMING_SNAKE_CASE__				(		cls					,  _lowerCamelCase					,  _lowerCamelCase					,  **_lowerCamelCase    ):
       a						:Any 							=       {}
       a						:Union[str, Any] 							=       text_config
       a						:Dict 							=       vision_config

       return cls.from_dict(_lowerCamelCase					,  **_lowerCamelCase    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:List[Any] 							=       copy.deepcopy(self.__dict__    )
       a						:Tuple 							=       self.text_config.to_dict()
       a						:str 							=       self.vision_config.to_dict()
       a						:Dict 							=       self.__class__.model_type
       return output







class 		_snake_case  (      _snake_case							):




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




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




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase = -1					,  _lowerCamelCase = -1					,  _lowerCamelCase = None					,  ):
       a						:List[str] 							=       super().generate_dummy_inputs(
           processor.tokenizer					,  batch_size=_lowerCamelCase					,  seq_length=_lowerCamelCase					,  framework=_lowerCamelCase    )
       a						:Tuple 							=       super().generate_dummy_inputs(
           processor.image_processor					,  batch_size=_lowerCamelCase					,  framework=_lowerCamelCase    )
       return {**text_input_dict, **image_input_dict}




 @property
 def        SCREAMING_SNAKE_CASE__				(		self    ):
       return 14









snake_case				:    str       				=     '''
# Transformers installation
! pip install transformers datasets
# To install from source instead of the last release, comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/transformers.git
'''

snake_case				:    List[Any]       				=     [{'''type''': '''code''', '''content''': INSTALL_CONTENT}]
snake_case				:    int       				=     {
    '''{processor_class}''': '''FakeProcessorClass''',
    '''{model_class}''': '''FakeModelClass''',
    '''{object_class}''': '''FakeObjectClass''',
}





