




import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case            = logging.get_logger(__name__)

_snake_case            = {
    'Salesforce/blip-vqa-base': 'https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json',
    'Salesforce/blip-vqa-capfit-large': (
        'https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json'
    ),
    'Salesforce/blip-image-captioning-base': (
        'https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json'
    ),
    'Salesforce/blip-image-captioning-large': (
        'https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json'
    ),
    'Salesforce/blip-itm-base-coco': 'https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json',
    'Salesforce/blip-itm-large-coco': 'https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json',
    'Salesforce/blip-itm-base-flikr': 'https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json',
    'Salesforce/blip-itm-large-flikr': (
        'https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json'
    ),
}







class 		lowercase							(     _A	):
     _a											=		"blip_text_model"

     def __init__(						self	,  _a=3_0524	,  _a=768	,  _a=768	,  _a=3072	,  _a=768	,  _a=12	,  _a=8	,  _a=512	,  _a="gelu"	,  _a=1e-12	,  _a=0.0	,  _a=0.0	,  _a=0.02	,  _a=3_0522	,  _a=2	,  _a=0	,  _a=102	,  _a=True	,  _a=True	,  **_a	,  )		->							Tuple:
           super().__init__(
               pad_token_id=UpperCamelCase__	,  bos_token_id=UpperCamelCase__	,  eos_token_id=UpperCamelCase__	,  sep_token_id=UpperCamelCase__	,  **UpperCamelCase__	,  )

           _A							:  Any    =		vocab_size
           _A							:  Dict    =		hidden_size
           _A							:  Optional[int]    =		encoder_hidden_size
           _A							:  Optional[Any]    =		intermediate_size
           _A							:  Tuple    =		projection_dim
           _A							:  str    =		hidden_dropout_prob
           _A							:  List[Any]    =		num_hidden_layers
           _A							:  List[str]    =		num_attention_heads
           _A							:  Tuple    =		max_position_embeddings
           _A							:  List[str]    =		layer_norm_eps
           _A							:  Tuple    =		hidden_act
           _A							:  Optional[int]    =		initializer_range
           _A							:  Union[str, Any]    =		attention_probs_dropout_prob
           _A							:  Any    =		is_decoder
           _A							:  Dict    =		use_cache



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

           _A    ,     _A							:  List[Any]    =		cls.get_config_dict(UpperCamelCase__	,  **UpperCamelCase__       )

           # get the text config dict if we are loading from BlipConfig
           if config_dict.get("""model_type"""       ) == "blip":
                 _A							:  Any    =		config_dict["""text_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 		lowercase							(     _A	):
     _a											=		"blip_vision_model"

     def __init__(						self	,  _a=768	,  _a=3072	,  _a=512	,  _a=12	,  _a=12	,  _a=384	,  _a=16	,  _a="gelu"	,  _a=1e-5	,  _a=0.0	,  _a=1e-10	,  **_a	,  )		->							List[str]:
           super().__init__(**UpperCamelCase__       )

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



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

           _A    ,     _A							:  Optional[int]    =		cls.get_config_dict(UpperCamelCase__	,  **UpperCamelCase__       )

           # get the vision config dict if we are loading from BlipConfig
           if config_dict.get("""model_type"""       ) == "blip":
                 _A							:  Tuple    =		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 		lowercase							(     _A	):
     _a											=		"blip"
     _a											=		True

     def __init__(						self	,  _a=None	,  _a=None	,  _a=512	,  _a=2.6592	,  _a=256	,  **_a	,  )		->							str:
           super().__init__(**UpperCamelCase__       )

           if text_config is None:
                 _A							:  Optional[Any]    =		{}
                 logger.info("""`text_config` is `None`. Initializing the `BlipTextConfig` with default values."""       )

           if vision_config is None:
                 _A							:  Dict    =		{}
                 logger.info("""`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values."""       )

           _A							:  str    =		BlipTextConfig(**UpperCamelCase__       )
           _A							:  Optional[Any]    =		BlipVisionConfig(**UpperCamelCase__       )

           _A							:  Union[str, Any]    =		self.vision_config.hidden_size

           _A							:  Dict    =		projection_dim
           _A							:  str    =		logit_scale_init_value
           _A							:  Optional[int]    =		1.0
           _A							:  List[Any]    =		0.02
           _A							:  List[str]    =		image_text_hidden_size

     @classmethod
     def       a__			(						cls	,  _a	,  _a	,  **_a       )		->							List[Any]:
           return cls(text_config=text_config.to_dict()	,  vision_config=vision_config.to_dict()	,  **UpperCamelCase__       )



     def       a__			(						self       )		->							List[str]:
           _A							:  List[Any]    =		copy.deepcopy(self.__dict__       )
           _A							:  str    =		self.text_config.to_dict()
           _A							:  Union[str, Any]    =		self.vision_config.to_dict()
           _A							:  Dict    =		self.__class__.model_type
           return output










from collections.abc import Callable
from math import pi, sqrt
from random import uniform
from statistics import mean







def        lowerCAmelCase_			(  snake_case_  ):

      # A local function to see if a dot lands in the circle.
      def is_in_circle(snake_case_,snake_case_  ) -> bool:
            _A							:  List[str]    =		sqrt((x**2) + (y**2)  )
            # Our circle has a radius of 1, so a distance
            # greater than 1 would land outside the circle.
            return distance_from_centre <= 1

      # The proportion of guesses that landed in the circle
      _A							:  Optional[int]    =		mean(
          int(is_in_circle(uniform(-1.0,1.0  ),uniform(-1.0,1.0  )  )  )
          for _ in range(snake_case_  )  )
      # The ratio of the area for circle to square is pi/4.
      _A							:  List[str]    =		proportion * 4
      print(f'''The estimated value of pi is {pi_estimate}'''  )
      print(f'''The numpy value of pi is {pi}'''  )
      print(f'''The total error is {abs(pi - pi_estimate  )}'''  )







def        lowerCAmelCase_			(  snake_case_,snake_case_,snake_case_ = 0.0,snake_case_ = 1.0,):
      return mean(
          function_to_integrate(uniform(snake_case_,snake_case_  )  ) for _ in range(snake_case_  )  ) * (max_value - min_value)







def        lowerCAmelCase_			(  snake_case_,snake_case_ = 0.0,snake_case_ = 1.0  ):

      def identity_function(snake_case_  ) -> float:
            return x

      _A							:  Any    =		area_under_curve_estimator(
          snake_case_,snake_case_,snake_case_,snake_case_  )
      _A							:  Tuple    =		(max_value * max_value - min_value * min_value) / 2

      print("""******************"""  )
      print(f'''Estimating area under y=x where x varies from {min_value} to {max_value}'''  )
      print(f'''Estimated value is {estimated_value}'''  )
      print(f'''Expected value is {expected_value}'''  )
      print(f'''Total error is {abs(estimated_value - expected_value  )}'''  )
      print("""******************"""  )







def        lowerCAmelCase_			(  snake_case_  ):

      def function_to_integrate(snake_case_  ) -> float:
            return sqrt(4.0 - x * x  )

      _A							:  Optional[int]    =		area_under_curve_estimator(
          snake_case_,snake_case_,0.0,2.0  )

      print("""******************"""  )
      print("""Estimating pi using area_under_curve_estimator"""  )
      print(f'''Estimated value is {estimated_value}'''  )
      print(f'''Expected value is {pi}'''  )
      print(f'''Total error is {abs(estimated_value - pi  )}'''  )
      print("""******************"""  )


if __name__ == "__main__":
  import doctest

  doctest.testmod()

