"""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


UpperCAmelCase__  		=						logging.get_logger(__name__)

UpperCAmelCase__  		=						{
    """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        a				(		lowerCAmelCase_   ):
    _snake_case     :  Optional[Any]     							=							'owlvit_text_model'


    def __init__(					self	:  str   ,				__lowerCAmelCase	:  List[str]=4_9408   ,				__lowerCAmelCase	:  Union[str, Any]=512   ,				__lowerCAmelCase	:  Tuple=2048   ,				__lowerCAmelCase	:  List[str]=12   ,				__lowerCAmelCase	:  int=8   ,				__lowerCAmelCase	:  Optional[int]=16   ,				__lowerCAmelCase	:  Tuple="quick_gelu"   ,				__lowerCAmelCase	:  Dict=1e-5   ,				__lowerCAmelCase	:  Optional[Any]=0.0   ,				__lowerCAmelCase	:  str=0.02   ,				__lowerCAmelCase	:  Any=1.0   ,				__lowerCAmelCase	:  Tuple=0   ,				__lowerCAmelCase	:  Optional[int]=4_9406   ,				__lowerCAmelCase	:  str=4_9407   ,				**__lowerCAmelCase	:  int   ,				):
      super().__init__(pad_token_id=__lowerCAmelCase   ,				bos_token_id=__lowerCAmelCase   ,				eos_token_id=__lowerCAmelCase   ,				**__lowerCAmelCase					)

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


    @classmethod
    def      lowerCAmelCase_  (					cls	:  List[Any]   ,				__lowerCAmelCase	:  Union[str, os.PathLike]   ,				**__lowerCAmelCase	:  Optional[Any]					):
      cls._set_token_in_kwargs(__lowerCAmelCase					)

      _UpperCAmelCase ,				_UpperCAmelCase						 =      cls.get_config_dict(__lowerCAmelCase   ,				**__lowerCAmelCase					)

      # get the text config dict if we are loading from OwlViTConfig
      if config_dict.get("""model_type"""					) == "owlvit":
        _UpperCAmelCase						 =      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        a				(		lowerCAmelCase_   ):
    _snake_case     :  Union[str, Any]     							=							'owlvit_vision_model'


    def __init__(					self	:  List[str]   ,				__lowerCAmelCase	:  Union[str, Any]=768   ,				__lowerCAmelCase	:  Union[str, Any]=3072   ,				__lowerCAmelCase	:  Tuple=12   ,				__lowerCAmelCase	:  List[str]=12   ,				__lowerCAmelCase	:  Any=3   ,				__lowerCAmelCase	:  str=768   ,				__lowerCAmelCase	:  int=32   ,				__lowerCAmelCase	:  Optional[Any]="quick_gelu"   ,				__lowerCAmelCase	:  Tuple=1e-5   ,				__lowerCAmelCase	:  Optional[Any]=0.0   ,				__lowerCAmelCase	:  List[Any]=0.02   ,				__lowerCAmelCase	:  List[Any]=1.0   ,				**__lowerCAmelCase	:  List[str]   ,				):
      super().__init__(**__lowerCAmelCase					)

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


    @classmethod
    def      lowerCAmelCase_  (					cls	:  Dict   ,				__lowerCAmelCase	:  Union[str, os.PathLike]   ,				**__lowerCAmelCase	:  int					):
      cls._set_token_in_kwargs(__lowerCAmelCase					)

      _UpperCAmelCase ,				_UpperCAmelCase						 =      cls.get_config_dict(__lowerCAmelCase   ,				**__lowerCAmelCase					)

      # get the vision config dict if we are loading from OwlViTConfig
      if config_dict.get("""model_type"""					) == "owlvit":
        _UpperCAmelCase						 =      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        a				(		lowerCAmelCase_   ):
    _snake_case     :  Optional[Any]     							=							'owlvit'
    _snake_case     :  List[Any]     							=							True


    def __init__(					self	:  Optional[int]   ,				__lowerCAmelCase	:  int=None   ,				__lowerCAmelCase	:  Optional[Any]=None   ,				__lowerCAmelCase	:  int=512   ,				__lowerCAmelCase	:  Union[str, Any]=2.6_592   ,				__lowerCAmelCase	:  Dict=True   ,				**__lowerCAmelCase	:  Dict   ,				):
      super().__init__(**__lowerCAmelCase					)

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

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

      _UpperCAmelCase						 =      OwlViTTextConfig(**__lowerCAmelCase					)
      _UpperCAmelCase						 =      OwlViTVisionConfig(**__lowerCAmelCase					)

      _UpperCAmelCase						 =      projection_dim
      _UpperCAmelCase						 =      logit_scale_init_value
      _UpperCAmelCase						 =      return_dict
      _UpperCAmelCase						 =      1.0


    @classmethod
    def      lowerCAmelCase_  (					cls	:  Dict   ,				__lowerCAmelCase	:  Union[str, os.PathLike]   ,				**__lowerCAmelCase	:  Optional[Any]					):
      cls._set_token_in_kwargs(__lowerCAmelCase					)

      _UpperCAmelCase ,				_UpperCAmelCase						 =      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      lowerCAmelCase_  (					cls	:  Any   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  Dict   ,				**__lowerCAmelCase	:  Tuple					):
      _UpperCAmelCase						 =      {}
      _UpperCAmelCase						 =      text_config
      _UpperCAmelCase						 =      vision_config

      return cls.from_dict(__lowerCAmelCase   ,				**__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  str					):
      _UpperCAmelCase						 =      copy.deepcopy(self.__dict__					)
      _UpperCAmelCase						 =      self.text_config.to_dict()
      _UpperCAmelCase						 =      self.vision_config.to_dict()
      _UpperCAmelCase						 =      self.__class__.model_type
      return output



