
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		: List[str]								=     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    a_ (			_a    ):
			a	:			int					   =							'''blip_2_vision_model'''






			def __init__(      self				,			__UpperCamelCase=1_408				,			__UpperCamelCase=6_144				,			__UpperCamelCase=39				,			__UpperCamelCase=16				,			__UpperCamelCase=224				,			__UpperCamelCase=14				,			__UpperCamelCase="gelu"				,			__UpperCamelCase=0.0_00_01				,			__UpperCamelCase=0.0				,			__UpperCamelCase=1E-10				,			__UpperCamelCase=True				,			**__UpperCamelCase				,			):
									super().__init__(**snake_case_  )

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






			@classmethod
			def    UpperCamelCase_				(      cls				,			__UpperCamelCase				,			**__UpperCamelCase  ):
									cls._set_token_in_kwargs(snake_case_  )

									_lowercase					       =					cls.get_config_dict(snake_case_				,			**snake_case_  )

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







class    a_ (			_a    ):
			a	:			Any					   =							'''blip_2_qformer'''






			def __init__(      self				,			__UpperCamelCase=30_522				,			__UpperCamelCase=768				,			__UpperCamelCase=12				,			__UpperCamelCase=12				,			__UpperCamelCase=3_072				,			__UpperCamelCase="gelu"				,			__UpperCamelCase=0.1				,			__UpperCamelCase=0.1				,			__UpperCamelCase=512				,			__UpperCamelCase=0.02				,			__UpperCamelCase=1E-12				,			__UpperCamelCase=0				,			__UpperCamelCase="absolute"				,			__UpperCamelCase=2				,			__UpperCamelCase=1_408				,			**__UpperCamelCase				,			):
									super().__init__(pad_token_id=snake_case_				,			**snake_case_  )

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






			@classmethod
			def    UpperCamelCase_				(      cls				,			__UpperCamelCase				,			**__UpperCamelCase  ):
									cls._set_token_in_kwargs(snake_case_  )

									_lowercase					       =					cls.get_config_dict(snake_case_				,			**snake_case_  )

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







class    a_ (			_a    ):
			a	:			Union[str, Any]					   =							'''blip-2'''
			a	:			List[Any]					   =							True






			def __init__(      self				,			__UpperCamelCase=None				,			__UpperCamelCase=None				,			__UpperCamelCase=None				,			__UpperCamelCase=32				,			**__UpperCamelCase  ):
									super().__init__(**snake_case_  )

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

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

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

									_lowercase					       =					BlipaVisionConfig(**snake_case_  )
									_lowercase					       =					BlipaQFormerConfig(**snake_case_  )
									_lowercase					       =					text_config["""model_type"""] if """model_type""" in text_config else """opt"""
									_lowercase					       =					CONFIG_MAPPING[text_model_type](**snake_case_  )

									_lowercase					       =					self.text_config.tie_word_embeddings
									_lowercase					       =					self.text_config.is_encoder_decoder

									_lowercase					       =					num_query_tokens
									_lowercase					       =					self.vision_config.hidden_size
									_lowercase					       =					self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
									_lowercase					       =					1.0
									_lowercase					       =					0.02






			@classmethod
			def    UpperCamelCase_				(      cls				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			**__UpperCamelCase				,			):
									return cls(
									    vision_config=vision_config.to_dict()				,			qformer_config=qformer_config.to_dict()				,			text_config=text_config.to_dict()				,			**snake_case_				,			)






			def    UpperCamelCase_				(      self  ):
									_lowercase					       =					copy.deepcopy(self.__dict__  )
									_lowercase					       =					self.vision_config.to_dict()
									_lowercase					       =					self.qformer_config.to_dict()
									_lowercase					       =					self.text_config.to_dict()
									_lowercase					       =					self.__class__.model_type
									return output




'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__a  			=						{
    "configuration_bigbird_pegasus": [
        "BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "BigBirdPegasusConfig",
        "BigBirdPegasusOnnxConfig",
    ],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __a  			=						[
           "BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST",
           "BigBirdPegasusForCausalLM",
           "BigBirdPegasusForConditionalGeneration",
           "BigBirdPegasusForQuestionAnswering",
           "BigBirdPegasusForSequenceClassification",
           "BigBirdPegasusModel",
           "BigBirdPegasusPreTrainedModel",
       ]


if TYPE_CHECKING:
       from .configuration_bigbird_pegasus import (
           BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP,
           BigBirdPegasusConfig,
           BigBirdPegasusOnnxConfig,
       )

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_bigbird_pegasus import (
                  BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
                  BigBirdPegasusForCausalLM,
                  BigBirdPegasusForConditionalGeneration,
                  BigBirdPegasusForQuestionAnswering,
                  BigBirdPegasusForSequenceClassification,
                  BigBirdPegasusModel,
                  BigBirdPegasusPreTrainedModel,
              )


else:
       import sys

       __a  			=						_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
