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


UpperCamelCase			:       Optional[int]									=				logging.get_logger(__name__)

UpperCamelCase			:       int									=				{
    "salesforce/blip2-opt-2.7b": "https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json",
}

class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ):
     lowercase		     =		"blip_2_vision_model"





     def __init__(			self			,  __UpperCAmelCase=1408			,  __UpperCAmelCase=6144			,  __UpperCAmelCase=39			,  __UpperCAmelCase=16			,  __UpperCAmelCase=224			,  __UpperCAmelCase=14			,  __UpperCAmelCase="gelu"			,  __UpperCAmelCase=0.0_0_0_0_1			,  __UpperCAmelCase=0.0			,  __UpperCAmelCase=1E-10			,  __UpperCAmelCase=True			,  **__UpperCAmelCase			,  ):

      '''simple docstring'''




      super().__init__(**__UpperCAmelCase   )

      __UpperCamelCase       						= hidden_size
      __UpperCamelCase       						= intermediate_size
      __UpperCamelCase       						= num_hidden_layers
      __UpperCamelCase       						= num_attention_heads
      __UpperCamelCase       						= patch_size
      __UpperCamelCase       						= image_size
      __UpperCamelCase       						= initializer_range
      __UpperCamelCase       						= attention_dropout
      __UpperCamelCase       						= layer_norm_eps
      __UpperCamelCase       						= hidden_act
      __UpperCamelCase       						= qkv_bias







     @classmethod
     def 		UpperCAmelCase      (			cls			,  __UpperCAmelCase			,  **__UpperCAmelCase   ):

      '''simple docstring'''




      cls._set_token_in_kwargs(__UpperCAmelCase   )

      __UpperCamelCase						,			__UpperCamelCase       						= cls.get_config_dict(__UpperCAmelCase			,  **__UpperCAmelCase   )

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


class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ):
     lowercase		     =		"blip_2_qformer"





     def __init__(			self			,  __UpperCAmelCase=3_0522			,  __UpperCAmelCase=768			,  __UpperCAmelCase=12			,  __UpperCAmelCase=12			,  __UpperCAmelCase=3072			,  __UpperCAmelCase="gelu"			,  __UpperCAmelCase=0.1			,  __UpperCAmelCase=0.1			,  __UpperCAmelCase=512			,  __UpperCAmelCase=0.0_2			,  __UpperCAmelCase=1E-12			,  __UpperCAmelCase=0			,  __UpperCAmelCase="absolute"			,  __UpperCAmelCase=2			,  __UpperCAmelCase=1408			,  **__UpperCAmelCase			,  ):

      '''simple docstring'''




      super().__init__(pad_token_id=__UpperCAmelCase			,  **__UpperCAmelCase   )

      __UpperCamelCase       						= vocab_size
      __UpperCamelCase       						= hidden_size
      __UpperCamelCase       						= num_hidden_layers
      __UpperCamelCase       						= num_attention_heads
      __UpperCamelCase       						= hidden_act
      __UpperCamelCase       						= intermediate_size
      __UpperCamelCase       						= hidden_dropout_prob
      __UpperCamelCase       						= attention_probs_dropout_prob
      __UpperCamelCase       						= max_position_embeddings
      __UpperCamelCase       						= initializer_range
      __UpperCamelCase       						= layer_norm_eps
      __UpperCamelCase       						= position_embedding_type
      __UpperCamelCase       						= cross_attention_frequency
      __UpperCamelCase       						= encoder_hidden_size







     @classmethod
     def 		UpperCAmelCase      (			cls			,  __UpperCAmelCase			,  **__UpperCAmelCase   ):

      '''simple docstring'''




      cls._set_token_in_kwargs(__UpperCAmelCase   )

      __UpperCamelCase						,			__UpperCamelCase       						= cls.get_config_dict(__UpperCAmelCase			,  **__UpperCAmelCase   )

      # get the qformer config dict if we are loading from Blip2Config
      if config_dict.get('model_type'   ) == "blip-2":
       __UpperCamelCase       						= 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(__UpperCAmelCase			,  **__UpperCAmelCase   )