class        a				(		lowerCAmelCase_   ):


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


    @property
    def      lowerCAmelCase_  (					self	:  List[str]					):
      return 1e-4


    def      lowerCAmelCase_  (					self	:  Dict   ,				__lowerCAmelCase	:  "ProcessorMixin"   ,				__lowerCAmelCase	:  int = -1   ,				__lowerCAmelCase	:  int = -1   ,				__lowerCAmelCase	:  Optional["TensorType"] = None   ,				):
      _UpperCAmelCase						 =      super().generate_dummy_inputs(
          processor.tokenizer   ,				batch_size=__lowerCAmelCase   ,				seq_length=__lowerCAmelCase   ,				framework=__lowerCAmelCase					)
      _UpperCAmelCase						 =      super().generate_dummy_inputs(
          processor.image_processor   ,				batch_size=__lowerCAmelCase   ,				framework=__lowerCAmelCase					)
      return {**text_input_dict, **image_input_dict}


    @property
    def      lowerCAmelCase_  (					self	:  str					):
      return 14

"""simple docstring"""


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


UpperCAmelCase__  		=						logging.get_logger(__name__)

UpperCAmelCase__  		=						{
    """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				(		lowerCAmelCase_	,							lowerCAmelCase_   ):
    _snake_case     :  Union[str, Any]     							=							'nat'

    _snake_case     :  List[str]     							=							{
        'num_attention_heads': 'num_heads',
        'num_hidden_layers': 'num_layers',
    }


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

      _UpperCAmelCase						 =      patch_size
      _UpperCAmelCase						 =      num_channels
      _UpperCAmelCase						 =      embed_dim
      _UpperCAmelCase						 =      depths
      _UpperCAmelCase						 =      len(__lowerCAmelCase					)
      _UpperCAmelCase						 =      num_heads
      _UpperCAmelCase						 =      kernel_size
      _UpperCAmelCase						 =      mlp_ratio
      _UpperCAmelCase						 =      qkv_bias
      _UpperCAmelCase						 =      hidden_dropout_prob
      _UpperCAmelCase						 =      attention_probs_dropout_prob
      _UpperCAmelCase						 =      drop_path_rate
      _UpperCAmelCase						 =      hidden_act
      _UpperCAmelCase						 =      layer_norm_eps
      _UpperCAmelCase						 =      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
      _UpperCAmelCase						 =      int(embed_dim * 2 ** (len(__lowerCAmelCase					) - 1)					)
      _UpperCAmelCase						 =      layer_scale_init_value
      _UpperCAmelCase						 =      ["""stem"""] + [f'''stage{idx}''' for idx in range(1   ,				len(__lowerCAmelCase					) + 1					)]
      _UpperCAmelCase ,				_UpperCAmelCase						 =      get_aligned_output_features_output_indices(
          out_features=__lowerCAmelCase   ,				out_indices=__lowerCAmelCase   ,				stage_names=self.stage_names					)
