
def 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE							):
	lowercase       =    0
	for ch in input_str:
		lowercase       =    ord(__SCREAMING_SNAKE_CASE							)
		lowercase       =    pow(2 ,							__SCREAMING_SNAKE_CASE							)

		# If we already turned on bit for current character's unicode
		if bitmap >> ch_unicode & 1 == 1:
			return False
		bitmap |= ch_bit_index_on
	return True


if __name__ == "__main__":
	import doctest

	doctest.testmod()



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

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







class        A_   (			__lowerCamelCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     Optional[Any]							 =       """blip_2_vision_model"""





	def __init__(       self		,    snake_case=1408		,    snake_case=6144		,    snake_case=39		,    snake_case=16		,    snake_case=224		,    snake_case=14		,    snake_case="gelu"		,    snake_case=0.00_001		,    snake_case=0.0		,    snake_case=1E-10		,    snake_case=True		,    **snake_case		,    ):
		super().__init__(**snake_case       )

		lowercase       =    hidden_size
		lowercase       =    intermediate_size
		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
		lowercase       =    qkv_bias





	@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 Blip2Config
		if config_dict.get('model_type'       ) == "blip-2":
			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     :     int							 =       """blip_2_qformer"""





	def __init__(       self		,    snake_case=3_0522		,    snake_case=768		,    snake_case=12		,    snake_case=12		,    snake_case=3072		,    snake_case="gelu"		,    snake_case=0.1		,    snake_case=0.1		,    snake_case=512		,    snake_case=0.02		,    snake_case=1E-12		,    snake_case=0		,    snake_case="absolute"		,    snake_case=2		,    snake_case=1408		,    **snake_case		,    ):
		super().__init__(pad_token_id=snake_case		,    **snake_case       )

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





	@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 qformer config dict if we are loading from Blip2Config
		if config_dict.get('model_type'       ) == "blip-2":
			lowercase       =    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(snake_case		,    **snake_case       )







class        A_   (			__lowerCamelCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     List[Any]							 =       """blip-2"""
	_UpperCamelCase     :     str							 =       True





	def __init__(       self		,    snake_case=None		,    snake_case=None		,    snake_case=None		,    snake_case=32		,    **snake_case       ):
		super().__init__(**snake_case       )

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

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

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

		lowercase       =    BlipaVisionConfig(**snake_case       )
		lowercase       =    BlipaQFormerConfig(**snake_case       )
		lowercase       =    text_config['model_type'] if 'model_type' in text_config else 'opt'
		lowercase       =    CONFIG_MAPPING[text_model_type](**snake_case       )

		lowercase       =    self.text_config.tie_word_embeddings
		lowercase       =    self.text_config.is_encoder_decoder

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





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





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    copy.deepcopy(self.__dict__       )
		lowercase       =    self.vision_config.to_dict()
		lowercase       =    self.qformer_config.to_dict()
		lowercase       =    self.text_config.to_dict()
		lowercase       =    self.__class__.model_type
		return output