class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ):
     lowercase		     =		"blip-2"
     lowercase		     =		True





     def __init__(			self			,  __UpperCAmelCase=None			,  __UpperCAmelCase=None			,  __UpperCAmelCase=None			,  __UpperCAmelCase=32			,  **__UpperCAmelCase   ):

      '''simple docstring'''




      super().__init__(**__UpperCAmelCase   )

      if vision_config is None:
       __UpperCamelCase       						= {}
       logger.info('vision_config is None. initializing the Blip2VisionConfig with default values.'   )

      if qformer_config is None:
       __UpperCamelCase       						= {}
       logger.info('qformer_config is None. Initializing the Blip2QFormerConfig with default values.'   )

      if text_config is None:
       __UpperCamelCase       						= {}
       logger.info('text_config is None. Initializing the text config with default values (`OPTConfig`).'   )

      __UpperCamelCase       						= BlipaVisionConfig(**__UpperCAmelCase   )
      __UpperCamelCase       						= BlipaQFormerConfig(**__UpperCAmelCase   )
      __UpperCamelCase       						= text_config['model_type'] if 'model_type' in text_config else 'opt'
      __UpperCamelCase       						= CONFIG_MAPPING[text_model_type](**__UpperCAmelCase   )

      __UpperCamelCase       						= self.text_config.tie_word_embeddings
      __UpperCamelCase       						= self.text_config.is_encoder_decoder

      __UpperCamelCase       						= num_query_tokens
      __UpperCamelCase       						= self.vision_config.hidden_size
      __UpperCamelCase       						= self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
      __UpperCamelCase       						= 1.0
      __UpperCamelCase       						= 0.0_2





     @classmethod
     def 		UpperCAmelCase      (			cls			,  __UpperCAmelCase			,  __UpperCAmelCase			,  __UpperCAmelCase			,  **__UpperCAmelCase			,  ):

      '''simple docstring'''




      return cls(
          vision_config=vision_config.to_dict()			,  qformer_config=qformer_config.to_dict()			,  text_config=text_config.to_dict()			,  **__UpperCAmelCase			,  )







     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= copy.deepcopy(self.__dict__   )
      __UpperCamelCase       						= self.vision_config.to_dict()
      __UpperCamelCase       						= self.qformer_config.to_dict()
      __UpperCamelCase       						= self.text_config.to_dict()
      __UpperCamelCase       						= self.__class__.model_type
      return output





"""simple docstring"""

from typing import List

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


UpperCamelCase			:       Tuple									=				logging.get_logger(__name__)

UpperCamelCase			:       List[str]									=				{
    "snap-research/efficientformer-l1-300": (
        "https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json"
    ),
}

class __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ):
     lowercase		     =		"efficientformer"





     def __init__(			self			,  __UpperCAmelCase = [3, 2, 6, 4]			,  __UpperCAmelCase = [48, 96, 224, 448]			,  __UpperCAmelCase = [True, True, True, True]			,  __UpperCAmelCase = 448			,  __UpperCAmelCase = 32			,  __UpperCAmelCase = 4			,  __UpperCAmelCase = 7			,  __UpperCAmelCase = 5			,  __UpperCAmelCase = 8			,  __UpperCAmelCase = 4			,  __UpperCAmelCase = 0.0			,  __UpperCAmelCase = 16			,  __UpperCAmelCase = 3			,  __UpperCAmelCase = 3			,  __UpperCAmelCase = 3			,  __UpperCAmelCase = 2			,  __UpperCAmelCase = 1			,  __UpperCAmelCase = 0.0			,  __UpperCAmelCase = 1			,  __UpperCAmelCase = True			,  __UpperCAmelCase = True			,  __UpperCAmelCase = 1E-5			,  __UpperCAmelCase = "gelu"			,  __UpperCAmelCase = 0.0_2			,  __UpperCAmelCase = 1E-12			,  __UpperCAmelCase = 224			,  __UpperCAmelCase = 1E-05			,  **__UpperCAmelCase			,  ):

      '''simple docstring'''




      super().__init__(**__UpperCAmelCase   )

      __UpperCamelCase       						= hidden_act
      __UpperCamelCase       						= hidden_dropout_prob
      __UpperCamelCase       						= hidden_sizes
      __UpperCamelCase       						= num_hidden_layers
      __UpperCamelCase       						= num_attention_heads
      __UpperCamelCase       						= initializer_range
      __UpperCamelCase       						= layer_norm_eps
      __UpperCamelCase       						= patch_size
      __UpperCamelCase       						= num_channels
      __UpperCamelCase       						= depths
      __UpperCamelCase       						= mlp_expansion_ratio
      __UpperCamelCase       						= downsamples
      __UpperCamelCase       						= dim
      __UpperCamelCase       						= key_dim
      __UpperCamelCase       						= attention_ratio
      __UpperCamelCase       						= resolution
      __UpperCamelCase       						= pool_size
      __UpperCamelCase       						= downsample_patch_size
      __UpperCamelCase       						= downsample_stride
      __UpperCamelCase       						= downsample_pad
      __UpperCamelCase       						= drop_path_rate
      __UpperCamelCase       						= num_metaad_blocks
      __UpperCamelCase       						= distillation
      __UpperCamelCase       						= use_layer_scale
      __UpperCamelCase       						= layer_scale_init_value
      __UpperCamelCase       						= image_size
      __UpperCamelCase       						= batch_norm_eps



