



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


__snake_case				:  str =       logging.get_logger(__name__)

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



class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'blip_2_vision_model'

	def __init__(	self:						str			,     _SCREAMING_SNAKE_CASE:						Optional[int]=1408			,     _SCREAMING_SNAKE_CASE:						List[str]=6144			,     _SCREAMING_SNAKE_CASE:						int=39			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=16			,     _SCREAMING_SNAKE_CASE:						List[Any]=224			,     _SCREAMING_SNAKE_CASE:						Dict=14			,     _SCREAMING_SNAKE_CASE:						List[str]="gelu"			,     _SCREAMING_SNAKE_CASE:						List[str]=0.0_0001			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=0.0			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=1e-10			,     _SCREAMING_SNAKE_CASE:						List[Any]=True			,     **_SCREAMING_SNAKE_CASE:						Tuple			,     )							->			str:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

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







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Optional[Any]			,     _SCREAMING_SNAKE_CASE:						Union[str, os.PathLike]			,     **_SCREAMING_SNAKE_CASE:						Dict)							->			"PretrainedConfig":

				"""simple docstring"""

				cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase		,      __lowerCAmelCase :    Optional[int]				=			cls.get_config_dict(_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

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






class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'blip_2_qformer'

	def __init__(	self:						List[Any]			,     _SCREAMING_SNAKE_CASE:						List[Any]=3_0522			,     _SCREAMING_SNAKE_CASE:						str=768			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=12			,     _SCREAMING_SNAKE_CASE:						List[str]=12			,     _SCREAMING_SNAKE_CASE:						str=3072			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]="gelu"			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=0.1			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=0.1			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=512			,     _SCREAMING_SNAKE_CASE:						List[Any]=0.02			,     _SCREAMING_SNAKE_CASE:						List[Any]=1e-12			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=0			,     _SCREAMING_SNAKE_CASE:						Optional[int]="absolute"			,     _SCREAMING_SNAKE_CASE:						List[Any]=2			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=1408			,     **_SCREAMING_SNAKE_CASE:						List[str]			,     )							->			str:

				"""simple docstring"""

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

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







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Any			,     _SCREAMING_SNAKE_CASE:						Union[str, os.PathLike]			,     **_SCREAMING_SNAKE_CASE:						Union[str, Any])							->			"PretrainedConfig":

				"""simple docstring"""

				cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase		,      __lowerCAmelCase :    Optional[int]				=			cls.get_config_dict(_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

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






class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'blip-2'
	SCREAMING_SNAKE_CASE        =      True

	def __init__(	self:						Optional[Any]			,     _SCREAMING_SNAKE_CASE:						str=None			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=None			,     _SCREAMING_SNAKE_CASE:						str=None			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=32			,     **_SCREAMING_SNAKE_CASE:						Tuple)							->			Optional[int]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

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

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

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

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

				__lowerCAmelCase :    List[Any]				=			self.text_config.tie_word_embeddings
				__lowerCAmelCase :    Dict				=			self.text_config.is_encoder_decoder

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

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						List[Any]			,     _SCREAMING_SNAKE_CASE:						BlipaVisionConfig			,     _SCREAMING_SNAKE_CASE:						BlipaQFormerConfig			,     _SCREAMING_SNAKE_CASE:						PretrainedConfig			,     **_SCREAMING_SNAKE_CASE:						Union[str, Any]			,     )							->			Dict:

				"""simple docstring"""

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







	def 				_SCREAMING_SNAKE_CASE  (	self:						int)							->			List[Any]:

				"""simple docstring"""

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







from typing import List, Optional

from tokenizers import ByteLevelBPETokenizer

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_blenderbot_small import BlenderbotSmallTokenizer


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

__a:     str   					=					{
    '''vocab_file''': '''vocab.json''',
    '''merges_file''': '''merges.txt''',
    '''tokenizer_config_file''': '''tokenizer_config.json''',
}

__a:     Dict   					=					{
    '''vocab_file''': {
        '''facebook/blenderbot_small-90M''': '''https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/vocab.json'''
    },
    '''merges_file''': {
        '''facebook/blenderbot_small-90M''': '''https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/merges.txt'''
    },
    '''tokenizer_config_file''': {
        '''facebook/blenderbot_small-90M''': (
            '''https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/tokenizer_config.json'''
        )
    },
}

__a:     Union[str, Any]   					=					{
    '''facebook/blenderbot_small-90M''': 512,
}
class 		SCREAMING_SNAKE_CASE__	(  UpperCAmelCase     ):

  '''simple docstring'''







  _lowerCamelCase    =  VOCAB_FILES_NAMES
  _lowerCamelCase    =  PRETRAINED_VOCAB_FILES_MAP
  _lowerCamelCase    =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  _lowerCamelCase    =  BlenderbotSmallTokenizer


  def __init__(      self		:			List[str]       ,				lowerCamelCase		:			List[str]=None       ,				lowerCamelCase		:			str=None       ,				lowerCamelCase		:			Optional[Any]="<|endoftext|>"       ,				lowerCamelCase		:			Dict="<|endoftext|>"       ,				lowerCamelCase		:			str="<|endoftext|>"       ,				lowerCamelCase		:			str=False       ,				lowerCamelCase		:			Tuple=True       ,				**lowerCamelCase		:			List[str]       ,				)						->	List[Any]:


         """simple docstring"""
         super().__init__(
             ByteLevelBPETokenizer(
                 vocab=lowerCamelCase       ,				merges=lowerCamelCase       ,				add_prefix_space=lowerCamelCase       ,				trim_offsets=lowerCamelCase       ,				)       ,				bos_token=lowerCamelCase       ,				eos_token=lowerCamelCase       ,				unk_token=lowerCamelCase       ,				**lowerCamelCase       ,				)
         _UpperCAmelCase							=    add_prefix_space


  def  lowerCamelCase       (      self		:			Union[str, Any]       ,				lowerCamelCase		:			str       ,				lowerCamelCase		:			Union[str, Any]=None							)						->	str:


         """simple docstring"""
         _UpperCAmelCase							=    [self.bos_token_id] + token_ids_a + [self.eos_token_id]
         if token_ids_a is None:
                return output

         return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]





  def  lowerCamelCase       (      self		:			Any       ,				lowerCamelCase		:			List[int]       ,				lowerCamelCase		:			Optional[List[int]] = None							)						->	List[int]:


         """simple docstring"""
         _UpperCAmelCase							=    [self.sep_token_id]
         _UpperCAmelCase							=    [self.cls_token_id]

         if token_ids_a is None:
                return len(cls + token_ids_a + sep							) * [0]
         return len(cls + token_ids_a + sep + sep + token_ids_a + sep							) * [0]