





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


lowerCAmelCase       		=      logging.get_logger(__name__)

lowerCAmelCase       		=      {
    """salesforce/blip2-opt-2.7b""": """https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json""",
}
class 		lowerCamelCase  (      _A       ):
	snake_case_      =   "blip_2_vision_model"



	def __init__(   self		,      a_=1_408		,      a_=6_144		,      a_=39		,      a_=16		,      a_=224		,      a_=14		,      a_="gelu"		,      a_=0.00001		,      a_=0.0		,      a_=1e-1_0		,      a_=True		,      **a_		,      ):
			super().__init__(**a_	)

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





	@classmethod
	def   _lowerCamelCase    (   cls		,      a_		,      **a_	):
			cls._set_token_in_kwargs(a_	)

			lowerCAmelCase	,		lowerCAmelCase     :    Optional[int]						=   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     :    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(a_		,      **a_	)






class 		lowerCamelCase  (      _A       ):
	snake_case_      =   "blip_2_qformer"



	def __init__(   self		,      a_=30_522		,      a_=768		,      a_=12		,      a_=12		,      a_=3_072		,      a_="gelu"		,      a_=0.1		,      a_=0.1		,      a_=512		,      a_=0.02		,      a_=1e-1_2		,      a_=0		,      a_="absolute"		,      a_=2		,      a_=1_408		,      **a_		,      ):
			super().__init__(pad_token_id=a_		,      **a_	)

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





	@classmethod
	def   _lowerCamelCase    (   cls		,      a_		,      **a_	):
			cls._set_token_in_kwargs(a_	)

			lowerCAmelCase	,		lowerCAmelCase     :    Any						=   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     :    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(a_		,      **a_	)






class 		lowerCamelCase  (      _A       ):
	snake_case_      =   "blip-2"
	snake_case_      =   True



	def __init__(   self		,      a_=None		,      a_=None		,      a_=None		,      a_=32		,      **a_	):
			super().__init__(**a_	)

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

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

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

			lowerCAmelCase     :    List[Any]						=   BlipaVisionConfig(**a_	)
			lowerCAmelCase     :    List[str]						=   BlipaQFormerConfig(**a_	)
			lowerCAmelCase     :    Union[str, Any]						=   text_config["model_type"] if "model_type" in text_config else "opt"
			lowerCAmelCase     :    str						=   CONFIG_MAPPING[text_model_type](**a_	)

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

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



	@classmethod
	def   _lowerCamelCase    (   cls		,      a_		,      a_		,      a_		,      **a_		,      ):
			return cls(
			    vision_config=vision_config.to_dict()		,      qformer_config=qformer_config.to_dict()		,      text_config=text_config.to_dict()		,      **a_		,      )





	def   _lowerCamelCase    (   self	):
			lowerCAmelCase     :    Any						=   copy.deepcopy(self.__dict__	)
			lowerCAmelCase     :    List[str]						=   self.vision_config.to_dict()
			lowerCAmelCase     :    Optional[int]						=   self.qformer_config.to_dict()
			lowerCAmelCase     :    List[Any]						=   self.text_config.to_dict()
			lowerCAmelCase     :    str						=   self.__class__.model_type
			return output










'''simple docstring'''






from __future__ import annotations






def      __A						(							a_						:  float      ,a_						:  float      ,a_						:  float      ,):
		if (stress, tangential_force, area).count(0	) != 1:
				raise ValueError("You cannot supply more or less than 2 values"	)
		elif stress < 0:
				raise ValueError("Stress cannot be negative"	)
		elif tangential_force < 0:
				raise ValueError("Tangential Force cannot be negative"	)
		elif area < 0:
				raise ValueError("Area cannot be negative"	)
		elif stress == 0:
				return (
				    "stress",
				    tangential_force / area,
				)
		elif tangential_force == 0:
				return (
				    "tangential_force",
				    stress * area,
				)
		else:
				return (
				    "area",
				    tangential_force / stress,
				)


if __name__ == "__main__":
					import doctest

					doctest.testmod()



