



"""simple docstring"""







import copy
import os
from typing import Union

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


A		=						logging.get_logger(__name__)

A		=						{
    '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  ( SCREAMING_SNAKE_CASE__):
			__magic_name__     					=     """blip_text_model"""



			def __init__(			self							:				Any   ,	_lowercase							:				Optional[Any]=30524   ,	_lowercase							:				Tuple=768   ,	_lowercase							:				Optional[int]=768   ,	_lowercase							:				Any=3072   ,	_lowercase							:				List[Any]=768   ,	_lowercase							:				int=12   ,	_lowercase							:				Any=8   ,	_lowercase							:				List[Any]=512   ,	_lowercase							:				List[str]="gelu"   ,	_lowercase							:				str=1E-12   ,	_lowercase							:				str=0.0   ,	_lowercase							:				List[str]=0.0   ,	_lowercase							:				Tuple=0.02   ,	_lowercase							:				str=30522   ,	_lowercase							:				Any=2   ,	_lowercase							:				Optional[Any]=0   ,	_lowercase							:				int=102   ,	_lowercase							:				Tuple=True   ,	_lowercase							:				Optional[int]=True   ,	**_lowercase							:				str   ,	)							->					List[Any]:
									super().__init__(
									    pad_token_id=_lowercase   ,	bos_token_id=_lowercase   ,	eos_token_id=_lowercase   ,	sep_token_id=_lowercase   ,	**_lowercase   ,	)

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



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

									snake_case    ,			snake_case   :			int						    = cls.get_config_dict(_lowercase   ,	**_lowercase		)

									# get the text config dict if we are loading from BlipConfig
									if config_dict.get("model_type"		) == "blip":
															snake_case   :			List[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(_lowercase   ,	**_lowercase		)



class       _a  ( SCREAMING_SNAKE_CASE__):
			__magic_name__     					=     """blip_vision_model"""



			def __init__(			self							:				str   ,	_lowercase							:				Optional[Any]=768   ,	_lowercase							:				Dict=3072   ,	_lowercase							:				Tuple=512   ,	_lowercase							:				Optional[int]=12   ,	_lowercase							:				Optional[int]=12   ,	_lowercase							:				str=384   ,	_lowercase							:				Union[str, Any]=16   ,	_lowercase							:				int="gelu"   ,	_lowercase							:				Dict=1E-5   ,	_lowercase							:				Any=0.0   ,	_lowercase							:				int=1E-10   ,	**_lowercase							:				Optional[Any]   ,	)							->					Optional[Any]:
									super().__init__(**_lowercase		)

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



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

									snake_case    ,			snake_case   :			Dict						    = cls.get_config_dict(_lowercase   ,	**_lowercase		)

									# get the vision config dict if we are loading from BlipConfig
									if config_dict.get("model_type"		) == "blip":
															snake_case   :			Dict						    = 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(_lowercase   ,	**_lowercase		)



class       _a  ( SCREAMING_SNAKE_CASE__):
			__magic_name__     					=     """blip"""
			__magic_name__     					=     True



			def __init__(			self							:				Any   ,	_lowercase							:				str=None   ,	_lowercase							:				Tuple=None   ,	_lowercase							:				List[Any]=512   ,	_lowercase							:				Any=2.6592   ,	_lowercase							:				List[str]=256   ,	**_lowercase							:				List[str]   ,	)							->					Dict:
									super().__init__(**_lowercase		)

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

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

									snake_case   :			Tuple						    = BlipTextConfig(**_lowercase		)
									snake_case   :			Optional[int]						    = BlipVisionConfig(**_lowercase		)

									snake_case   :			Tuple						    = self.vision_config.hidden_size

									snake_case   :			Union[str, Any]						    = projection_dim
									snake_case   :			List[Any]						    = logit_scale_init_value
									snake_case   :			str						    = 1.0
									snake_case   :			Union[str, Any]						    = 0.02
									snake_case   :			List[str]						    = image_text_hidden_size



			@classmethod
			def 				__lowercase					(			cls							:				Union[str, Any]   ,	_lowercase							:				BlipTextConfig   ,	_lowercase							:				BlipVisionConfig   ,	**_lowercase							:				int		)							->					str:
									return cls(text_config=text_config.to_dict()   ,	vision_config=vision_config.to_dict()   ,	**_lowercase		)



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








"""simple docstring"""







# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re

from ..utils import cached_file


# docstyle-ignore
A		=						'\nHuman: <<task>>\n\nAssistant: '


A		=						'huggingface-tools/default-prompts'
A		=						{'chat': 'chat_prompt_template.txt', 'run': 'run_prompt_template.txt'}

def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							Optional[int]     ,		lowerCamelCase_:							str     ,		lowerCamelCase_:							Tuple="run" ):
						"""simple docstring"""






						if prompt_or_repo_id is None:
												snake_case   :			Any						    = DEFAULT_PROMPTS_REPO

						# prompt is considered a repo ID when it does not contain any kind of space
						if re.search("\\s"     ,		lowerCamelCase_ ) is not None:
												return prompt_or_repo_id

						snake_case   :			Optional[int]						    = cached_file(
						    lowerCamelCase_     ,		PROMPT_FILES[mode]     ,		repo_type="dataset"     ,		user_agent={"agent": agent_name} )
						with open(lowerCamelCase_     ,		"r"     ,		encoding="utf-8" ) as f:
												return f.read()



