

"""simple docstring"""






import copy
import os
from typing import Union

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


snake_case_   :   Union[str, Any]        =       logging.get_logger(__name__)

snake_case_   :   Optional[int]        =       {
    """BAAI/AltCLIP""": """https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json""",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}







class       snake_case__  ( __lowercase     ):
			SCREAMING_SNAKE_CASE__     				=						'''altclip_text_model'''







			def __init__(			self			: Optional[Any]			,  lowercase			: List[str]=25_00_02			,  lowercase			: Optional[int]=10_24			,  lowercase			: str=24			,  lowercase			: List[Any]=16			,  lowercase			: int=40_96			,  lowercase			: Any="gelu"			,  lowercase			: Union[str, Any]=0.1			,  lowercase			: Optional[int]=0.1			,  lowercase			: List[Any]=5_14			,  lowercase			: Any=1			,  lowercase			: List[str]=0.0_2			,  lowercase			: List[str]=0.0_2			,  lowercase			: Optional[int]=1E-05			,  lowercase			: Dict=1			,  lowercase			: Dict=0			,  lowercase			: Union[str, Any]=2			,  lowercase			: str="absolute"			,  lowercase			: Optional[Any]=True			,  lowercase			: Union[str, Any]=7_68			,  **lowercase			: str			,  ):





								'''simple docstring'''



								super().__init__(pad_token_id=_A			,  bos_token_id=_A			,  eos_token_id=_A			,  **_A  )

								UpperCAmelCase			:   Optional[Any]      =				vocab_size
								UpperCAmelCase			:   Dict      =				hidden_size
								UpperCAmelCase			:   Any      =				num_hidden_layers
								UpperCAmelCase			:   List[Any]      =				num_attention_heads
								UpperCAmelCase			:   Optional[Any]      =				hidden_act
								UpperCAmelCase			:   Any      =				intermediate_size
								UpperCAmelCase			:   Dict      =				hidden_dropout_prob
								UpperCAmelCase			:   List[Any]      =				attention_probs_dropout_prob
								UpperCAmelCase			:   List[str]      =				max_position_embeddings
								UpperCAmelCase			:   List[Any]      =				type_vocab_size
								UpperCAmelCase			:   Dict      =				initializer_range
								UpperCAmelCase			:   Dict      =				initializer_factor
								UpperCAmelCase			:   Tuple      =				layer_norm_eps
								UpperCAmelCase			:   str      =				position_embedding_type
								UpperCAmelCase			:   Dict      =				use_cache
								UpperCAmelCase			:   Dict      =				project_dim







