






'''simple docstring'''







import copy
import os
from typing import Union

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


__lowerCAmelCase       		=      logging.get_logger(__name__)

__lowerCAmelCase       		=      {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}





class 	SCREAMING_SNAKE_CASE					(					lowerCAmelCase__       ):
			snake_case__  =				"altclip_text_model"






			def __init__( self      :			str  ,						__SCREAMING_SNAKE_CASE      :			str=25_0002  ,						__SCREAMING_SNAKE_CASE      :			Any=1024  ,						__SCREAMING_SNAKE_CASE      :			List[str]=24  ,						__SCREAMING_SNAKE_CASE      :			Dict=16  ,						__SCREAMING_SNAKE_CASE      :			List[str]=4096  ,						__SCREAMING_SNAKE_CASE      :			Dict="gelu"  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]=0.1  ,						__SCREAMING_SNAKE_CASE      :			Tuple=0.1  ,						__SCREAMING_SNAKE_CASE      :			List[Any]=514  ,						__SCREAMING_SNAKE_CASE      :			Optional[int]=1  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]=0.02  ,						__SCREAMING_SNAKE_CASE      :			Tuple=0.02  ,						__SCREAMING_SNAKE_CASE      :			int=1e-05  ,						__SCREAMING_SNAKE_CASE      :			Any=1  ,						__SCREAMING_SNAKE_CASE      :			Dict=0  ,						__SCREAMING_SNAKE_CASE      :			Any=2  ,						__SCREAMING_SNAKE_CASE      :			int="absolute"  ,						__SCREAMING_SNAKE_CASE      :			Dict=True  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]=768  ,						**__SCREAMING_SNAKE_CASE      :			Union[str, Any]  ,						)			->			Any:
							super().__init__(pad_token_id=_lowerCamelCase  ,						bos_token_id=_lowerCamelCase  ,						eos_token_id=_lowerCamelCase  ,						**_lowerCamelCase					)

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





class 	SCREAMING_SNAKE_CASE					(					lowerCAmelCase__       ):
			snake_case__  =				"altclip_vision_model"






			def __init__( self      :			str  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]=768  ,						__SCREAMING_SNAKE_CASE      :			List[Any]=3072  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]=512  ,						__SCREAMING_SNAKE_CASE      :			Optional[int]=12  ,						__SCREAMING_SNAKE_CASE      :			Dict=12  ,						__SCREAMING_SNAKE_CASE      :			List[Any]=3  ,						__SCREAMING_SNAKE_CASE      :			str=224  ,						__SCREAMING_SNAKE_CASE      :			Optional[int]=32  ,						__SCREAMING_SNAKE_CASE      :			List[Any]="quick_gelu"  ,						__SCREAMING_SNAKE_CASE      :			Dict=1e-5  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]=0.0  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]=0.02  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]=1.0  ,						**__SCREAMING_SNAKE_CASE      :			List[Any]  ,						)			->			str:
							super().__init__(**_lowerCamelCase					)

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







			@classmethod
			def 			SCREAMING_SNAKE_CASE      ( cls      :			Optional[int]  ,						__SCREAMING_SNAKE_CASE      :			List[Any]  ,						**__SCREAMING_SNAKE_CASE      :			Any					)			->			"PretrainedConfig":
							cls._set_token_in_kwargs(_lowerCamelCase					)

							a_				,			a_		:  Tuple											=      cls.get_config_dict(_lowerCamelCase  ,						**_lowerCamelCase					)

							# get the vision config dict if we are loading from AltCLIPConfig
							if config_dict.get('''model_type'''					) == "altclip":
											a_		:  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(_lowerCamelCase  ,						**_lowerCamelCase					)





class 	SCREAMING_SNAKE_CASE					(					lowerCAmelCase__       ):
			snake_case__  =				"altclip"
			snake_case__  =				True






			def __init__( self      :			Optional[Any]  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]=None  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]=None  ,						__SCREAMING_SNAKE_CASE      :			int=768  ,						__SCREAMING_SNAKE_CASE      :			int=2.6592  ,						**__SCREAMING_SNAKE_CASE      :			Dict					)			->			List[Any]:
							a_		:  List[str]											=      kwargs.pop('''text_config_dict'''  ,						_lowerCamelCase					)
							a_		:  Tuple											=      kwargs.pop('''vision_config_dict'''  ,						_lowerCamelCase					)

							super().__init__(**_lowerCamelCase					)

							# 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:
															a_		:  str											=      {}

											# This is the complete result when using `text_config_dict`.
											a_		:  List[str]											=      AltCLIPTextConfig(**_lowerCamelCase					).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:
																							a_		:  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:
																							a_		:  List[str]											=      (
																							    f'`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '
																							    f'value `text_config[\"{key}\"]` will be overriden.'
																							)
																			logger.warning(_lowerCamelCase					)

            # 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:
															a_		:  str											=      {}

											# This is the complete result when using `vision_config_dict`.
											a_		:  Optional[int]											=      AltCLIPVisionConfig(**_lowerCamelCase					).to_dict()
											# convert keys to string instead of integer
											if "id2label" in _vision_config_dict:
															a_		:  Any											=      {
															    str(_lowerCamelCase					): 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:
																							a_		:  str											=      (
																							    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:
																							a_		:  str											=      (
																							    f'`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '
																							    f'The value `vision_config[\"{key}\"]` will be overriden.'
																							)
																			logger.warning(_lowerCamelCase					)

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

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

							if vision_config is None:
											a_		:  List[Any]											=      {}
											logger.info('''`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'''					)

							a_		:  List[Any]											=      AltCLIPTextConfig(**_lowerCamelCase					)
							a_		:  int											=      AltCLIPVisionConfig(**_lowerCamelCase					)

							a_		:  List[Any]											=      projection_dim
							a_		:  int											=      logit_scale_init_value
							a_		:  int											=      1.0






			@classmethod
			def 			SCREAMING_SNAKE_CASE      ( cls      :			Any  ,						__SCREAMING_SNAKE_CASE      :			Dict  ,						__SCREAMING_SNAKE_CASE      :			Dict  ,						**__SCREAMING_SNAKE_CASE      :			Dict					)			->			List[Any]:
							return cls(text_config=text_config.to_dict()  ,						vision_config=vision_config.to_dict()  ,						**_lowerCamelCase					)







			def 			SCREAMING_SNAKE_CASE      ( self      :			List[Any]					)			->			List[Any]:
							a_		:  List[Any]											=      copy.deepcopy(self.__dict__					)
							a_		:  Tuple											=      self.text_config.to_dict()
							a_		:  List[str]											=      self.vision_config.to_dict()
							a_		:  Any											=      self.__class__.model_type
							return output












'''simple docstring'''







import warnings


warnings.warn(
    'memory_utils has been reorganized to utils.memory. Import `find_executable_batchsize` from the main `__init__`: '
    '`from accelerate import find_executable_batch_size` to avoid this warning.',
    FutureWarning,
)




