






'''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


a_ 		=       logging.get_logger(__name__)

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






class    __SCREAMING_SNAKE_CASE					(	_UpperCamelCase ):
 snake_case_     							=							'blip_2_vision_model'




 def __init__(					self		:							List[Any]    ,					__lowercase		:							List[Any]=14_08    ,					__lowercase		:							Optional[int]=61_44    ,					__lowercase		:							List[str]=39    ,					__lowercase		:							Dict=16    ,					__lowercase		:							Optional[Any]=2_24    ,					__lowercase		:							Any=14    ,					__lowercase		:							Optional[int]="gelu"    ,					__lowercase		:							Optional[int]=0.00001    ,					__lowercase		:							Tuple=0.0    ,					__lowercase		:							Union[str, Any]=1e-10    ,					__lowercase		:							Any=True    ,					**__lowercase		:							Dict    ,					)		->  Optional[Any]:
       super().__init__(**_UpperCAmelCase					)

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




 @classmethod
 def    __magic_name__		(					cls		:							Tuple    ,					__lowercase		:							Union[str, os.PathLike]    ,					**__lowercase		:							Any					)		->  Optional[int]:
       cls._set_token_in_kwargs(_UpperCAmelCase					)

       SCREAMING_SNAKE_CASE__   : List[Any]													=cls.get_config_dict(_UpperCAmelCase    ,					**_UpperCAmelCase					)

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






class    __SCREAMING_SNAKE_CASE					(	_UpperCamelCase ):
 snake_case_     							=							'blip_2_qformer'




 def __init__(					self		:							int    ,					__lowercase		:							List[str]=3_05_22    ,					__lowercase		:							Dict=7_68    ,					__lowercase		:							Tuple=12    ,					__lowercase		:							Any=12    ,					__lowercase		:							int=30_72    ,					__lowercase		:							str="gelu"    ,					__lowercase		:							Dict=0.1    ,					__lowercase		:							str=0.1    ,					__lowercase		:							int=5_12    ,					__lowercase		:							Union[str, Any]=0.02    ,					__lowercase		:							List[str]=1e-12    ,					__lowercase		:							int=0    ,					__lowercase		:							Optional[int]="absolute"    ,					__lowercase		:							List[str]=2    ,					__lowercase		:							Any=14_08    ,					**__lowercase		:							Optional[int]    ,					)		->  List[Any]:
       super().__init__(pad_token_id=_UpperCAmelCase    ,					**_UpperCAmelCase					)

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




 @classmethod
 def    __magic_name__		(					cls		:							Dict    ,					__lowercase		:							Union[str, os.PathLike]    ,					**__lowercase		:							Union[str, Any]					)		->  Union[str, Any]:
       cls._set_token_in_kwargs(_UpperCAmelCase					)

       SCREAMING_SNAKE_CASE__   : str													=cls.get_config_dict(_UpperCAmelCase    ,					**_UpperCAmelCase					)

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






class    __SCREAMING_SNAKE_CASE					(	_UpperCamelCase ):
 snake_case_     							=							'blip-2'
 snake_case_     							=							True




 def __init__(					self		:							Any    ,					__lowercase		:							Union[str, Any]=None    ,					__lowercase		:							Tuple=None    ,					__lowercase		:							Dict=None    ,					__lowercase		:							int=32    ,					**__lowercase		:							str					)		->  List[Any]:
       super().__init__(**_UpperCAmelCase					)

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

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

       if text_config is None:
             SCREAMING_SNAKE_CASE__   : List[Any]													={}
             logger.info('''text_config is None. Initializing the text config with default values (`OPTConfig`).'''					)

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

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

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




 @classmethod
 def    __magic_name__		(					cls		:							str    ,					__lowercase		:							BlipaVisionConfig    ,					__lowercase		:							BlipaQFormerConfig    ,					__lowercase		:							PretrainedConfig    ,					**__lowercase		:							List[Any]    ,					)		->  List[Any]:
       return cls(
           vision_config=vision_config.to_dict()    ,					qformer_config=qformer_config.to_dict()    ,					text_config=text_config.to_dict()    ,					**_UpperCAmelCase    ,					)




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




'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase									=   {
    '''configuration_lilt''': ['''LILT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''LiltConfig'''],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__lowerCAmelCase									=   [
							    '''LILT_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''LiltForQuestionAnswering''',
							    '''LiltForSequenceClassification''',
							    '''LiltForTokenClassification''',
							    '''LiltModel''',
							    '''LiltPreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_lilt import LILT_PRETRAINED_CONFIG_ARCHIVE_MAP, LiltConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_lilt import (
														    LILT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    LiltForQuestionAnswering,
														    LiltForSequenceClassification,
														    LiltForTokenClassification,
														    LiltModel,
														    LiltPreTrainedModel,
														)

else:
							import sys

							__lowerCAmelCase									=   _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