class       snake_case__  ( __lowercase     ):
			SCREAMING_SNAKE_CASE__     				=						'''altclip_vision_model'''







			def __init__(			self			: str			,  lowercase			: Optional[Any]=7_68			,  lowercase			: int=30_72			,  lowercase			: Optional[int]=5_12			,  lowercase			: Optional[int]=12			,  lowercase			: List[str]=12			,  lowercase			: Any=3			,  lowercase			: Optional[Any]=2_24			,  lowercase			: str=32			,  lowercase			: Dict="quick_gelu"			,  lowercase			: List[str]=1E-5			,  lowercase			: Dict=0.0			,  lowercase			: Dict=0.0_2			,  lowercase			: Union[str, Any]=1.0			,  **lowercase			: List[Any]			,  ):





								'''simple docstring'''



								super().__init__(**_A  )

								UpperCAmelCase			:   Dict      =				hidden_size
								UpperCAmelCase			:   Union[str, Any]      =				intermediate_size
								UpperCAmelCase			:   List[str]      =				projection_dim
								UpperCAmelCase			:   Any      =				num_hidden_layers
								UpperCAmelCase			:   Dict      =				num_attention_heads
								UpperCAmelCase			:   Tuple      =				num_channels
								UpperCAmelCase			:   Tuple      =				patch_size
								UpperCAmelCase			:   Tuple      =				image_size
								UpperCAmelCase			:   int      =				initializer_range
								UpperCAmelCase			:   List[str]      =				initializer_factor
								UpperCAmelCase			:   Dict      =				attention_dropout
								UpperCAmelCase			:   Dict      =				layer_norm_eps
								UpperCAmelCase			:   Dict      =				hidden_act







			@classmethod
			def 			__lowerCAmelCase				(			cls			: List[str]			,  lowercase			: Union[str, os.PathLike]			,  **lowercase			: Tuple  ):





								'''simple docstring'''



								cls._set_token_in_kwargs(_A  )

								UpperCAmelCase      ,							UpperCAmelCase			:   Dict      =				cls.get_config_dict(_A			,  **_A  )

								# get the vision config dict if we are loading from AltCLIPConfig
								if config_dict.get("model_type"  ) == "altclip":
													UpperCAmelCase			:   int      =				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       snake_case__  ( __lowercase     ):
			SCREAMING_SNAKE_CASE__     				=						'''altclip'''
			SCREAMING_SNAKE_CASE__     				=						True







			def __init__(			self			: List[str]			,  lowercase			: Tuple=None			,  lowercase			: Tuple=None			,  lowercase			: Union[str, Any]=7_68			,  lowercase			: Optional[int]=2.6_5_9_2			,  **lowercase			: Tuple  ):





								'''simple docstring'''



								UpperCAmelCase			:   str      =				kwargs.pop("text_config_dict"			,  _A  )
								UpperCAmelCase			:   Dict      =				kwargs.pop("vision_config_dict"			,  _A  )

								super().__init__(**_A  )

								# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
								# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
								# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
								if text_config_dict is not None:
													if text_config is None:
																		UpperCAmelCase			:   Optional[int]      =				{}

													# This is the complete result when using `text_config_dict`.
													UpperCAmelCase			:   Any      =				AltCLIPTextConfig(**_A  ).to_dict()

													# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
													for key, value in _text_config_dict.items():
																		if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
																							# If specified in `text_config_dict`
																							if key in text_config_dict:
																												UpperCAmelCase			:   Any      =				(
																												    f"""`{key}` is found in both `text_config_dict` and `text_config` but with different values. """
																												    f"""The value `text_config_dict[\"{key}\"]` will be used instead."""
																												)
																							# If inferred from default argument values (just to be super careful)
																							else:
																												UpperCAmelCase			:   int      =				(
																												    f"""`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The """
																												    f"""value `text_config[\"{key}\"]` will be overriden."""
																												)
																							logger.warning(_A  )

            # Update all values in `text_config` with the ones in `_text_config_dict`.
													text_config.update(_text_config_dict  )

								if vision_config_dict is not None:
													if vision_config is None:
																		UpperCAmelCase			:   List[str]      =				{}

													# This is the complete result when using `vision_config_dict`.
													UpperCAmelCase			:   List[Any]      =				AltCLIPVisionConfig(**_A  ).to_dict()
													# convert keys to string instead of integer
													if "id2label" in _vision_config_dict:
																		UpperCAmelCase			:   Dict      =				{
																		    str(_A  ): value for key, value in _vision_config_dict["id2label"].items()
																		}

													# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
													for key, value in _vision_config_dict.items():
																		if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
																							# If specified in `vision_config_dict`
																							if key in vision_config_dict:
																												UpperCAmelCase			:   int      =				(
																												    f"""`{key}` is found in both `vision_config_dict` and `vision_config` but with different """
																												    f"""values. The value `vision_config_dict[\"{key}\"]` will be used instead."""
																												)
																							# If inferred from default argument values (just to be super careful)
																							else:
																												UpperCAmelCase			:   Dict      =				(
																												    f"""`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. """
																												    f"""The value `vision_config[\"{key}\"]` will be overriden."""
																												)
																							logger.warning(_A  )

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
													vision_config.update(_vision_config_dict  )

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

								if vision_config is None:
													UpperCAmelCase			:   Dict      =				{}
													logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."  )

								UpperCAmelCase			:   List[Any]      =				AltCLIPTextConfig(**_A  )
								UpperCAmelCase			:   List[str]      =				AltCLIPVisionConfig(**_A  )

								UpperCAmelCase			:   Optional[int]      =				projection_dim
								UpperCAmelCase			:   str      =				logit_scale_init_value
								UpperCAmelCase			:   str      =				1.0







			@classmethod
			def 			__lowerCAmelCase				(			cls			: int			,  lowercase			: AltCLIPTextConfig			,  lowercase			: AltCLIPVisionConfig			,  **lowercase			: List[str]  ):





								'''simple docstring'''



								return cls(text_config=text_config.to_dict()			,  vision_config=vision_config.to_dict()			,  **_A  )







			def 			__lowerCAmelCase				(			self			: int  ):





								'''simple docstring'''



								UpperCAmelCase			:   List[Any]      =				copy.deepcopy(self.__dict__  )
								UpperCAmelCase			:   Union[str, Any]      =				self.text_config.to_dict()
								UpperCAmelCase			:   Union[str, Any]      =				self.vision_config.to_dict()
								UpperCAmelCase			:   Optional[Any]      =				self.__class__.model_type
								return output





