






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


lowercase    			=       logging.get_logger(__name__)

lowercase    			=       {
    '''salesforce/blip2-opt-2.7b''': '''https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json''',
}

class 						A_							(      snake_case_  ):
				UpperCAmelCase__        =				'''blip_2_vision_model'''







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

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







				@classmethod
				def     _snake_case					(							cls							:						int						,    __lowerCamelCase							:						Union[str, os.PathLike]						,    **__lowerCamelCase							:						Tuple	)				->					"PretrainedConfig":
										cls._set_token_in_kwargs(__lowerCamelCase	)

										__magic_name__      ,    __magic_name__            =     cls.get_config_dict(__lowerCamelCase						,    **__lowerCamelCase	)

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





class 						A_							(      snake_case_  ):
				UpperCAmelCase__        =				'''blip_2_qformer'''







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

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







				@classmethod
				def     _snake_case					(							cls							:						List[str]						,    __lowerCamelCase							:						Union[str, os.PathLike]						,    **__lowerCamelCase							:						Optional[Any]	)				->					"PretrainedConfig":
										cls._set_token_in_kwargs(__lowerCamelCase	)

										__magic_name__      ,    __magic_name__            =     cls.get_config_dict(__lowerCamelCase						,    **__lowerCamelCase	)

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





class 						A_							(      snake_case_  ):
				UpperCAmelCase__        =				'''blip-2'''
				UpperCAmelCase__        =				True







				def __init__(							self							:						Optional[int]						,    __lowerCamelCase							:						int=None						,    __lowerCamelCase							:						Dict=None						,    __lowerCamelCase							:						Any=None						,    __lowerCamelCase							:						Any=3_2						,    **__lowerCamelCase							:						Dict	)				->					List[str]:
										super().__init__(**__lowerCamelCase	)

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

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

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

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

										__magic_name__            =     self.text_config.tie_word_embeddings
										__magic_name__            =     self.text_config.is_encoder_decoder

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







				@classmethod
				def     _snake_case					(							cls							:						List[str]						,    __lowerCamelCase							:						BlipaVisionConfig						,    __lowerCamelCase							:						BlipaQFormerConfig						,    __lowerCamelCase							:						PretrainedConfig						,    **__lowerCamelCase							:						Optional[int]						,    )				->					List[str]:
										return cls(
										    vision_config=vision_config.to_dict()						,    qformer_config=qformer_config.to_dict()						,    text_config=text_config.to_dict()						,    **__lowerCamelCase						,    )







				def     _snake_case					(							self							:						int	)				->					str:
										__magic_name__            =     copy.deepcopy(self.__dict__	)
										__magic_name__            =     self.vision_config.to_dict()
										__magic_name__            =     self.qformer_config.to_dict()
										__magic_name__            =     self.text_config.to_dict()
										__magic_name__            =     self.__class__.model_type
										return output











"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowercase    			=       {
    '''configuration_xlm_roberta''': [
        '''XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XLMRobertaConfig''',
        '''XLMRobertaOnnxConfig''',
    ],
}

try:
			if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase    			=       ['''XLMRobertaTokenizer''']

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase    			=       ['''XLMRobertaTokenizerFast''']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase    			=       [
			    '''XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''XLMRobertaForCausalLM''',
			    '''XLMRobertaForMaskedLM''',
			    '''XLMRobertaForMultipleChoice''',
			    '''XLMRobertaForQuestionAnswering''',
			    '''XLMRobertaForSequenceClassification''',
			    '''XLMRobertaForTokenClassification''',
			    '''XLMRobertaModel''',
			    '''XLMRobertaPreTrainedModel''',
			]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase    			=       [
			    '''TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''TFXLMRobertaForCausalLM''',
			    '''TFXLMRobertaForMaskedLM''',
			    '''TFXLMRobertaForMultipleChoice''',
			    '''TFXLMRobertaForQuestionAnswering''',
			    '''TFXLMRobertaForSequenceClassification''',
			    '''TFXLMRobertaForTokenClassification''',
			    '''TFXLMRobertaModel''',
			    '''TFXLMRobertaPreTrainedModel''',
			]

try:
			if not is_flax_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase    			=       [
			    '''FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''FlaxXLMRobertaForMaskedLM''',
			    '''FlaxXLMRobertaForCausalLM''',
			    '''FlaxXLMRobertaForMultipleChoice''',
			    '''FlaxXLMRobertaForQuestionAnswering''',
			    '''FlaxXLMRobertaForSequenceClassification''',
			    '''FlaxXLMRobertaForTokenClassification''',
			    '''FlaxXLMRobertaModel''',
			    '''FlaxXLMRobertaPreTrainedModel''',
			]

if TYPE_CHECKING:
			from .configuration_xlm_roberta import (
			    XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP,
			    XLMRobertaConfig,
			    XLMRobertaOnnxConfig,
			)

			try:
						if not is_sentencepiece_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_xlm_roberta import XLMRobertaTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_xlm_roberta_fast import XLMRobertaTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_xlm_roberta import (
						    XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
						    XLMRobertaForCausalLM,
						    XLMRobertaForMaskedLM,
						    XLMRobertaForMultipleChoice,
						    XLMRobertaForQuestionAnswering,
						    XLMRobertaForSequenceClassification,
						    XLMRobertaForTokenClassification,
						    XLMRobertaModel,
						    XLMRobertaPreTrainedModel,
						)

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_xlm_roberta import (
						    TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFXLMRobertaForCausalLM,
						    TFXLMRobertaForMaskedLM,
						    TFXLMRobertaForMultipleChoice,
						    TFXLMRobertaForQuestionAnswering,
						    TFXLMRobertaForSequenceClassification,
						    TFXLMRobertaForTokenClassification,
						    TFXLMRobertaModel,
						    TFXLMRobertaPreTrainedModel,
						)

			try:
						if not is_flax_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_flax_xlm_roberta import (
						    FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
						    FlaxXLMRobertaForCausalLM,
						    FlaxXLMRobertaForMaskedLM,
						    FlaxXLMRobertaForMultipleChoice,
						    FlaxXLMRobertaForQuestionAnswering,
						    FlaxXLMRobertaForSequenceClassification,
						    FlaxXLMRobertaForTokenClassification,
						    FlaxXLMRobertaModel,
						    FlaxXLMRobertaPreTrainedModel,
						)

else:
			import sys

			lowercase    			=       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



