
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


snake_case					:						Optional[Any]				 =    logging.get_logger(__name__)

snake_case					:						List[Any]				 =    {
    """shi-labs/nat-mini-in1k-224""": """https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json""",
    # See all Nat models at https://huggingface.co/models?filter=nat
}





class  _snake_case   (	a_							,		a_							):
			UpperCamelCase__        =       'nat'

			UpperCamelCase__        =       {
			    'num_attention_heads': 'num_heads',
			    'num_hidden_layers': 'num_layers',
			}







			def __init__(							self		,  _a=4		,  _a=3		,  _a=64		,  _a=[3, 4, 6, 5]		,  _a=[2, 4, 8, 16]		,  _a=7		,  _a=3.0		,  _a=True		,  _a=0.0		,  _a=0.0		,  _a=0.1		,  _a="gelu"		,  _a=0.02		,  _a=1e-5		,  _a=0.0		,  _a=None		,  _a=None		,  **_a		,  ):
				super().__init__(**__SCREAMING_SNAKE_CASE						)

				__magic_name__						:						Optional[int]        =	patch_size
				__magic_name__						:						Tuple        =	num_channels
				__magic_name__						:						Optional[int]        =	embed_dim
				__magic_name__						:						List[str]        =	depths
				__magic_name__						:						str        =	len(__SCREAMING_SNAKE_CASE						)
				__magic_name__						:						List[str]        =	num_heads
				__magic_name__						:						Any        =	kernel_size
				__magic_name__						:						Tuple        =	mlp_ratio
				__magic_name__						:						Optional[Any]        =	qkv_bias
				__magic_name__						:						str        =	hidden_dropout_prob
				__magic_name__						:						Optional[int]        =	attention_probs_dropout_prob
				__magic_name__						:						Union[str, Any]        =	drop_path_rate
				__magic_name__						:						int        =	hidden_act
				__magic_name__						:						Dict        =	layer_norm_eps
				__magic_name__						:						Dict        =	initializer_range
				# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
				# this indicates the channel dimension after the last stage of the model
				__magic_name__						:						Optional[int]        =	int(embed_dim * 2 ** (len(__SCREAMING_SNAKE_CASE						) - 1)						)
				__magic_name__						:						Optional[Any]        =	layer_scale_init_value
				__magic_name__						:						List[Any]        =	["stem"] + [f'''stage{idx}''' for idx in range(1		,  len(__SCREAMING_SNAKE_CASE						) + 1						)]
				__magic_name__  ,       __magic_name__						:						Optional[int]        =	get_aligned_output_features_output_indices(
				    out_features=__SCREAMING_SNAKE_CASE		,  out_indices=__SCREAMING_SNAKE_CASE		,  stage_names=self.stage_names						)

import copy
import os
from typing import Union

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


SCREAMING_SNAKE_CASE			:						List[Any]				  =		logging.get_logger(__name__)

