





import copy
import os
from typing import Union

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


UpperCAmelCase_           =	logging.get_logger(__name__)

UpperCAmelCase_           =	{
    "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 			__UpperCamelCase    (							_UpperCamelCase    ):
     __A	:  Optional[int]							  =   'blip_text_model'





     def __init__(     self				,							_UpperCamelCase=30524				,							_UpperCamelCase=768				,							_UpperCamelCase=768				,							_UpperCamelCase=3072				,							_UpperCamelCase=768				,							_UpperCamelCase=12				,							_UpperCamelCase=8				,							_UpperCamelCase=512				,							_UpperCamelCase="gelu"				,							_UpperCamelCase=1e-12				,							_UpperCamelCase=0.0				,							_UpperCamelCase=0.0				,							_UpperCamelCase=0.02				,							_UpperCamelCase=30522				,							_UpperCamelCase=2				,							_UpperCamelCase=0				,							_UpperCamelCase=102				,							_UpperCamelCase=True				,							_UpperCamelCase=True				,							**_UpperCamelCase				,							):
        super().__init__(
            pad_token_id=_UpperCAmelCase				,							bos_token_id=_UpperCAmelCase				,							eos_token_id=_UpperCAmelCase				,							sep_token_id=_UpperCAmelCase				,							**_UpperCAmelCase				,							)

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





     @classmethod
     def 		UpperCamelCase(     cls				,							_UpperCamelCase				,							**_UpperCamelCase					):
        cls._set_token_in_kwargs(_UpperCAmelCase					)

        _UpperCAmelCase           =   cls.get_config_dict(_UpperCAmelCase				,							**_UpperCAmelCase					)

        # get the text config dict if we are loading from BlipConfig
        if config_dict.get('''model_type'''					) == "blip":
           _UpperCAmelCase           =   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 			__UpperCamelCase    (							_UpperCamelCase    ):
     __A	:  List[Any]							  =   'blip_vision_model'





     def __init__(     self				,							_UpperCamelCase=768				,							_UpperCamelCase=3072				,							_UpperCamelCase=512				,							_UpperCamelCase=12				,							_UpperCamelCase=12				,							_UpperCamelCase=384				,							_UpperCamelCase=16				,							_UpperCamelCase="gelu"				,							_UpperCamelCase=1e-5				,							_UpperCamelCase=0.0				,							_UpperCamelCase=1e-10				,							**_UpperCamelCase				,							):
        super().__init__(**_UpperCAmelCase					)

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





     @classmethod
     def 		UpperCamelCase(     cls				,							_UpperCamelCase				,							**_UpperCamelCase					):
        cls._set_token_in_kwargs(_UpperCAmelCase					)

        _UpperCAmelCase           =   cls.get_config_dict(_UpperCAmelCase				,							**_UpperCAmelCase					)

        # get the vision config dict if we are loading from BlipConfig
        if config_dict.get('''model_type'''					) == "blip":
           _UpperCAmelCase           =   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 			__UpperCamelCase    (							_UpperCamelCase    ):
     __A	:  List[str]							  =   'blip'
     __A	:  List[Any]							  =   True





     def __init__(     self				,							_UpperCamelCase=None				,							_UpperCamelCase=None				,							_UpperCamelCase=512				,							_UpperCamelCase=2.6592				,							_UpperCamelCase=256				,							**_UpperCamelCase				,							):
        super().__init__(**_UpperCAmelCase					)

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

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

        _UpperCAmelCase           =   BlipTextConfig(**_UpperCAmelCase					)
        _UpperCAmelCase           =   BlipVisionConfig(**_UpperCAmelCase					)

        _UpperCAmelCase           =   self.vision_config.hidden_size

        _UpperCAmelCase           =   projection_dim
        _UpperCAmelCase           =   logit_scale_init_value
        _UpperCAmelCase           =   1.0
        _UpperCAmelCase           =   0.02
        _UpperCAmelCase           =   image_text_hidden_size





     @classmethod
     def 		UpperCamelCase(     cls				,							_UpperCamelCase				,							_UpperCamelCase				,							**_UpperCamelCase					):
        return cls(text_config=text_config.to_dict()				,							vision_config=vision_config.to_dict()				,							**_UpperCAmelCase					)





     def 		UpperCamelCase(     self					):
        _UpperCAmelCase           =   copy.deepcopy(self.__dict__					)
        _UpperCAmelCase           =   self.text_config.to_dict()
        _UpperCAmelCase           =   self.vision_config.to_dict()
        _UpperCAmelCase           =   self.__class__.model_type
        return output




'''simple docstring'''

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


__lowerCAmelCase		     =  logging.get_logger(__name__)

__lowerCAmelCase		     =  {
    '''s-JoL/Open-Llama-V1''': '''https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json''',
}

class       __magic_name__		(       _UpperCamelCase  ):
							lowerCAmelCase			:       str  							=   'open-llama'







							def __init__(				self   :			str      ,_UpperCAmelCase   :			int=100000      ,_UpperCAmelCase   :			List[str]=4096      ,_UpperCAmelCase   :			Dict=11008      ,_UpperCAmelCase   :			int=32      ,_UpperCAmelCase   :			Union[str, Any]=32      ,_UpperCAmelCase   :			List[str]="silu"      ,_UpperCAmelCase   :			List[Any]=2048      ,_UpperCAmelCase   :			Any=0.02      ,_UpperCAmelCase   :			int=1E-6      ,_UpperCAmelCase   :			Optional[int]=True      ,_UpperCAmelCase   :			Dict=0      ,_UpperCAmelCase   :			Optional[Any]=1      ,_UpperCAmelCase   :			Dict=2      ,_UpperCAmelCase   :			Tuple=False      ,_UpperCAmelCase   :			Dict=True      ,_UpperCAmelCase   :			Dict=0.1      ,_UpperCAmelCase   :			Optional[int]=0.1      ,_UpperCAmelCase   :			List[str]=True      ,_UpperCAmelCase   :			int=True      ,_UpperCAmelCase   :			Union[str, Any]=None      ,**_UpperCAmelCase   :			Optional[int]      ,):
									_a	: str								=				vocab_size
									_a	: str								=				max_position_embeddings
									_a	: List[str]								=				hidden_size
									_a	: Any								=				intermediate_size
									_a	: Union[str, Any]								=				num_hidden_layers
									_a	: Tuple								=				num_attention_heads
									_a	: int								=				hidden_act
									_a	: str								=				initializer_range
									_a	: Any								=				rms_norm_eps
									_a	: Dict								=				use_cache
									_a	: Optional[int]								=				kwargs.pop(
									    'use_memorry_efficient_attention'      ,_UpperCAmelCase						)
									_a	: int								=				hidden_dropout_prob
									_a	: int								=				attention_dropout_prob
									_a	: Union[str, Any]								=				use_stable_embedding
									_a	: str								=				shared_input_output_embedding
									_a	: Any								=				rope_scaling
									self._rope_scaling_validation()

									super().__init__(
									    pad_token_id=_UpperCAmelCase      ,bos_token_id=_UpperCAmelCase      ,eos_token_id=_UpperCAmelCase      ,tie_word_embeddings=_UpperCAmelCase      ,**_UpperCAmelCase      ,)







							def 				__lowercase     (				self   :			Optional[Any]						):
									if self.rope_scaling is None:
											return

									if not isinstance(self.rope_scaling      ,_UpperCAmelCase						) or len(self.rope_scaling						) != 2:
											raise ValueError(
											    '`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '
											    F"""got {self.rope_scaling}"""						)
									_a	: Optional[Any]								=				self.rope_scaling.get('type'      ,_UpperCAmelCase						)
									_a	: Optional[Any]								=				self.rope_scaling.get('factor'      ,_UpperCAmelCase						)
									if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
											raise ValueError(
											    F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"""						)
									if rope_scaling_factor is None or not isinstance(_UpperCAmelCase      ,_UpperCAmelCase						) or rope_scaling_factor <= 1.0:
											raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""						)




