





'''simple docstring'''






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

A__							:  Tuple    ={
    """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 					UpperCAmelCase	(     a_  ):
      _lowercase:     Tuple			=  '''owlvit_text_model'''




      def __init__(     self     :					List[str]     ,     __snake_case     :					Union[str, Any]=4_94_08     ,     __snake_case     :					List[Any]=5_12     ,     __snake_case     :					Optional[Any]=20_48     ,     __snake_case     :					Optional[int]=12     ,     __snake_case     :					Tuple=8     ,     __snake_case     :					Optional[Any]=16     ,     __snake_case     :					Tuple="quick_gelu"     ,     __snake_case     :					Union[str, Any]=1E-5     ,     __snake_case     :					Any=0.0     ,     __snake_case     :					List[str]=0.02     ,     __snake_case     :					int=1.0     ,     __snake_case     :					int=0     ,     __snake_case     :					Optional[Any]=4_94_06     ,     __snake_case     :					Optional[Any]=4_94_07     ,     **__snake_case     :					Union[str, Any]     ,     )							-> int:
            super().__init__(pad_token_id=__SCREAMING_SNAKE_CASE     ,     bos_token_id=__SCREAMING_SNAKE_CASE     ,     eos_token_id=__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE    )

            _lowerCAmelCase					=				vocab_size
            _lowerCAmelCase					=				hidden_size
            _lowerCAmelCase					=				intermediate_size
            _lowerCAmelCase					=				num_hidden_layers
            _lowerCAmelCase					=				num_attention_heads
            _lowerCAmelCase					=				max_position_embeddings
            _lowerCAmelCase					=				hidden_act
            _lowerCAmelCase					=				layer_norm_eps
            _lowerCAmelCase					=				attention_dropout
            _lowerCAmelCase					=				initializer_range
            _lowerCAmelCase					=				initializer_factor




      @classmethod
      def 							lowercase__       (     cls     :					int     ,     __snake_case     :					Union[str, os.PathLike]     ,     **__snake_case     :					Optional[int]    )							-> int:
            cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE    )

            _lowerCAmelCase	,				_lowerCAmelCase					=				cls.get_config_dict(__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE    )

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




class 					UpperCAmelCase	(     a_  ):
      _lowercase:     Tuple			=  '''owlvit_vision_model'''




      def __init__(     self     :					List[str]     ,     __snake_case     :					Optional[Any]=7_68     ,     __snake_case     :					Any=30_72     ,     __snake_case     :					str=12     ,     __snake_case     :					int=12     ,     __snake_case     :					str=3     ,     __snake_case     :					Optional[Any]=7_68     ,     __snake_case     :					List[Any]=32     ,     __snake_case     :					Dict="quick_gelu"     ,     __snake_case     :					List[Any]=1E-5     ,     __snake_case     :					int=0.0     ,     __snake_case     :					Optional[Any]=0.02     ,     __snake_case     :					Dict=1.0     ,     **__snake_case     :					Optional[int]     ,     )							-> List[str]:
            super().__init__(**__SCREAMING_SNAKE_CASE    )

            _lowerCAmelCase					=				hidden_size
            _lowerCAmelCase					=				intermediate_size
            _lowerCAmelCase					=				num_hidden_layers
            _lowerCAmelCase					=				num_attention_heads
            _lowerCAmelCase					=				num_channels
            _lowerCAmelCase					=				image_size
            _lowerCAmelCase					=				patch_size
            _lowerCAmelCase					=				hidden_act
            _lowerCAmelCase					=				layer_norm_eps
            _lowerCAmelCase					=				attention_dropout
            _lowerCAmelCase					=				initializer_range
            _lowerCAmelCase					=				initializer_factor




      @classmethod
      def 							lowercase__       (     cls     :					List[str]     ,     __snake_case     :					Union[str, os.PathLike]     ,     **__snake_case     :					Tuple    )							-> Union[str, Any]:
            cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE    )

            _lowerCAmelCase	,				_lowerCAmelCase					=				cls.get_config_dict(__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE    )

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




class 					UpperCAmelCase	(     a_  ):
      _lowercase:     Any			=  '''owlvit'''
      _lowercase:     Union[str, Any]			=  True




      def __init__(     self     :					Dict     ,     __snake_case     :					Optional[int]=None     ,     __snake_case     :					Tuple=None     ,     __snake_case     :					str=5_12     ,     __snake_case     :					List[Any]=2.65_92     ,     __snake_case     :					Dict=True     ,     **__snake_case     :					List[Any]     ,     )							-> Dict:
            super().__init__(**__SCREAMING_SNAKE_CASE    )

            if text_config is None:
                  _lowerCAmelCase					=				{}
                  logger.info("""text_config is None. Initializing the OwlViTTextConfig with default values."""    )

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

            _lowerCAmelCase					=				OwlViTTextConfig(**__SCREAMING_SNAKE_CASE    )
            _lowerCAmelCase					=				OwlViTVisionConfig(**__SCREAMING_SNAKE_CASE    )

            _lowerCAmelCase					=				projection_dim
            _lowerCAmelCase					=				logit_scale_init_value
            _lowerCAmelCase					=				return_dict
            _lowerCAmelCase					=				1.0




      @classmethod
      def 							lowercase__       (     cls     :					Tuple     ,     __snake_case     :					Union[str, os.PathLike]     ,     **__snake_case     :					List[str]    )							-> Any:
            cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE    )

            _lowerCAmelCase	,				_lowerCAmelCase					=				cls.get_config_dict(__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_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(__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE    )




      @classmethod
      def 							lowercase__       (     cls     :					List[Any]     ,     __snake_case     :					Dict     ,     __snake_case     :					Dict     ,     **__snake_case     :					Optional[Any]    )							-> Union[str, Any]:
            _lowerCAmelCase					=				{}
            _lowerCAmelCase					=				text_config
            _lowerCAmelCase					=				vision_config

            return cls.from_dict(__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_SNAKE_CASE    )




      def 							lowercase__       (     self     :					Optional[Any]    )							-> Any:
            _lowerCAmelCase					=				copy.deepcopy(self.__dict__    )
            _lowerCAmelCase					=				self.text_config.to_dict()
            _lowerCAmelCase					=				self.vision_config.to_dict()
            _lowerCAmelCase					=				self.__class__.model_type
            return output




class 					UpperCAmelCase	(     a_  ):




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




      @property
      def 							lowercase__       (     self     :					str    )							-> Dict:
            return 1E-4




      def 							lowercase__       (     self     :					Any     ,     __snake_case     :					"ProcessorMixin"     ,     __snake_case     :					int = -1     ,     __snake_case     :					int = -1     ,     __snake_case     :					Optional["TensorType"] = None     ,     )							-> Tuple:
            _lowerCAmelCase					=				super().generate_dummy_inputs(
                processor.tokenizer     ,     batch_size=__SCREAMING_SNAKE_CASE     ,     seq_length=__SCREAMING_SNAKE_CASE     ,     framework=__SCREAMING_SNAKE_CASE    )
            _lowerCAmelCase					=				super().generate_dummy_inputs(
                processor.image_processor     ,     batch_size=__SCREAMING_SNAKE_CASE     ,     framework=__SCREAMING_SNAKE_CASE    )
            return {**text_input_dict, **image_input_dict}




      @property
      def 							lowercase__       (     self     :					Optional[int]    )							-> Tuple:
            return 14







from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


SCREAMING_SNAKE_CASE			:						Optional[Any]				  =		logging.get_logger(__name__)

SCREAMING_SNAKE_CASE			:						List[Any]				  =		{
    """shi-labs/nat-mini-in1k-224""": """https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json""",
    # See all Nat models at https://huggingface.co/models?filter=nat
}
class  A_			(							a_      ,							a_			):
  _SCREAMING_SNAKE_CASE     					=      """nat"""

  _SCREAMING_SNAKE_CASE     					=      {
      """num_attention_heads""": """num_heads""",
      """num_hidden_layers""": """num_layers""",
  }

  def __init__(		self			:   str  ,				__SCREAMING_SNAKE_CASE			:   Tuple=4  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=3  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=64  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=[3, 4, 6, 5]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=[2, 4, 8, 16]  ,				__SCREAMING_SNAKE_CASE			:   int=7  ,				__SCREAMING_SNAKE_CASE			:   List[str]=3.0  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=True  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=0.0  ,				__SCREAMING_SNAKE_CASE			:   str=0.0  ,				__SCREAMING_SNAKE_CASE			:   int=0.1  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=0.02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=1E-5  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=0.0  ,				__SCREAMING_SNAKE_CASE			:   str=None  ,				__SCREAMING_SNAKE_CASE			:   int=None  ,				**__SCREAMING_SNAKE_CASE			:   List[str]  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   __a							=	patch_size
   __a							=	num_channels
   __a							=	embed_dim
   __a							=	depths
   __a							=	len(__SCREAMING_SNAKE_CASE							)
   __a							=	num_heads
   __a							=	kernel_size
   __a							=	mlp_ratio
   __a							=	qkv_bias
   __a							=	hidden_dropout_prob
   __a							=	attention_probs_dropout_prob
   __a							=	drop_path_rate
   __a							=	hidden_act
   __a							=	layer_norm_eps
   __a							=	initializer_range
   # we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
   # this indicates the channel dimension after the last stage of the model
   __a							=	int(embed_dim * 2 ** (len(__SCREAMING_SNAKE_CASE							) - 1)							)
   __a							=	layer_scale_init_value
   __a							=	["stem"] + [f"""stage{idx}""" for idx in range(1  ,				len(__SCREAMING_SNAKE_CASE							) + 1							)]
   __a							,  __a							=	get_aligned_output_features_output_indices(
       out_features=__SCREAMING_SNAKE_CASE  ,				out_indices=__SCREAMING_SNAKE_CASE  ,				stage_names=self.stage_names							)


