


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			:  Optional[int]     =logging.get_logger(__name__)

_UpperCAmelCase			:  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 				snake_case__(							UpperCAmelCase__							):







      '''simple docstring'''




      SCREAMING_SNAKE_CASE__      :  Tuple					=							"""owlvit_text_model"""




      def __init__(				self   ,						__lowercase=4_9_4_0_8   ,						__lowercase=5_1_2   ,						__lowercase=2_0_4_8   ,						__lowercase=1_2   ,						__lowercase=8   ,						__lowercase=1_6   ,						__lowercase="quick_gelu"   ,						__lowercase=1e-5   ,						__lowercase=0.0   ,						__lowercase=0.02   ,						__lowercase=1.0   ,						__lowercase=0   ,						__lowercase=4_9_4_0_6   ,						__lowercase=4_9_4_0_7   ,						**__lowercase   ,						)					->    Optional[int]:
          super().__init__(pad_token_id=__A   ,						bos_token_id=__A   ,						eos_token_id=__A   ,						**__A							)

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




      @classmethod
      def 						lowercase_ (				cls   ,						__lowercase   ,						**__lowercase							)					->    Any:
          cls._set_token_in_kwargs(__A							)

          lowerCAmelCase_ :      Optional[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":
              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(__A   ,						**__A							)







class 				snake_case__(							UpperCAmelCase__							):







      '''simple docstring'''




      SCREAMING_SNAKE_CASE__      :  List[str]					=							"""owlvit_vision_model"""




      def __init__(				self   ,						__lowercase=7_6_8   ,						__lowercase=3_0_7_2   ,						__lowercase=1_2   ,						__lowercase=1_2   ,						__lowercase=3   ,						__lowercase=7_6_8   ,						__lowercase=3_2   ,						__lowercase="quick_gelu"   ,						__lowercase=1e-5   ,						__lowercase=0.0   ,						__lowercase=0.02   ,						__lowercase=1.0   ,						**__lowercase   ,						)					->    Any:
          super().__init__(**__A							)

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




      @classmethod
      def 						lowercase_ (				cls   ,						__lowercase   ,						**__lowercase							)					->    Tuple:
          cls._set_token_in_kwargs(__A							)

          lowerCAmelCase_ :      int    				=				cls.get_config_dict(__A   ,						**__A							)

          # get the vision config dict if we are loading from OwlViTConfig
          if config_dict.get('''model_type'''							) == "owlvit":
              lowerCAmelCase_ :      Dict    				=				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 				snake_case__(							UpperCAmelCase__							):







      '''simple docstring'''




      SCREAMING_SNAKE_CASE__      :  Dict					=							"""owlvit"""
      SCREAMING_SNAKE_CASE__      :  Any					=							True




      def __init__(				self   ,						__lowercase=None   ,						__lowercase=None   ,						__lowercase=5_1_2   ,						__lowercase=2.65_92   ,						__lowercase=True   ,						**__lowercase   ,						)					->    str:
          super().__init__(**__A							)

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

          if vision_config is None:
              lowerCAmelCase_ :      List[Any]    				=				{}
              logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.'''							)

          lowerCAmelCase_ :      Any    				=				OwlViTTextConfig(**__A							)
          lowerCAmelCase_ :      str    				=				OwlViTVisionConfig(**__A							)

          lowerCAmelCase_ :      Tuple    				=				projection_dim
          lowerCAmelCase_ :      Union[str, Any]    				=				logit_scale_init_value
          lowerCAmelCase_ :      int    				=				return_dict
          lowerCAmelCase_ :      Optional[int]    				=				1.0




      @classmethod
      def 						lowercase_ (				cls   ,						__lowercase   ,						**__lowercase							)					->    Union[str, Any]:
          cls._set_token_in_kwargs(__A							)

          lowerCAmelCase_ :      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 						lowercase_ (				cls   ,						__lowercase   ,						__lowercase   ,						**__lowercase							)					->    str:
          lowerCAmelCase_ :      List[Any]    				=				{}
          lowerCAmelCase_ :      List[str]    				=				text_config
          lowerCAmelCase_ :      str    				=				vision_config

          return cls.from_dict(__A   ,						**__A							)




      def 						lowercase_ (				self							)					->    Any:
          lowerCAmelCase_ :      int    				=				copy.deepcopy(self.__dict__							)
          lowerCAmelCase_ :      Optional[int]    				=				self.text_config.to_dict()
          lowerCAmelCase_ :      Optional[int]    				=				self.vision_config.to_dict()
          lowerCAmelCase_ :      Dict    				=				self.__class__.model_type
          return output







class 				snake_case__(							UpperCAmelCase__							):







      '''simple docstring'''




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




      @property
      def 						lowercase_ (				self							)					->    Any:
          return 1e-4




      def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = -1   ,						__lowercase = -1   ,						__lowercase = None   ,						)					->    Dict:
          lowerCAmelCase_ :      int    				=				super().generate_dummy_inputs(
              processor.tokenizer   ,						batch_size=__A   ,						seq_length=__A   ,						framework=__A							)
          lowerCAmelCase_ :      List[Any]    				=				super().generate_dummy_inputs(
              processor.image_processor   ,						batch_size=__A   ,						framework=__A							)
          return {**text_input_dict, **image_input_dict}




      @property
      def 						lowercase_ (				self							)					->    Dict:
          return 1_4



import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_UpperCAmelCase			:  str     =logging.get_logger(__name__)







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Optional[int]					=							"""encoder-decoder"""
						SCREAMING_SNAKE_CASE__      :  str					=							True




						def __init__(				self   ,						**__lowercase							)					->    Union[str, Any]:
										super().__init__(**__lowercase							)
										assert (
										    "encoder" in kwargs and "decoder" in kwargs
										), "Config has to be initialized with encoder and decoder config"
										lowerCAmelCase_ :      str    				=				kwargs.pop('''encoder'''							)
										lowerCAmelCase_ :      int    				=				encoder_config.pop('''model_type'''							)
										lowerCAmelCase_ :      Optional[Any]    				=				kwargs.pop('''decoder'''							)
										lowerCAmelCase_ :      Optional[Any]    				=				decoder_config.pop('''model_type'''							)

										from ..auto.configuration_auto import AutoConfig

										lowerCAmelCase_ :      Union[str, Any]    				=				AutoConfig.for_model(__lowercase   ,						**__lowercase							)
										lowerCAmelCase_ :      List[str]    				=				AutoConfig.for_model(__lowercase   ,						**__lowercase							)
										lowerCAmelCase_ :      Any    				=				True




						@classmethod
						def 						lowercase_ (				cls   ,						__lowercase   ,						__lowercase   ,						**__lowercase							)					->    PretrainedConfig:
										logger.info('''Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config'''							)
										lowerCAmelCase_ :      int    				=				True
										lowerCAmelCase_ :      List[Any]    				=				True

										return cls(encoder=encoder_config.to_dict()   ,						decoder=decoder_config.to_dict()   ,						**__lowercase							)




						def 						lowercase_ (				self							)					->    Any:
										lowerCAmelCase_ :      Optional[Any]    				=				copy.deepcopy(self.__dict__							)
										lowerCAmelCase_ :      List[str]    				=				self.encoder.to_dict()
										lowerCAmelCase_ :      Dict    				=				self.decoder.to_dict()
										lowerCAmelCase_ :      Optional[Any]    				=				self.__class__.model_type
										return output