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


SCREAMING_SNAKE_CASE_	   =			logging.get_logger(__name__)

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




class    a (       __lowerCAmelCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					"""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.0_0_0_0_1   ,    snake_case_=0.0   ,    snake_case_=1e-1_0   ,    snake_case_=True   ,    **snake_case_   ,    ):

    '''simple docstring'''







    super().__init__(**snake_case_					)

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







  @classmethod
  def    lowercase_  (							cls   ,    snake_case_   ,    **snake_case_					):

    '''simple docstring'''







    cls._set_token_in_kwargs(snake_case_					)

    __UpperCAmelCase:					List[Any]		= 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":
      __UpperCAmelCase:					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(snake_case_   ,    **snake_case_					)




class    a (       __lowerCAmelCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					"""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.0_2   ,    snake_case_=1e-1_2   ,    snake_case_=0   ,    snake_case_="absolute"   ,    snake_case_=2   ,    snake_case_=1408   ,    **snake_case_   ,    ):

    '''simple docstring'''







    super().__init__(pad_token_id=snake_case_   ,    **snake_case_					)

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







  @classmethod
  def    lowercase_  (							cls   ,    snake_case_   ,    **snake_case_					):

    '''simple docstring'''







    cls._set_token_in_kwargs(snake_case_					)

    __UpperCAmelCase:					Optional[int]		= 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":
      __UpperCAmelCase:					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(snake_case_   ,    **snake_case_					)




class    a (       __lowerCAmelCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					"""blip-2"""
  __lowerCAmelCase				      =					True







  def __init__(							self   ,    snake_case_=None   ,    snake_case_=None   ,    snake_case_=None   ,    snake_case_=32   ,    **snake_case_					):

    '''simple docstring'''







    super().__init__(**snake_case_					)

    if vision_config is None:
      __UpperCAmelCase:					Any		= {}
      logger.info("""vision_config is None. initializing the Blip2VisionConfig with default values."""					)

    if qformer_config is None:
      __UpperCAmelCase:					Tuple		= {}
      logger.info("""qformer_config is None. Initializing the Blip2QFormerConfig with default values."""					)

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

    __UpperCAmelCase:					Union[str, Any]		= BlipaVisionConfig(**snake_case_					)
    __UpperCAmelCase:					List[str]		= BlipaQFormerConfig(**snake_case_					)
    __UpperCAmelCase:					Dict		= text_config["""model_type"""] if """model_type""" in text_config else """opt"""
    __UpperCAmelCase:					Tuple		= CONFIG_MAPPING[text_model_type](**snake_case_					)

    __UpperCAmelCase:					List[Any]		= self.text_config.tie_word_embeddings
    __UpperCAmelCase:					Dict		= self.text_config.is_encoder_decoder

    __UpperCAmelCase:					Any		= num_query_tokens
    __UpperCAmelCase:					Dict		= self.vision_config.hidden_size
    __UpperCAmelCase:					Union[str, Any]		= self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
    __UpperCAmelCase:					List[str]		= 1.0
    __UpperCAmelCase:					Any		= 0.0_2







  @classmethod
  def    lowercase_  (							cls   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    **snake_case_   ,    ):

    '''simple docstring'''







    return cls(
        vision_config=vision_config.to_dict()   ,    qformer_config=qformer_config.to_dict()   ,    text_config=text_config.to_dict()   ,    **snake_case_   ,    )







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[str]		= copy.deepcopy(self.__dict__					)
    __UpperCAmelCase:					Any		= self.vision_config.to_dict()
    __UpperCAmelCase:					Optional[int]		= self.qformer_config.to_dict()
    __UpperCAmelCase:					Optional[Any]		= self.text_config.to_dict()
    __UpperCAmelCase:					Union[str, Any]		= self.__class__.model_type
    return output
'''simple docstring'''






def  UpperCamelCase__					(					_lowercase    :				int     )							->	int:

  if not isinstance(_lowercase   ,    _lowercase     ):
    __UpperCAmelCase:					List[str]		= F'''Input value of [number={number}] must be an integer'''
    raise TypeError(_lowercase     )

  if number < 1:
    __UpperCAmelCase:					Dict		= F'''Input value of [number={number}] must be > 0'''
    raise ValueError(_lowercase     )

  __UpperCAmelCase:					int		= 1

  for i in range(1   ,    _lowercase     ):
    current_number *= 4 * i - 2
    current_number //= i + 1

  return current_number


if __name__ == "__main__":
    import doctest

    doctest.testmod()