"""simple docstring"""






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


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

snake_case_   :   List[Any]        =       {
    """RWKV/rwkv-4-169m-pile""": """https://huggingface.co/RWKV/rwkv-4-169m-pile/resolve/main/config.json""",
    """RWKV/rwkv-4-430m-pile""": """https://huggingface.co/RWKV/rwkv-4-430m-pile/resolve/main/config.json""",
    """RWKV/rwkv-4-1b5-pile""": """https://huggingface.co/RWKV/rwkv-4-1b5-pile/resolve/main/config.json""",
    """RWKV/rwkv-4-3b-pile""": """https://huggingface.co/RWKV/rwkv-4-3b-pile/resolve/main/config.json""",
    """RWKV/rwkv-4-7b-pile""": """https://huggingface.co/RWKV/rwkv-4-7b-pile/resolve/main/config.json""",
    """RWKV/rwkv-4-14b-pile""": """https://huggingface.co/RWKV/rwkv-4-14b-pile/resolve/main/config.json""",
    """RWKV/rwkv-raven-1b5""": """https://huggingface.co/RWKV/rwkv-raven-1b5/resolve/main/config.json""",
    """RWKV/rwkv-raven-3b""": """https://huggingface.co/RWKV/rwkv-raven-3b/resolve/main/config.json""",
    """RWKV/rwkv-raven-7b""": """https://huggingface.co/RWKV/rwkv-raven-7b/resolve/main/config.json""",
    """RWKV/rwkv-raven-14b""": """https://huggingface.co/RWKV/rwkv-raven-14b/resolve/main/config.json""",
}







class       snake_case__  ( lowerCAmelCase_     ):
			SCREAMING_SNAKE_CASE__     				=						'''rwkv'''
			SCREAMING_SNAKE_CASE__     				=						{'''max_position_embeddings''': '''context_length'''}







			def __init__(			self			: int			,  lowercase			: Optional[Any]=5_02_77			,  lowercase			: Union[str, Any]=10_24			,  lowercase			: Union[str, Any]=40_96			,  lowercase			: List[str]=32			,  lowercase			: str=None			,  lowercase			: Tuple=None			,  lowercase			: Dict=1E-5			,  lowercase			: Any=0			,  lowercase			: List[Any]=0			,  lowercase			: int=6			,  lowercase			: Dict=False			,  lowercase			: Dict=True			,  **lowercase			: Optional[Any]			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   Optional[int]      =				vocab_size
								UpperCAmelCase			:   List[str]      =				context_length
								UpperCAmelCase			:   Optional[Any]      =				hidden_size
								UpperCAmelCase			:   List[Any]      =				num_hidden_layers
								UpperCAmelCase			:   Union[str, Any]      =				attention_hidden_size if attention_hidden_size is not None else hidden_size
								UpperCAmelCase			:   List[Any]      =				intermediate_size if intermediate_size is not None else 4 * hidden_size
								UpperCAmelCase			:   Tuple      =				layer_norm_epsilon
								UpperCAmelCase			:   Optional[int]      =				rescale_every
								UpperCAmelCase			:   Tuple      =				use_cache

								UpperCAmelCase			:   Union[str, Any]      =				bos_token_id
								UpperCAmelCase			:   Optional[int]      =				eos_token_id

								super().__init__(
								    tie_word_embeddings=lowercase			,  bos_token_id=lowercase			,  eos_token_id=lowercase			,  **lowercase  )


