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

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


class      UpperCAmelCase_	(    __lowerCamelCase):
      lowerCamelCase__		:    Optional[Any]   =  """blip_2_vision_model"""


      def __init__(   self		,			a=1_4_0_8		,			a=6_1_4_4		,			a=3_9		,			a=1_6		,			a=2_2_4		,			a=1_4		,			a="gelu"		,			a=0.00_001		,			a=0.0		,			a=1e-10		,			a=True		,			**a		,			)       ->					int:
             super().__init__(**a							)

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


      @classmethod
      def 		_UpperCAmelCase       (   cls		,			a		,			**a							)       ->					Union[str, Any]:
             cls._set_token_in_kwargs(a							)

             lowercase__    ,      lowercase__			:		List[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__			:		Union[str, 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      UpperCAmelCase_	(    __lowerCamelCase):
      lowerCamelCase__		:    int   =  """blip_2_qformer"""


      def __init__(   self		,			a=3_0_5_2_2		,			a=7_6_8		,			a=1_2		,			a=1_2		,			a=3_0_7_2		,			a="gelu"		,			a=0.1		,			a=0.1		,			a=5_1_2		,			a=0.02		,			a=1e-12		,			a=0		,			a="absolute"		,			a=2		,			a=1_4_0_8		,			**a		,			)       ->					Dict:
             super().__init__(pad_token_id=a		,			**a							)

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


      @classmethod
      def 		_UpperCAmelCase       (   cls		,			a		,			**a							)       ->					Optional[Any]:
             cls._set_token_in_kwargs(a							)

             lowercase__    ,      lowercase__			:		Optional[int]       =	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__			:		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      UpperCAmelCase_	(    __lowerCamelCase):
      lowerCamelCase__		:    List[Any]   =  """blip-2"""
      lowerCamelCase__		:    str   =  True


      def __init__(   self		,			a=None		,			a=None		,			a=None		,			a=3_2		,			**a							)       ->					Optional[Any]:
             super().__init__(**a							)

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

             if qformer_config is None:
                    lowercase__			:		Dict       =	{}
                    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__			:		List[str]       =	BlipaQFormerConfig(**a							)
             lowercase__			:		Dict       =	text_config['model_type'] if 'model_type' in text_config else 'opt'
             lowercase__			:		List[str]       =	CONFIG_MAPPING[text_model_type](**a							)

             lowercase__			:		int       =	self.text_config.tie_word_embeddings
             lowercase__			:		str       =	self.text_config.is_encoder_decoder

             lowercase__			:		Any       =	num_query_tokens
             lowercase__			:		Optional[int]       =	self.vision_config.hidden_size
             lowercase__			:		str       =	self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
             lowercase__			:		Tuple       =	1.0
             lowercase__			:		str       =	0.02


      @classmethod
      def 		_UpperCAmelCase       (   cls		,			a		,			a		,			a		,			**a		,			)       ->					List[str]:
             return cls(
                 vision_config=vision_config.to_dict()		,			qformer_config=qformer_config.to_dict()		,			text_config=text_config.to_dict()		,			**a		,			)


      def 		_UpperCAmelCase       (   self							)       ->					Optional[Any]:
             lowercase__			:		Optional[int]       =	copy.deepcopy(self.__dict__							)
             lowercase__			:		Dict       =	self.vision_config.to_dict()
             lowercase__			:		Optional[Any]       =	self.qformer_config.to_dict()
             lowercase__			:		Union[str, Any]       =	self.text_config.to_dict()
             lowercase__			:		Any       =	self.__class__.model_type
             return output



import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase	      = logging.get_logger(__name__)

UpperCAmelCase	      = {
    '''xlnet-base-cased''': '''https://huggingface.co/xlnet-base-cased/resolve/main/config.json''',
    '''xlnet-large-cased''': '''https://huggingface.co/xlnet-large-cased/resolve/main/config.json''',
}







class        A_   (			__lowerCamelCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     Tuple							 =       """xlnet"""
	_UpperCamelCase     :     Optional[Any]							 =       ["""mems"""]
	_UpperCamelCase     :     Tuple							 =       {
	    """n_token""": """vocab_size""",  # Backward compatibility
	    """hidden_size""": """d_model""",
	    """num_attention_heads""": """n_head""",
	    """num_hidden_layers""": """n_layer""",
	}





	def __init__(       self		,    snake_case=3_2000		,    snake_case=1024		,    snake_case=24		,    snake_case=16		,    snake_case=4096		,    snake_case="gelu"		,    snake_case=True		,    snake_case="bi"		,    snake_case=0.02		,    snake_case=1E-12		,    snake_case=0.1		,    snake_case=512		,    snake_case=None		,    snake_case=True		,    snake_case=False		,    snake_case=False		,    snake_case=-1		,    snake_case=False		,    snake_case="last"		,    snake_case=True		,    snake_case="tanh"		,    snake_case=0.1		,    snake_case=5		,    snake_case=5		,    snake_case=5		,    snake_case=1		,    snake_case=2		,    **snake_case		,    ):
		lowercase       =    vocab_size
		lowercase       =    d_model
		lowercase       =    n_layer
		lowercase       =    n_head
		if d_model % n_head != 0:
			raise ValueError(F'''\'d_model % n_head\' ({d_model % n_head}) should be equal to 0'''       )
		if "d_head" in kwargs:
			if kwargs["d_head"] != d_model // n_head:
				raise ValueError(
				    F'''`d_head` ({kwargs['d_head']}) should be equal to `d_model // n_head` ({d_model // n_head})'''       )
		lowercase       =    d_model // n_head
		lowercase       =    ff_activation
		lowercase       =    d_inner
		lowercase       =    untie_r
		lowercase       =    attn_type

		lowercase       =    initializer_range
		lowercase       =    layer_norm_eps

		lowercase       =    dropout
		lowercase       =    mem_len
		lowercase       =    reuse_len
		lowercase       =    bi_data
		lowercase       =    clamp_len
		lowercase       =    same_length

		lowercase       =    summary_type
		lowercase       =    summary_use_proj
		lowercase       =    summary_activation
		lowercase       =    summary_last_dropout
		lowercase       =    start_n_top
		lowercase       =    end_n_top

		lowercase       =    bos_token_id
		lowercase       =    pad_token_id
		lowercase       =    eos_token_id

		if "use_cache" in kwargs:
			warnings.warn(
			    'The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'
			    ' instead.'		,    snake_case		,    )
			lowercase       =    kwargs['use_cache']

		lowercase       =    use_mems_eval
		lowercase       =    use_mems_train
		super().__init__(pad_token_id=snake_case		,    bos_token_id=snake_case		,    eos_token_id=snake_case		,    **snake_case       )





	@property
	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		logger.info(F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''       )
		return -1





	@max_position_embeddings.setter
	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case       ):
		# Message copied from Transformer-XL documentation
		raise NotImplementedError(
		    F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''       )

