



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__  :  Tuple								=					logging.get_logger(__name__)

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



class 				__snake_case						(     UpperCamelCase_						):
							_a			      = '''blip_2_vision_model'''




							def __init__(       self     :       Tuple				,				A_     :       Optional[int]=1_4_0_8				,				A_     :       Tuple=6_1_4_4				,				A_     :       Tuple=3_9				,				A_     :       Dict=1_6				,				A_     :       Tuple=2_2_4				,				A_     :       Any=1_4				,				A_     :       Dict="gelu"				,				A_     :       Any=0.0_0001				,				A_     :       int=0.0				,				A_     :       Dict=1e-10				,				A_     :       Optional[Any]=True				,				**A_     :       Tuple				,				):
									super().__init__(**A_)

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







							@classmethod
							def    UpperCAmelCase__			(       cls     :       str				,				A_     :       Union[str, os.PathLike]				,				**A_     :       List[str]):
									cls._set_token_in_kwargs(A_)

									lowerCAmelCase_					,  lowerCAmelCase_			:     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":
											lowerCAmelCase_			:     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 				__snake_case						(     UpperCamelCase_						):
							_a			      = '''blip_2_qformer'''




							def __init__(       self     :       List[str]				,				A_     :       List[str]=3_0_5_2_2				,				A_     :       Union[str, Any]=7_6_8				,				A_     :       Optional[int]=1_2				,				A_     :       Optional[Any]=1_2				,				A_     :       str=3_0_7_2				,				A_     :       Tuple="gelu"				,				A_     :       Union[str, Any]=0.1				,				A_     :       Optional[Any]=0.1				,				A_     :       Any=5_1_2				,				A_     :       Optional[Any]=0.02				,				A_     :       List[Any]=1e-12				,				A_     :       Optional[int]=0				,				A_     :       Dict="absolute"				,				A_     :       List[Any]=2				,				A_     :       Union[str, Any]=1_4_0_8				,				**A_     :       Optional[int]				,				):
									super().__init__(pad_token_id=A_				,				**A_)

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







							@classmethod
							def    UpperCAmelCase__			(       cls     :       Dict				,				A_     :       Union[str, os.PathLike]				,				**A_     :       Tuple):
									cls._set_token_in_kwargs(A_)

									lowerCAmelCase_					,  lowerCAmelCase_			:     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":
											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(A_				,				**A_)





class 				__snake_case						(     UpperCamelCase_						):
							_a			      = '''blip-2'''
							_a			      = True




							def __init__(       self     :       str				,				A_     :       str=None				,				A_     :       Dict=None				,				A_     :       List[str]=None				,				A_     :       str=3_2				,				**A_     :       Any):
									super().__init__(**A_)

									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_			:     List[str]									= {}
											logger.info('''qformer_config is None. Initializing the Blip2QFormerConfig with default values.''')

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

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

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

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




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







							def    UpperCAmelCase__			(       self     :       Tuple):
									lowerCAmelCase_			:     List[Any]									= copy.deepcopy(self.__dict__)
									lowerCAmelCase_			:     Union[str, Any]									= self.vision_config.to_dict()
									lowerCAmelCase_			:     List[Any]									= self.qformer_config.to_dict()
									lowerCAmelCase_			:     Any									= self.text_config.to_dict()
									lowerCAmelCase_			:     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),
									    ])





