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


snake_case__				= logging.get_logger(__name__)

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



class  UpperCamelCase				( __lowercase ):

     '''simple docstring'''

     A_										=  'blip_2_vision_model'



     def __init__(					self				,				A_=14_08				,				A_=61_44				,				A_=39				,				A_=16				,				A_=2_24				,				A_=14				,				A_="gelu"				,				A_=0.00001				,				A_=0.0				,				A_=1E-1_0				,				A_=True				,				**A_				,				) ->				int:






           """simple docstring"""
           super().__init__(**A_						)

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





     @classmethod
     def 		UpperCamelCase_						(					cls				,				A_				,				**A_						) ->				"PretrainedConfig":






           """simple docstring"""
           cls._set_token_in_kwargs(A_						)

           _lowerCamelCase    ,					_lowerCamelCase			    =				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":
                 _lowerCamelCase			    =				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				( __lowercase ):

     '''simple docstring'''

     A_										=  'blip_2_qformer'



     def __init__(					self				,				A_=3_05_22				,				A_=7_68				,				A_=12				,				A_=12				,				A_=30_72				,				A_="gelu"				,				A_=0.1				,				A_=0.1				,				A_=5_12				,				A_=0.02				,				A_=1E-1_2				,				A_=0				,				A_="absolute"				,				A_=2				,				A_=14_08				,				**A_				,				) ->				Union[str, Any]:






           """simple docstring"""
           super().__init__(pad_token_id=A_				,				**A_						)

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





     @classmethod
     def 		UpperCamelCase_						(					cls				,				A_				,				**A_						) ->				"PretrainedConfig":






           """simple docstring"""
           cls._set_token_in_kwargs(A_						)

           _lowerCamelCase    ,					_lowerCamelCase			    =				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":
                 _lowerCamelCase			    =				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				( __lowercase ):

     '''simple docstring'''

     A_										=  'blip-2'
     A_										=  True



     def __init__(					self				,				A_=None				,				A_=None				,				A_=None				,				A_=32				,				**A_						) ->				str:






           """simple docstring"""
           super().__init__(**A_						)

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

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

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

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

           _lowerCamelCase			    =				self.text_config.tie_word_embeddings
           _lowerCamelCase			    =				self.text_config.is_encoder_decoder

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



     @classmethod
     def 		UpperCamelCase_						(					cls				,				A_				,				A_				,				A_				,				**A_				,				) ->				Tuple:






           """simple docstring"""
           return cls(
               vision_config=vision_config.to_dict()				,				qformer_config=qformer_config.to_dict()				,				text_config=text_config.to_dict()				,				**A_				,				)





     def 		UpperCamelCase_						(					self						) ->				int:






           """simple docstring"""
           _lowerCamelCase			    =				copy.deepcopy(self.__dict__						)
           _lowerCamelCase			    =				self.vision_config.to_dict()
           _lowerCamelCase			    =				self.qformer_config.to_dict()
           _lowerCamelCase			    =				self.text_config.to_dict()
           _lowerCamelCase			    =				self.__class__.model_type
           return output
import warnings

from ...utils import logging
from .image_processing_dpt import DPTImageProcessor


snake_case__				= logging.get_logger(__name__)



class  UpperCamelCase				( __lowercase ):

     '''simple docstring'''

     def __init__(					self				,				*A_				,				**A_						) ->				None:






           """simple docstring"""
           warnings.warn(
               '''The class DPTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'''
               ''' use DPTImageProcessor instead.'''				,				A_				,				)
           super().__init__(*A_				,				**A_						)