





import copy
import os
from typing import Union

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


_UpperCAmelCase       : int			     =       logging.get_logger(__name__)

_UpperCAmelCase       : Optional[Any]			     =       {
    """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      lowerCAmelCase							(      __UpperCamelCase    ):
 UpperCAmelCase__									=	"""blip_text_model"""
 def __init__(   self						:   Dict    ,  UpperCAmelCase						:   Optional[Any]=30524    ,  UpperCAmelCase						:   Tuple=768    ,  UpperCAmelCase						:   str=768    ,  UpperCAmelCase						:   int=3072    ,  UpperCAmelCase						:   Dict=768    ,  UpperCAmelCase						:   Tuple=12    ,  UpperCAmelCase						:   Any=8    ,  UpperCAmelCase						:   int=512    ,  UpperCAmelCase						:   str="gelu"    ,  UpperCAmelCase						:   List[str]=1e-12    ,  UpperCAmelCase						:   str=0.0    ,  UpperCAmelCase						:   List[str]=0.0    ,  UpperCAmelCase						:   List[Any]=0.0_2    ,  UpperCAmelCase						:   Optional[Any]=30522    ,  UpperCAmelCase						:   Dict=2    ,  UpperCAmelCase						:   List[str]=0    ,  UpperCAmelCase						:   Tuple=102    ,  UpperCAmelCase						:   int=True    ,  UpperCAmelCase						:   List[Any]=True    ,  **UpperCAmelCase						:   Dict    ,  )    ->			Any:
     super().__init__(
         pad_token_id=UpperCAmelCase    ,  bos_token_id=UpperCAmelCase    ,  eos_token_id=UpperCAmelCase    ,  sep_token_id=UpperCAmelCase    ,  **UpperCAmelCase    ,  )

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







 @classmethod
 def   A_			(   cls						:   int    ,  UpperCAmelCase						:   Union[str, os.PathLike]    ,  **UpperCAmelCase						:   int			)    ->			"PretrainedConfig":
     cls._set_token_in_kwargs(UpperCAmelCase			)

     lowerCamelCase__				,							lowerCamelCase__					:   List[str]      				=	cls.get_config_dict(UpperCAmelCase    ,  **UpperCAmelCase			)

     # get the text config dict if we are loading from BlipConfig
     if config_dict.get('model_type'			) == "blip":
         lowerCamelCase__					:   str      				=	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      lowerCAmelCase							(      __UpperCamelCase    ):
 UpperCAmelCase__									=	"""blip_vision_model"""
 def __init__(   self						:   Optional[int]    ,  UpperCAmelCase						:   str=768    ,  UpperCAmelCase						:   Dict=3072    ,  UpperCAmelCase						:   Optional[Any]=512    ,  UpperCAmelCase						:   str=12    ,  UpperCAmelCase						:   Dict=12    ,  UpperCAmelCase						:   List[Any]=384    ,  UpperCAmelCase						:   Dict=16    ,  UpperCAmelCase						:   List[str]="gelu"    ,  UpperCAmelCase						:   str=1e-5    ,  UpperCAmelCase						:   Tuple=0.0    ,  UpperCAmelCase						:   List[str]=1e-10    ,  **UpperCAmelCase						:   str    ,  )    ->			str:
     super().__init__(**UpperCAmelCase			)

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







 @classmethod
 def   A_			(   cls						:   Tuple    ,  UpperCAmelCase						:   Union[str, os.PathLike]    ,  **UpperCAmelCase						:   Dict			)    ->			"PretrainedConfig":
     cls._set_token_in_kwargs(UpperCAmelCase			)

     lowerCamelCase__				,							lowerCamelCase__					:   Any      				=	cls.get_config_dict(UpperCAmelCase    ,  **UpperCAmelCase			)

     # get the vision config dict if we are loading from BlipConfig
     if config_dict.get('model_type'			) == "blip":
         lowerCamelCase__					:   List[str]      				=	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      lowerCAmelCase							(      __UpperCamelCase    ):
 UpperCAmelCase__									=	"""blip"""
 UpperCAmelCase__									=	True
 def __init__(   self						:   Any    ,  UpperCAmelCase						:   str=None    ,  UpperCAmelCase						:   List[str]=None    ,  UpperCAmelCase						:   List[Any]=512    ,  UpperCAmelCase						:   Union[str, Any]=2.6_5_9_2    ,  UpperCAmelCase						:   Optional[int]=256    ,  **UpperCAmelCase						:   Optional[Any]    ,  )    ->			List[str]:
     super().__init__(**UpperCAmelCase			)

     if text_config is None:
         lowerCamelCase__					:   Union[str, Any]      				=	{}
         logger.info('`text_config` is `None`. Initializing the `BlipTextConfig` with default values.'			)

     if vision_config is None:
         lowerCamelCase__					:   Optional[int]      				=	{}
         logger.info('`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.'			)

     lowerCamelCase__					:   str      				=	BlipTextConfig(**UpperCAmelCase			)
     lowerCamelCase__					:   int      				=	BlipVisionConfig(**UpperCAmelCase			)

     lowerCamelCase__					:   int      				=	self.vision_config.hidden_size

     lowerCamelCase__					:   Tuple      				=	projection_dim
     lowerCamelCase__					:   int      				=	logit_scale_init_value
     lowerCamelCase__					:   int      				=	1.0
     lowerCamelCase__					:   int      				=	0.0_2
     lowerCamelCase__					:   Optional[Any]      				=	image_text_hidden_size
 @classmethod
 def   A_			(   cls						:   List[Any]    ,  UpperCAmelCase						:   BlipTextConfig    ,  UpperCAmelCase						:   BlipVisionConfig    ,  **UpperCAmelCase						:   Any			)    ->			Tuple:
     return cls(text_config=text_config.to_dict()    ,  vision_config=vision_config.to_dict()    ,  **UpperCAmelCase			)







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












import enum
import shutil
import sys


_UpperCAmelCase     ,_UpperCAmelCase       : List[Any]			     =       shutil.get_terminal_size()

_UpperCAmelCase       : Union[str, Any]			     =       {"""UP""": """A""", """DOWN""": """B""", """RIGHT""": """C""", """LEFT""": """D"""}

class      lowerCAmelCase							(      enum.Enum    ):
 UpperCAmelCase__									=	0
 UpperCAmelCase__									=	1


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase		,			_UpperCAmelCase=""				)    ->  int:
    sys.stdout.write(str(_UpperCAmelCase				) + end				)
    sys.stdout.flush()


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase		,			_UpperCAmelCase		,			_UpperCAmelCase=""				)    ->  Union[str, Any]:
    forceWrite(F"""\u001b[{color}m{content}\u001b[0m"""		,			_UpperCAmelCase				)


def  SCREAMING_SNAKE_CASE   ( )    ->  Dict:
    forceWrite('\r'				)


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase		,			_UpperCAmelCase				)    ->  Optional[Any]:
    forceWrite(F"""\033[{num_lines}{CURSOR_TO_CHAR[direction.upper()]}"""				)


def  SCREAMING_SNAKE_CASE   ( )    ->  int:
    forceWrite(' ' * TERMINAL_WIDTH				)
    reset_cursor()


def  SCREAMING_SNAKE_CASE   ( )    ->  Optional[Any]:
    reset_cursor()
    forceWrite('-' * TERMINAL_WIDTH				)





