
import copy
import os
from typing import Union

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


UpperCAmelCase	      = logging.get_logger(__name__)

UpperCAmelCase	      = {
    '''Salesforce/blip-vqa-base''': '''https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json''',
    '''Salesforce/blip-vqa-capfit-large''': (
        '''https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json'''
    ),
    '''Salesforce/blip-image-captioning-base''': (
        '''https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json'''
    ),
    '''Salesforce/blip-image-captioning-large''': (
        '''https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json'''
    ),
    '''Salesforce/blip-itm-base-coco''': '''https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json''',
    '''Salesforce/blip-itm-large-coco''': '''https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json''',
    '''Salesforce/blip-itm-base-flikr''': '''https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json''',
    '''Salesforce/blip-itm-large-flikr''': (
        '''https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json'''
    ),
}







class        A_   (			__lowerCamelCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     str							 =       """blip_text_model"""





	def __init__(       self		,    snake_case=3_0524		,    snake_case=768		,    snake_case=768		,    snake_case=3072		,    snake_case=768		,    snake_case=12		,    snake_case=8		,    snake_case=512		,    snake_case="gelu"		,    snake_case=1E-12		,    snake_case=0.0		,    snake_case=0.0		,    snake_case=0.02		,    snake_case=3_0522		,    snake_case=2		,    snake_case=0		,    snake_case=102		,    snake_case=True		,    snake_case=True		,    **snake_case		,    ):
		super().__init__(
		    pad_token_id=snake_case		,    bos_token_id=snake_case		,    eos_token_id=snake_case		,    sep_token_id=snake_case		,    **snake_case		,    )

		lowercase       =    vocab_size
		lowercase       =    hidden_size
		lowercase       =    encoder_hidden_size
		lowercase       =    intermediate_size
		lowercase       =    projection_dim
		lowercase       =    hidden_dropout_prob
		lowercase       =    num_hidden_layers
		lowercase       =    num_attention_heads
		lowercase       =    max_position_embeddings
		lowercase       =    layer_norm_eps
		lowercase       =    hidden_act
		lowercase       =    initializer_range
		lowercase       =    attention_probs_dropout_prob
		lowercase       =    is_decoder
		lowercase       =    use_cache





	@classmethod
	def 	SCREAMING_SNAKE_CASE__						(       cls		,    snake_case		,    **snake_case       ):
		cls._set_token_in_kwargs(snake_case       )

		lowercase  ,					lowercase       =    cls.get_config_dict(snake_case		,    **snake_case       )

		# get the text config dict if we are loading from BlipConfig
		if config_dict.get('model_type'       ) == "blip":
			lowercase       =    config_dict['text_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(snake_case		,    **snake_case       )







class        A_   (			__lowerCamelCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     Optional[int]							 =       """blip_vision_model"""





	def __init__(       self		,    snake_case=768		,    snake_case=3072		,    snake_case=512		,    snake_case=12		,    snake_case=12		,    snake_case=384		,    snake_case=16		,    snake_case="gelu"		,    snake_case=1E-5		,    snake_case=0.0		,    snake_case=1E-10		,    **snake_case		,    ):
		super().__init__(**snake_case       )

		lowercase       =    hidden_size
		lowercase       =    intermediate_size
		lowercase       =    projection_dim
		lowercase       =    num_hidden_layers
		lowercase       =    num_attention_heads
		lowercase       =    patch_size
		lowercase       =    image_size
		lowercase       =    initializer_range
		lowercase       =    attention_dropout
		lowercase       =    layer_norm_eps
		lowercase       =    hidden_act





	@classmethod
	def 	SCREAMING_SNAKE_CASE__						(       cls		,    snake_case		,    **snake_case       ):
		cls._set_token_in_kwargs(snake_case       )

		lowercase  ,					lowercase       =    cls.get_config_dict(snake_case		,    **snake_case       )

		# get the vision config dict if we are loading from BlipConfig
		if config_dict.get('model_type'       ) == "blip":
			lowercase       =    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(snake_case		,    **snake_case       )







class        A_   (			__lowerCamelCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     str							 =       """blip"""
	_UpperCamelCase     :     Any							 =       True





	def __init__(       self		,    snake_case=None		,    snake_case=None		,    snake_case=512		,    snake_case=2.6_592		,    snake_case=256		,    **snake_case		,    ):
		super().__init__(**snake_case       )

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

		if vision_config is None:
			lowercase       =    {}
			logger.info('`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.'       )

		lowercase       =    BlipTextConfig(**snake_case       )
		lowercase       =    BlipVisionConfig(**snake_case       )

		lowercase       =    self.vision_config.hidden_size

		lowercase       =    projection_dim
		lowercase       =    logit_scale_init_value
		lowercase       =    1.0
		lowercase       =    0.02
		lowercase       =    image_text_hidden_size





	@classmethod
	def 	SCREAMING_SNAKE_CASE__						(       cls		,    snake_case		,    snake_case		,    **snake_case       ):
		return cls(text_config=text_config.to_dict()		,    vision_config=vision_config.to_dict()		,    **snake_case       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    copy.deepcopy(self.__dict__       )
		lowercase       =    self.text_config.to_dict()
		lowercase       =    self.vision_config.to_dict()
		lowercase       =    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.'''       )

