


'''simple docstring'''






import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


__A :  Any    							=				logging.get_logger(__name__)

__A :  Union[str, Any]    							=				{
    "salesforce/blip2-opt-2.7b": "https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json",
}






class        __snake_case	(       _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase       			= 'blip_2_vision_model'

    def __init__(       self   :  List[str]   ,						lowerCamelCase   :  int=14_08   ,						lowerCamelCase   :  str=61_44   ,						lowerCamelCase   :  str=39   ,						lowerCamelCase   :  List[str]=16   ,						lowerCamelCase   :  List[str]=2_24   ,						lowerCamelCase   :  List[Any]=14   ,						lowerCamelCase   :  Dict="gelu"   ,						lowerCamelCase   :  int=0.00_001   ,						lowerCamelCase   :  Optional[int]=0.0   ,						lowerCamelCase   :  Optional[int]=1E-10   ,						lowerCamelCase   :  Dict=True   ,						**lowerCamelCase   :  Optional[Any]   ,						)       ->  int:
      super().__init__(**lowerCamelCase		)

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





    @classmethod
    def __lowercase       (       cls   :  Tuple   ,						lowerCamelCase   :  Union[str, os.PathLike]   ,						**lowerCamelCase   :  Union[str, Any]		)       ->  "PretrainedConfig":
      cls._set_token_in_kwargs(lowerCamelCase		)

      lowerCAmelCase_,							lowerCAmelCase_      :				Optional[Any]      =       cls.get_config_dict(lowerCamelCase   ,						**lowerCamelCase		)

      # get the vision config dict if we are loading from Blip2Config
      if config_dict.get("""model_type"""		) == "blip-2":
        lowerCAmelCase_      :				Union[str, 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(lowerCamelCase   ,						**lowerCamelCase		)







class        __snake_case	(       _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase       			= 'blip_2_qformer'

    def __init__(       self   :  Optional[Any]   ,						lowerCamelCase   :  Optional[Any]=3_05_22   ,						lowerCamelCase   :  List[Any]=7_68   ,						lowerCamelCase   :  Optional[int]=12   ,						lowerCamelCase   :  Tuple=12   ,						lowerCamelCase   :  Union[str, Any]=30_72   ,						lowerCamelCase   :  List[str]="gelu"   ,						lowerCamelCase   :  Tuple=0.1   ,						lowerCamelCase   :  List[Any]=0.1   ,						lowerCamelCase   :  Any=5_12   ,						lowerCamelCase   :  Any=0.02   ,						lowerCamelCase   :  Union[str, Any]=1E-12   ,						lowerCamelCase   :  Tuple=0   ,						lowerCamelCase   :  Dict="absolute"   ,						lowerCamelCase   :  List[Any]=2   ,						lowerCamelCase   :  List[Any]=14_08   ,						**lowerCamelCase   :  str   ,						)       ->  Union[str, Any]:
      super().__init__(pad_token_id=lowerCamelCase   ,						**lowerCamelCase		)

      lowerCAmelCase_      :				str      =       vocab_size
      lowerCAmelCase_      :				Dict      =       hidden_size
      lowerCAmelCase_      :				str      =       num_hidden_layers
      lowerCAmelCase_      :				Tuple      =       num_attention_heads
      lowerCAmelCase_      :				Any      =       hidden_act
      lowerCAmelCase_      :				Optional[Any]      =       intermediate_size
      lowerCAmelCase_      :				Dict      =       hidden_dropout_prob
      lowerCAmelCase_      :				Any      =       attention_probs_dropout_prob
      lowerCAmelCase_      :				Optional[Any]      =       max_position_embeddings
      lowerCAmelCase_      :				List[Any]      =       initializer_range
      lowerCAmelCase_      :				Any      =       layer_norm_eps
      lowerCAmelCase_      :				Tuple      =       position_embedding_type
      lowerCAmelCase_      :				Optional[int]      =       cross_attention_frequency
      lowerCAmelCase_      :				Optional[Any]      =       encoder_hidden_size





    @classmethod
    def __lowercase       (       cls   :  Dict   ,						lowerCamelCase   :  Union[str, os.PathLike]   ,						**lowerCamelCase   :  Any		)       ->  "PretrainedConfig":
      cls._set_token_in_kwargs(lowerCamelCase		)

      lowerCAmelCase_,							lowerCAmelCase_      :				Optional[int]      =       cls.get_config_dict(lowerCamelCase   ,						**lowerCamelCase		)

      # get the qformer config dict if we are loading from Blip2Config
      if config_dict.get("""model_type"""		) == "blip-2":
        lowerCAmelCase_      :				Optional[Any]      =       config_dict["""qformer_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	(       _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase       			= 'blip-2'
    lowercase       			= True

    def __init__(       self   :  Union[str, Any]   ,						lowerCamelCase   :  Any=None   ,						lowerCamelCase   :  List[str]=None   ,						lowerCamelCase   :  List[Any]=None   ,						lowerCamelCase   :  Dict=32   ,						**lowerCamelCase   :  List[str]		)       ->  Union[str, Any]:
      super().__init__(**lowerCamelCase		)

      if vision_config is None:
        lowerCAmelCase_      :				List[str]      =       {}
        logger.info("""vision_config is None. initializing the Blip2VisionConfig with default values."""		)

      if qformer_config is None:
        lowerCAmelCase_      :				Any      =       {}
        logger.info("""qformer_config is None. Initializing the Blip2QFormerConfig with default values."""		)

      if text_config is None:
        lowerCAmelCase_      :				Union[str, Any]      =       {}
        logger.info("""text_config is None. Initializing the text config with default values (`OPTConfig`)."""		)

      lowerCAmelCase_      :				Optional[int]      =       BlipaVisionConfig(**lowerCamelCase		)
      lowerCAmelCase_      :				List[str]      =       BlipaQFormerConfig(**lowerCamelCase		)
      lowerCAmelCase_      :				List[str]      =       text_config["""model_type"""] if """model_type""" in text_config else """opt"""
      lowerCAmelCase_      :				List[str]      =       CONFIG_MAPPING[text_model_type](**lowerCamelCase		)

      lowerCAmelCase_      :				Union[str, Any]      =       self.text_config.tie_word_embeddings
      lowerCAmelCase_      :				Dict      =       self.text_config.is_encoder_decoder

      lowerCAmelCase_      :				Union[str, Any]      =       num_query_tokens
      lowerCAmelCase_      :				List[Any]      =       self.vision_config.hidden_size
      lowerCAmelCase_      :				int      =       self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
      lowerCAmelCase_      :				str      =       1.0
      lowerCAmelCase_      :				str      =       0.02

    @classmethod
    def __lowercase       (       cls   :  int   ,						lowerCamelCase   :  BlipaVisionConfig   ,						lowerCamelCase   :  BlipaQFormerConfig   ,						lowerCamelCase   :  PretrainedConfig   ,						**lowerCamelCase   :  Any   ,						)       ->  List[str]:
      return cls(
          vision_config=vision_config.to_dict()   ,						qformer_config=qformer_config.to_dict()   ,						text_config=text_config.to_dict()   ,						**lowerCamelCase   ,						)





    def __lowercase       (       self   :  List[str]		)       ->  int:
      lowerCAmelCase_      :				Union[str, Any]      =       copy.deepcopy(self.__dict__		)
      lowerCAmelCase_      :				Union[str, Any]      =       self.vision_config.to_dict()
      lowerCAmelCase_      :				Optional[Any]      =       self.qformer_config.to_dict()
      lowerCAmelCase_      :				Dict      =       self.text_config.to_dict()
      lowerCAmelCase_      :				Optional[int]      =       self.__class__.model_type
      return output







'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__A :  List[str]    							=				{
    "configuration_owlvit": [
        "OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "OwlViTConfig",
        "OwlViTOnnxConfig",
        "OwlViTTextConfig",
        "OwlViTVisionConfig",
    ],
    "processing_owlvit": ["OwlViTProcessor"],
}


try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A :  Optional[int]    							=				["OwlViTFeatureExtractor"]
  __A :  str    							=				["OwlViTImageProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A :  Tuple    							=				[
      "OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "OwlViTModel",
      "OwlViTPreTrainedModel",
      "OwlViTTextModel",
      "OwlViTVisionModel",
      "OwlViTForObjectDetection",
  ]

if TYPE_CHECKING:
  from .configuration_owlvit import (
      OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
      OwlViTConfig,
      OwlViTOnnxConfig,
      OwlViTTextConfig,
      OwlViTVisionConfig,
  )
  from .processing_owlvit import OwlViTProcessor

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_owlvit import OwlViTFeatureExtractor
    from .image_processing_owlvit import OwlViTImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_owlvit import (
        OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
        OwlViTForObjectDetection,
        OwlViTModel,
        OwlViTPreTrainedModel,
        OwlViTTextModel,
        OwlViTVisionModel,
    )

else:
  import sys

  __A :  List[Any]    							=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