SCREAMING_SNAKE_CASE			:						Optional[int]				  =		{
    """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  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip_text_model"""

  def __init__(		self			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   str=3_05_24  ,				__SCREAMING_SNAKE_CASE			:   Any=7_68  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=7_68  ,				__SCREAMING_SNAKE_CASE			:   Tuple=30_72  ,				__SCREAMING_SNAKE_CASE			:   Any=7_68  ,				__SCREAMING_SNAKE_CASE			:   Tuple=12  ,				__SCREAMING_SNAKE_CASE			:   Dict=8  ,				__SCREAMING_SNAKE_CASE			:   int=5_12  ,				__SCREAMING_SNAKE_CASE			:   List[Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   int=1E-12  ,				__SCREAMING_SNAKE_CASE			:   Tuple=0.0  ,				__SCREAMING_SNAKE_CASE			:   Tuple=0.0  ,				__SCREAMING_SNAKE_CASE			:   Dict=0.02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=3_05_22  ,				__SCREAMING_SNAKE_CASE			:   Any=2  ,				__SCREAMING_SNAKE_CASE			:   List[str]=0  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=1_02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=True  ,				__SCREAMING_SNAKE_CASE			:   Dict=True  ,				**__SCREAMING_SNAKE_CASE			:   str  ,				):
   super().__init__(
       pad_token_id=__SCREAMING_SNAKE_CASE  ,				bos_token_id=__SCREAMING_SNAKE_CASE  ,				eos_token_id=__SCREAMING_SNAKE_CASE  ,				sep_token_id=__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE  ,				)

   __a							=	vocab_size
   __a							=	hidden_size
   __a							=	encoder_hidden_size
   __a							=	intermediate_size
   __a							=	projection_dim
   __a							=	hidden_dropout_prob
   __a							=	num_hidden_layers
   __a							=	num_attention_heads
   __a							=	max_position_embeddings
   __a							=	layer_norm_eps
   __a							=	hidden_act
   __a							=	initializer_range
   __a							=	attention_probs_dropout_prob
   __a							=	is_decoder
   __a							=	use_cache

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, os.PathLike]  ,				**__SCREAMING_SNAKE_CASE			:   int							):
   cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE							)

   __a							,  __a							=	cls.get_config_dict(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   # get the text config dict if we are loading from BlipConfig
   if config_dict.get("model_type"							) == "blip":
    __a							=	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(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip_vision_model"""

  def __init__(		self			:   Optional[int]  ,				__SCREAMING_SNAKE_CASE			:   str=7_68  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=30_72  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=5_12  ,				__SCREAMING_SNAKE_CASE			:   int=12  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=12  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=3_84  ,				__SCREAMING_SNAKE_CASE			:   str=16  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=1E-5  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=0.0  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=1E-10  ,				**__SCREAMING_SNAKE_CASE			:   List[str]  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   __a							=	hidden_size
   __a							=	intermediate_size
   __a							=	projection_dim
   __a							=	num_hidden_layers
   __a							=	num_attention_heads
   __a							=	patch_size
   __a							=	image_size
   __a							=	initializer_range
   __a							=	attention_dropout
   __a							=	layer_norm_eps
   __a							=	hidden_act

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Optional[Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, os.PathLike]  ,				**__SCREAMING_SNAKE_CASE			:   str							):
   cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE							)

   __a							,  __a							=	cls.get_config_dict(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   # get the vision config dict if we are loading from BlipConfig
   if config_dict.get("model_type"							) == "blip":
    __a							=	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(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip"""
  _SCREAMING_SNAKE_CASE     					=      True

  def __init__(		self			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=None  ,				__SCREAMING_SNAKE_CASE			:   Any=None  ,				__SCREAMING_SNAKE_CASE			:   int=5_12  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=2.65_92  ,				__SCREAMING_SNAKE_CASE			:   Any=2_56  ,				**__SCREAMING_SNAKE_CASE			:   Any  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   if text_config is None:
    __a							=	{}
    logger.info("`text_config` is `None`. Initializing the `BlipTextConfig` with default values."							)

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

   __a							=	BlipTextConfig(**__SCREAMING_SNAKE_CASE							)
   __a							=	BlipVisionConfig(**__SCREAMING_SNAKE_CASE							)

   __a							=	self.vision_config.hidden_size

   __a							=	projection_dim
   __a							=	logit_scale_init_value
   __a							=	1.0
   __a							=	0.02
   __a							=	image_text_hidden_size

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Any  ,				__SCREAMING_SNAKE_CASE			:   BlipTextConfig  ,				__SCREAMING_SNAKE_CASE			:   BlipVisionConfig  ,				**__SCREAMING_SNAKE_CASE			:   List[Any]							):
   return cls(text_config=text_config.to_dict()  ,				vision_config=vision_config.to_dict()  ,				**__SCREAMING_SNAKE_CASE							)

  def 		_UpperCAmelCase (		self			:   Union[str, Any]							):
   __a							=	copy.deepcopy(self.__dict__							)
   __a							=	self.text_config.to_dict()
   __a							=	self.vision_config.to_dict()
   __a							=	self.__class__.model_type
   return output


