



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


SCREAMING_SNAKE_CASE_:Union[str, Any] 			=		logging.get_logger(__name__)

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






class SCREAMING_SNAKE_CASE__	(						_lowercase       ):




    '''simple docstring'''






    __lowerCamelCase     :					Optional[Any]   = '''blip_2_vision_model'''






    def __init__(			self,						lowerCamelCase__=1408,						lowerCamelCase__=6144,						lowerCamelCase__=39,						lowerCamelCase__=16,						lowerCamelCase__=224,						lowerCamelCase__=14,						lowerCamelCase__="gelu",						lowerCamelCase__=0.0_0001,						lowerCamelCase__=0.0,						lowerCamelCase__=1e-10,						lowerCamelCase__=True,						**lowerCamelCase__,						):
        super().__init__(**__A						)

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






    @classmethod
    def      _lowerCAmelCase   (			cls,						lowerCamelCase__,						**lowerCamelCase__						):
        cls._set_token_in_kwargs(__A						)

        A					:			Optional[Any]		=  cls.get_config_dict(__A,						**__A						)

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






class SCREAMING_SNAKE_CASE__	(						_lowercase       ):




    '''simple docstring'''






    __lowerCamelCase     :					List[str]   = '''blip_2_qformer'''






    def __init__(			self,						lowerCamelCase__=3_0522,						lowerCamelCase__=768,						lowerCamelCase__=12,						lowerCamelCase__=12,						lowerCamelCase__=3072,						lowerCamelCase__="gelu",						lowerCamelCase__=0.1,						lowerCamelCase__=0.1,						lowerCamelCase__=512,						lowerCamelCase__=0.02,						lowerCamelCase__=1e-12,						lowerCamelCase__=0,						lowerCamelCase__="absolute",						lowerCamelCase__=2,						lowerCamelCase__=1408,						**lowerCamelCase__,						):
        super().__init__(pad_token_id=__A,						**__A						)

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






    @classmethod
    def      _lowerCAmelCase   (			cls,						lowerCamelCase__,						**lowerCamelCase__						):
        cls._set_token_in_kwargs(__A						)

        A					:			Any		=  cls.get_config_dict(__A,						**__A						)

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






class SCREAMING_SNAKE_CASE__	(						_lowercase       ):




    '''simple docstring'''






    __lowerCamelCase     :					List[str]   = '''blip-2'''
    __lowerCamelCase     :					Any   = True






    def __init__(			self,						lowerCamelCase__=None,						lowerCamelCase__=None,						lowerCamelCase__=None,						lowerCamelCase__=32,						**lowerCamelCase__						):
        super().__init__(**__A						)

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

        if qformer_config is None:
            A					:			Union[str, Any]		=  {}
            logger.info("""qformer_config is None. Initializing the Blip2QFormerConfig with default values."""						)

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

        A					:			Any		=  BlipaVisionConfig(**__A						)
        A					:			Tuple		=  BlipaQFormerConfig(**__A						)
        A					:			Any		=  text_config["""model_type"""] if """model_type""" in text_config else """opt"""
        A					:			str		=  CONFIG_MAPPING[text_model_type](**__A						)

        A					:			List[Any]		=  self.text_config.tie_word_embeddings
        A					:			int		=  self.text_config.is_encoder_decoder

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






    @classmethod
    def      _lowerCAmelCase   (			cls,						lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__,						**lowerCamelCase__,						):
        return cls(
            vision_config=vision_config.to_dict(),						qformer_config=qformer_config.to_dict(),						text_config=text_config.to_dict(),						**__A,						)






    def      _lowerCAmelCase   (			self						):
        A					:			Union[str, Any]		=  copy.deepcopy(self.__dict__						)
        A					:			int		=  self.vision_config.to_dict()
        A					:			Optional[Any]		=  self.qformer_config.to_dict()
        A					:			Optional[Any]		=  self.text_config.to_dict()
        A					:			Any		=  self.__class__.model_type
        return output





from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase_							:					int		 =   {
    '''configuration_informer''': [
        '''INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''InformerConfig''',
    ],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			UpperCAmelCase_							:					List[str]		 =   [
			    '''INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''InformerForPrediction''',
			    '''InformerModel''',
			    '''InformerPreTrainedModel''',
			]


if TYPE_CHECKING:
			from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_informer import (
						    INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
						    InformerForPrediction,
						    InformerModel,
						    InformerPreTrainedModel,
						)

else:
			import sys

			UpperCAmelCase_							:					Optional[int]		 =   _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





