


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

a_ :List[str]  							=			{
    'salesforce/blip2-opt-2.7b': 'https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json',
}

class 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			Union[str, Any]      = '''blip_2_vision_model'''







     def __init__(						self :						Union[str, Any]   ,   _lowercase :						Optional[Any]=14_08   ,   _lowercase :						Optional[Any]=61_44   ,   _lowercase :						int=39   ,   _lowercase :						List[str]=16   ,   _lowercase :						Optional[int]=2_24   ,   _lowercase :						Union[str, Any]=14   ,   _lowercase :						Optional[int]="gelu"   ,   _lowercase :						Optional[int]=0.00001   ,   _lowercase :						List[str]=0.0   ,   _lowercase :						str=1E-10   ,   _lowercase :						List[str]=True   ,   **_lowercase :						List[str]   ,   ):
           super().__init__(**__UpperCAmelCase      )

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







     @classmethod
     def 							lowercase__       (						cls :						Union[str, Any]   ,   _lowercase :						Union[str, os.PathLike]   ,   **_lowercase :						Tuple      ):
           cls._set_token_in_kwargs(__UpperCAmelCase      )

           SCREAMING_SNAKE_CASE__     ,       SCREAMING_SNAKE_CASE__       :  List[str]						     =		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":
                 SCREAMING_SNAKE_CASE__       :  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(__UpperCAmelCase   ,   **__UpperCAmelCase      )




class 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			str      = '''blip_2_qformer'''







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

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







     @classmethod
     def 							lowercase__       (						cls :						Any   ,   _lowercase :						Union[str, os.PathLike]   ,   **_lowercase :						Optional[Any]      ):
           cls._set_token_in_kwargs(__UpperCAmelCase      )

           SCREAMING_SNAKE_CASE__     ,       SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		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":
                 SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		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 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			Optional[int]      = '''blip-2'''
     lowerCamelCase			:			Any      = True







     def __init__(						self :						Dict   ,   _lowercase :						Optional[Any]=None   ,   _lowercase :						List[str]=None   ,   _lowercase :						str=None   ,   _lowercase :						Union[str, Any]=32   ,   **_lowercase :						List[Any]      ):
           super().__init__(**__UpperCAmelCase      )

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

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

           if text_config is None:
                 SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		{}
                 logger.info('''text_config is None. Initializing the text config with default values (`OPTConfig`).'''      )

           SCREAMING_SNAKE_CASE__       :  Tuple						     =		BlipaVisionConfig(**__UpperCAmelCase      )
           SCREAMING_SNAKE_CASE__       :  str						     =		BlipaQFormerConfig(**__UpperCAmelCase      )
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
           SCREAMING_SNAKE_CASE__       :  int						     =		CONFIG_MAPPING[text_model_type](**__UpperCAmelCase      )

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

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







     @classmethod
     def 							lowercase__       (						cls :						Optional[Any]   ,   _lowercase :						BlipaVisionConfig   ,   _lowercase :						BlipaQFormerConfig   ,   _lowercase :						PretrainedConfig   ,   **_lowercase :						Optional[Any]   ,   ):
           return cls(
               vision_config=vision_config.to_dict()   ,   qformer_config=qformer_config.to_dict()   ,   text_config=text_config.to_dict()   ,   **__UpperCAmelCase   ,   )







     def 							lowercase__       (						self :						Any      ):
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		copy.deepcopy(self.__dict__      )
           SCREAMING_SNAKE_CASE__       :  Dict						     =		self.vision_config.to_dict()
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		self.qformer_config.to_dict()
           SCREAMING_SNAKE_CASE__       :  str						     =		self.text_config.to_dict()
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		self.__class__.model_type
           return output














from ... import PretrainedConfig


UpperCAmelCase__							  =						{
    "sijunhe/nezha-cn-base": "https://huggingface.co/sijunhe/nezha-cn-base/resolve/main/config.json",
}






class 						lowercase_   (      lowercase  ):






      '''simple docstring'''




      __snake_case	    =    NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP
      __snake_case	    =    '''nezha'''







      def __init__( self :		Union[str, Any]					,   __UpperCAmelCase :		List[str]=21_128					,   __UpperCAmelCase :		Any=768					,   __UpperCAmelCase :		int=12					,   __UpperCAmelCase :		Optional[int]=12					,   __UpperCAmelCase :		Tuple=3_072					,   __UpperCAmelCase :		Union[str, Any]="gelu"					,   __UpperCAmelCase :		List[str]=0.1					,   __UpperCAmelCase :		Any=0.1					,   __UpperCAmelCase :		str=512					,   __UpperCAmelCase :		List[Any]=64					,   __UpperCAmelCase :		Tuple=2					,   __UpperCAmelCase :		List[Any]=0.02					,   __UpperCAmelCase :		List[str]=1e-1_2					,   __UpperCAmelCase :		int=0.1					,   __UpperCAmelCase :		Dict=0					,   __UpperCAmelCase :		Any=2					,   __UpperCAmelCase :		Optional[Any]=3					,   __UpperCAmelCase :		int=True					,   **__UpperCAmelCase :		Optional[Any]					,   )       ->Any:




       """simple docstring"""


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

       a						    = vocab_size
       a						    = hidden_size
       a						    = num_hidden_layers
       a						    = num_attention_heads
       a						    = hidden_act
       a						    = intermediate_size
       a						    = hidden_dropout_prob
       a						    = attention_probs_dropout_prob
       a						    = max_position_embeddings
       a						    = max_relative_position
       a						    = type_vocab_size
       a						    = initializer_range
       a						    = layer_norm_eps
       a						    = classifier_dropout
       a						    = use_cache


