



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


_UpperCamelCase: Tuple										=     logging.get_logger(__name__)

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


class      a__						(  UpperCamelCase_   ):
   _lowerCamelCase    							= 'blip_2_vision_model'


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

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






   @classmethod
   def 				lowercase (							cls					:							str,   lowerCAmelCase					:							Union[str, os.PathLike],   **lowerCAmelCase					:							List[str]	)			->				Any:
         cls._set_token_in_kwargs(A_	)

         lowercase     :					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":
               lowercase     :					Optional[Any] 		=      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      a__						(  UpperCamelCase_   ):
   _lowerCamelCase    							= 'blip_2_qformer'


   def __init__(							self					:							List[str],   lowerCAmelCase					:							List[str]=30522,   lowerCAmelCase					:							Union[str, Any]=768,   lowerCAmelCase					:							Optional[int]=12,   lowerCAmelCase					:							Optional[Any]=12,   lowerCAmelCase					:							str=3072,   lowerCAmelCase					:							Tuple="gelu",   lowerCAmelCase					:							Union[str, Any]=0.1,   lowerCAmelCase					:							Optional[Any]=0.1,   lowerCAmelCase					:							Any=512,   lowerCAmelCase					:							Optional[Any]=0.02,   lowerCAmelCase					:							List[Any]=1e-12,   lowerCAmelCase					:							Optional[int]=0,   lowerCAmelCase					:							Dict="absolute",   lowerCAmelCase					:							List[Any]=2,   lowerCAmelCase					:							Union[str, Any]=1408,   **lowerCAmelCase					:							Optional[int],   )			->				List[str]:
         super().__init__(pad_token_id=A_,   **A_	)

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






   @classmethod
   def 				lowercase (							cls					:							Dict,   lowerCAmelCase					:							Union[str, os.PathLike],   **lowerCAmelCase					:							Tuple	)			->				Any:
         cls._set_token_in_kwargs(A_	)

         lowercase     :					str 		=      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":
               lowercase     :					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(A_,   **A_	)




class      a__						(  UpperCamelCase_   ):
   _lowerCamelCase    							= 'blip-2'
   _lowerCamelCase    							= True


   def __init__(							self					:							str,   lowerCAmelCase					:							str=None,   lowerCAmelCase					:							Dict=None,   lowerCAmelCase					:							List[str]=None,   lowerCAmelCase					:							str=32,   **lowerCAmelCase					:							Any	)			->				Optional[int]:
         super().__init__(**A_	)

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

         if qformer_config is None:
               lowercase     :					List[str] 		=      {}
               logger.info('qformer_config is None. Initializing the Blip2QFormerConfig with default values.'	)

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

         lowercase     :					Union[str, Any] 		=      BlipaVisionConfig(**A_	)
         lowercase     :					int 		=      BlipaQFormerConfig(**A_	)
         lowercase     :					Any 		=      text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
         lowercase     :					Dict 		=      CONFIG_MAPPING[text_model_type](**A_	)

         lowercase     :					List[str] 		=      self.text_config.tie_word_embeddings
         lowercase     :					Optional[Any] 		=      self.text_config.is_encoder_decoder

         lowercase     :					Tuple 		=      num_query_tokens
         lowercase     :					Tuple 		=      self.vision_config.hidden_size
         lowercase     :					str 		=      self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
         lowercase     :					List[Any] 		=      1.0
         lowercase     :					List[Any] 		=      0.02


   @classmethod
   def 				lowercase (							cls					:							Dict,   lowerCAmelCase					:							BlipaVisionConfig,   lowerCAmelCase					:							BlipaQFormerConfig,   lowerCAmelCase					:							PretrainedConfig,   **lowerCAmelCase					:							List[Any],   )			->				List[Any]:
         return cls(
             vision_config=vision_config.to_dict(),   qformer_config=qformer_config.to_dict(),   text_config=text_config.to_dict(),   **A_,   )






   def 				lowercase (							self					:							Tuple	)			->				int:
         lowercase     :					List[Any] 		=      copy.deepcopy(self.__dict__	)
         lowercase     :					Union[str, Any] 		=      self.vision_config.to_dict()
         lowercase     :					List[Any] 		=      self.qformer_config.to_dict()
         lowercase     :					Any 		=      self.text_config.to_dict()
         lowercase     :					Any 		=      self.__class__.model_type
         return output





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


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

A__  :  Tuple								=					{
    '''facebook/xlm-roberta-xl''': '''https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json''',
    '''facebook/xlm-roberta-xxl''': '''https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json''',
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}



class 				__snake_case						(     UpperCamelCase_						):
							_a			      = '''xlm-roberta-xl'''




							def __init__(       self     :       int				,				A_     :       List[str]=2_5_0_8_8_0				,				A_     :       List[str]=2_5_6_0				,				A_     :       Optional[int]=3_6				,				A_     :       List[Any]=3_2				,				A_     :       Optional[int]=1_0_2_4_0				,				A_     :       Dict="gelu"				,				A_     :       int=0.1				,				A_     :       Optional[Any]=0.1				,				A_     :       int=5_1_4				,				A_     :       Any=1				,				A_     :       Optional[Any]=0.02				,				A_     :       str=1e-05				,				A_     :       Dict=1				,				A_     :       Any=0				,				A_     :       Tuple=2				,				A_     :       str="absolute"				,				A_     :       str=True				,				A_     :       List[str]=None				,				**A_     :       Dict				,				):
									super().__init__(pad_token_id=A_				,				bos_token_id=A_				,				eos_token_id=A_				,				**A_)
									lowerCAmelCase_			:     Tuple									= vocab_size
									lowerCAmelCase_			:     List[str]									= hidden_size
									lowerCAmelCase_			:     int									= num_hidden_layers
									lowerCAmelCase_			:     int									= num_attention_heads
									lowerCAmelCase_			:     Dict									= hidden_act
									lowerCAmelCase_			:     int									= intermediate_size
									lowerCAmelCase_			:     Tuple									= hidden_dropout_prob
									lowerCAmelCase_			:     Optional[Any]									= attention_probs_dropout_prob
									lowerCAmelCase_			:     Union[str, Any]									= max_position_embeddings
									lowerCAmelCase_			:     Dict									= type_vocab_size
									lowerCAmelCase_			:     str									= initializer_range
									lowerCAmelCase_			:     str									= layer_norm_eps
									lowerCAmelCase_			:     Optional[Any]									= position_embedding_type
									lowerCAmelCase_			:     Optional[Any]									= use_cache
									lowerCAmelCase_			:     List[str]									= classifier_dropout





class 				__snake_case						(     UpperCamelCase_						):




							@property
							def    UpperCAmelCase__			(       self     :       List[str]):
									if self.task == "multiple-choice":
											lowerCAmelCase_			:     Union[str, Any]									= {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
									else:
											lowerCAmelCase_			:     List[Any]									= {0: '''batch''', 1: '''sequence'''}
									return OrderedDict(
									    [
									        ('''input_ids''', dynamic_axis),
									        ('''attention_mask''', dynamic_axis),
									    ])





