






"""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__	:    Optional[Any]			 = logging.get_logger(__name__)

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







class        lowercase__      (							snake_case__       ):
			_UpperCAmelCase		:Any             =			"blip_2_vision_model"


			def __init__(				self					:  Dict       ,	snake_case__					:  int=1408       ,	snake_case__					:  str=6144       ,	snake_case__					:  List[Any]=39       ,	snake_case__					:  Tuple=16       ,	snake_case__					:  str=224       ,	snake_case__					:  Optional[Any]=14       ,	snake_case__					:  Union[str, Any]="gelu"       ,	snake_case__					:  Dict=0.00_001       ,	snake_case__					:  List[str]=0.0       ,	snake_case__					:  List[Any]=1E-10       ,	snake_case__					:  List[str]=True       ,	**snake_case__					:  List[str]       ,	):
										super().__init__(**snake_case__ )

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


			@classmethod
			def      UpperCAmelCase__						(				cls					:  Optional[Any]       ,	snake_case__					:  Union[str, os.PathLike]       ,	**snake_case__					:  Optional[Any] ):
										cls._set_token_in_kwargs(snake_case__ )

										lowerCamelCase_	:							Optional[Any]									=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":
																	lowerCamelCase_	:							Optional[int]									=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        lowercase__      (							snake_case__       ):
			_UpperCAmelCase		:Tuple             =			"blip_2_qformer"


			def __init__(				self					:  Tuple       ,	snake_case__					:  Optional[int]=3_0522       ,	snake_case__					:  Tuple=768       ,	snake_case__					:  Optional[Any]=12       ,	snake_case__					:  int=12       ,	snake_case__					:  str=3072       ,	snake_case__					:  Union[str, Any]="gelu"       ,	snake_case__					:  Union[str, Any]=0.1       ,	snake_case__					:  Optional[int]=0.1       ,	snake_case__					:  List[Any]=512       ,	snake_case__					:  Any=0.02       ,	snake_case__					:  List[str]=1E-12       ,	snake_case__					:  Optional[int]=0       ,	snake_case__					:  List[Any]="absolute"       ,	snake_case__					:  int=2       ,	snake_case__					:  Optional[Any]=1408       ,	**snake_case__					:  List[Any]       ,	):
										super().__init__(pad_token_id=snake_case__       ,	**snake_case__ )

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


			@classmethod
			def      UpperCAmelCase__						(				cls					:  Optional[Any]       ,	snake_case__					:  Union[str, os.PathLike]       ,	**snake_case__					:  Union[str, Any] ):
										cls._set_token_in_kwargs(snake_case__ )

										lowerCamelCase_	:							Tuple									=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":
																	lowerCamelCase_	:							List[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(snake_case__       ,	**snake_case__ )







class        lowercase__      (							snake_case__       ):
			_UpperCAmelCase		:Optional[Any]             =			"blip-2"
			_UpperCAmelCase		:Dict             =			True


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

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

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

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

										lowerCamelCase_	:							Optional[int]									=BlipaVisionConfig(**snake_case__ )
										lowerCamelCase_	:							Union[str, Any]									=BlipaQFormerConfig(**snake_case__ )
										lowerCamelCase_	:							int									=text_config["model_type"] if "model_type" in text_config else "opt"
										lowerCamelCase_	:							int									=CONFIG_MAPPING[text_model_type](**snake_case__ )

										lowerCamelCase_	:							Tuple									=self.text_config.tie_word_embeddings
										lowerCamelCase_	:							str									=self.text_config.is_encoder_decoder

										lowerCamelCase_	:							Optional[int]									=num_query_tokens
										lowerCamelCase_	:							Optional[int]									=self.vision_config.hidden_size
										lowerCamelCase_	:							Dict									=self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
										lowerCamelCase_	:							Optional[int]									=1.0
										lowerCamelCase_	:							List[Any]									=0.02


			@classmethod
			def      UpperCAmelCase__						(				cls					:  List[str]       ,	snake_case__					:  BlipaVisionConfig       ,	snake_case__					:  BlipaQFormerConfig       ,	snake_case__					:  PretrainedConfig       ,	**snake_case__					:  List[Any]       ,	):
										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					:  Optional[int] ):
										lowerCamelCase_	:							str									=copy.deepcopy(self.__dict__ )
										lowerCamelCase_	:							List[str]									=self.vision_config.to_dict()
										lowerCamelCase_	:							Dict									=self.qformer_config.to_dict()
										lowerCamelCase_	:							str									=self.text_config.to_dict()
										lowerCamelCase_	:							List[str]									=self.__class__.model_type
										return output











"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import _LazyModule


A__	:    Tuple			 = {'tokenization_byt5': ['ByT5Tokenizer']}


if TYPE_CHECKING:
						from .tokenization_byta import ByTaTokenizer
else:
						import sys

						A__	:    Dict			 = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



