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 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						List[Any]						=      'blip_2_vision_model'







    def __init__(	self , __lowercase=1_408 , __lowercase=6_144 , __lowercase=39 , __lowercase=16 , __lowercase=224 , __lowercase=14 , __lowercase="gelu" , __lowercase=0.0_00_01 , __lowercase=0.0 , __lowercase=1E-1_0 , __lowercase=True , **__lowercase , )       ->	List[Any]:
        super().__init__(**SCREAMING_SNAKE_CASE_)

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







    @classmethod
    def 			UpperCamelCase__   (	cls , __lowercase , **__lowercase)       ->	"PretrainedConfig":
        cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_)

        __UpperCamelCase  ,       __UpperCamelCase     :Tuple			  =		cls.get_config_dict(SCREAMING_SNAKE_CASE_ , **SCREAMING_SNAKE_CASE_)

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


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						Dict						=      'blip_2_qformer'







    def __init__(	self , __lowercase=30_522 , __lowercase=768 , __lowercase=12 , __lowercase=12 , __lowercase=3_072 , __lowercase="gelu" , __lowercase=0.1 , __lowercase=0.1 , __lowercase=512 , __lowercase=0.02 , __lowercase=1E-1_2 , __lowercase=0 , __lowercase="absolute" , __lowercase=2 , __lowercase=1_408 , **__lowercase , )       ->	List[Any]:
        super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_ , **SCREAMING_SNAKE_CASE_)

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







    @classmethod
    def 			UpperCamelCase__   (	cls , __lowercase , **__lowercase)       ->	"PretrainedConfig":
        cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_)

        __UpperCamelCase  ,       __UpperCamelCase     :str			  =		cls.get_config_dict(SCREAMING_SNAKE_CASE_ , **SCREAMING_SNAKE_CASE_)

        # get the qformer config dict if we are loading from Blip2Config
        if config_dict.get('''model_type''') == "blip-2":
            __UpperCamelCase     :Optional[int]			  =		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(SCREAMING_SNAKE_CASE_ , **SCREAMING_SNAKE_CASE_)


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						str						=      'blip-2'
    a__	:						int						=      True







    def __init__(	self , __lowercase=None , __lowercase=None , __lowercase=None , __lowercase=32 , **__lowercase)       ->	Tuple:
        super().__init__(**SCREAMING_SNAKE_CASE_)

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

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

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

        __UpperCamelCase     :Optional[int]			  =		BlipaVisionConfig(**SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Optional[Any]			  =		BlipaQFormerConfig(**SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
        __UpperCamelCase     :Tuple			  =		CONFIG_MAPPING[text_model_type](**SCREAMING_SNAKE_CASE_)

        __UpperCamelCase     :Union[str, Any]			  =		self.text_config.tie_word_embeddings
        __UpperCamelCase     :Dict			  =		self.text_config.is_encoder_decoder

        __UpperCamelCase     :Optional[Any]			  =		num_query_tokens
        __UpperCamelCase     :List[Any]			  =		self.vision_config.hidden_size
        __UpperCamelCase     :Any			  =		self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
        __UpperCamelCase     :Optional[int]			  =		1.0
        __UpperCamelCase     :int			  =		0.02







    @classmethod
    def 			UpperCamelCase__   (	cls , __lowercase , __lowercase , __lowercase , **__lowercase , )       ->	Dict:
        return cls(
            vision_config=vision_config.to_dict() , qformer_config=qformer_config.to_dict() , text_config=text_config.to_dict() , **SCREAMING_SNAKE_CASE_ , )







    def 			UpperCamelCase__   (	self)       ->	str:
        __UpperCamelCase     :Optional[Any]			  =		copy.deepcopy(self.__dict__)
        __UpperCamelCase     :str			  =		self.vision_config.to_dict()
        __UpperCamelCase     :int			  =		self.qformer_config.to_dict()
        __UpperCamelCase     :Dict			  =		self.text_config.to_dict()
        __UpperCamelCase     :List[Any]			  =		self.__class__.model_type
        return output







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


__a  			=					logging.get_logger(__name__)
class  lowercase__(				UpperCAmelCase							):



	"""simple docstring"""




	a			:Union[str, Any]         =	'upernet'
	def __init__(       self  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Dict=None       ,							SCREAMING_SNAKE_CASE_  :			str=5_1_2       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.02       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=[1, 2, 3, 6]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=True       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.4       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=3_8_4       ,							SCREAMING_SNAKE_CASE_  :			str=2_5_6       ,							SCREAMING_SNAKE_CASE_  :			Dict=1       ,							SCREAMING_SNAKE_CASE_  :			Tuple=False       ,							SCREAMING_SNAKE_CASE_  :			str=2_5_5       ,							**SCREAMING_SNAKE_CASE_  :			str       ,							)       ->     int:
					super().__init__(**SCREAMING_SNAKE_CASE_       )

					if backbone_config is None:
									logger.info('''`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.'''       )
									lowercase_       =					CONFIG_MAPPING['''resnet'''](out_features=['''stage1''', '''stage2''', '''stage3''', '''stage4''']       )
					elif isinstance(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ):
									lowercase_       =					backbone_config.get('''model_type'''       )
									lowercase_       =					CONFIG_MAPPING[backbone_model_type]
									lowercase_       =					config_class.from_dict(SCREAMING_SNAKE_CASE_       )

					lowercase_       =					backbone_config
					lowercase_       =					hidden_size
					lowercase_       =					initializer_range
					lowercase_       =					pool_scales
					lowercase_       =					use_auxiliary_head
					lowercase_       =					auxiliary_loss_weight
					lowercase_       =					auxiliary_in_channels
					lowercase_       =					auxiliary_channels
					lowercase_       =					auxiliary_num_convs
					lowercase_       =					auxiliary_concat_input
					lowercase_       =					loss_ignore_index




	def 						_lowercase  (       self  :			List[str]       )       ->     List[str]:
					lowercase_       =					copy.deepcopy(self.__dict__       )
					lowercase_       =					self.backbone_config.to_dict()
					lowercase_       =					self.__class__.model_type
					return output




