


import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
				pass

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


lowerCAmelCase__			:      Any								=logging.get_logger(__name__)

lowerCAmelCase__			:      Union[str, Any]								={
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""align_text_model"""






							def __init__(      self			,						lowerCAmelCase__=3_0_5_2_2			,						lowerCAmelCase__=7_6_8			,						lowerCAmelCase__=1_2			,						lowerCAmelCase__=1_2			,						lowerCAmelCase__=3_0_7_2			,						lowerCAmelCase__="gelu"			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=5_1_2			,						lowerCAmelCase__=2			,						lowerCAmelCase__=0.02			,						lowerCAmelCase__=1E-12			,						lowerCAmelCase__=0			,						lowerCAmelCase__="absolute"			,						lowerCAmelCase__=True			,						**lowerCAmelCase__			,						):





										"""simple docstring"""




										super().__init__(**lowerCAmelCase__       )

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






							@classmethod
							def 					UpperCamelCase__     (      cls			,						lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										cls._set_token_in_kwargs(lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     Dict					=					cls.get_config_dict(lowerCAmelCase__			,						**lowerCAmelCase__       )

										# get the text config dict if we are loading from AlignConfig
										if config_dict.get('model_type'       ) == "align":
													SCREAMING_SNAKE_CASE_		:     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(lowerCAmelCase__			,						**lowerCAmelCase__       )







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""align_vision_model"""






							def __init__(      self			,						lowerCAmelCase__ = 3			,						lowerCAmelCase__ = 6_0_0			,						lowerCAmelCase__ = 2.0			,						lowerCAmelCase__ = 3.1			,						lowerCAmelCase__ = 8			,						lowerCAmelCase__ = [3, 3, 5, 3, 5, 5, 3]			,						lowerCAmelCase__ = [3_2, 1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2]			,						lowerCAmelCase__ = [1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2, 3_2_0]			,						lowerCAmelCase__ = []			,						lowerCAmelCase__ = [1, 2, 2, 2, 1, 2, 1]			,						lowerCAmelCase__ = [1, 2, 2, 3, 3, 4, 1]			,						lowerCAmelCase__ = [1, 6, 6, 6, 6, 6, 6]			,						lowerCAmelCase__ = 0.25			,						lowerCAmelCase__ = "swish"			,						lowerCAmelCase__ = 2_5_6_0			,						lowerCAmelCase__ = "mean"			,						lowerCAmelCase__ = 0.02			,						lowerCAmelCase__ = 0.001			,						lowerCAmelCase__ = 0.99			,						lowerCAmelCase__ = 0.2			,						**lowerCAmelCase__			,						):





										"""simple docstring"""




										super().__init__(**lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		:     str					=					num_channels
										SCREAMING_SNAKE_CASE_		:     Dict					=					image_size
										SCREAMING_SNAKE_CASE_		:     int					=					width_coefficient
										SCREAMING_SNAKE_CASE_		:     int					=					depth_coefficient
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					depth_divisor
										SCREAMING_SNAKE_CASE_		:     int					=					kernel_sizes
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					in_channels
										SCREAMING_SNAKE_CASE_		:     Dict					=					out_channels
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					depthwise_padding
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					strides
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					num_block_repeats
										SCREAMING_SNAKE_CASE_		:     int					=					expand_ratios
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					squeeze_expansion_ratio
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					hidden_act
										SCREAMING_SNAKE_CASE_		:     Tuple					=					hidden_dim
										SCREAMING_SNAKE_CASE_		:     int					=					pooling_type
										SCREAMING_SNAKE_CASE_		:     Dict					=					initializer_range
										SCREAMING_SNAKE_CASE_		:     int					=					batch_norm_eps
										SCREAMING_SNAKE_CASE_		:     int					=					batch_norm_momentum
										SCREAMING_SNAKE_CASE_		:     Tuple					=					drop_connect_rate
										SCREAMING_SNAKE_CASE_		:     List[str]					=					sum(lowerCAmelCase__       ) * 4






							@classmethod
							def 					UpperCamelCase__     (      cls			,						lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										cls._set_token_in_kwargs(lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     List[Any]					=					cls.get_config_dict(lowerCAmelCase__			,						**lowerCAmelCase__       )

										# get the vision config dict if we are loading from AlignConfig
										if config_dict.get('model_type'       ) == "align":
													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					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 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""align"""
							_UpperCAmelCase      =						True






							def __init__(      self			,						lowerCAmelCase__=None			,						lowerCAmelCase__=None			,						lowerCAmelCase__=6_4_0			,						lowerCAmelCase__=1.0			,						lowerCAmelCase__=0.02			,						**lowerCAmelCase__			,						):





										"""simple docstring"""




										super().__init__(**lowerCAmelCase__       )

										if text_config is None:
													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					{}
													logger.info('text_config is None. Initializing the AlignTextConfig with default values.'       )

										if vision_config is None:
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					{}
													logger.info('vision_config is None. Initializing the AlignVisionConfig with default values.'       )

										SCREAMING_SNAKE_CASE_		:     Tuple					=					AlignTextConfig(**lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Tuple					=					AlignVisionConfig(**lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		:     Any					=					projection_dim
										SCREAMING_SNAKE_CASE_		:     str					=					temperature_init_value
										SCREAMING_SNAKE_CASE_		:     int					=					initializer_range






							@classmethod
							def 					UpperCamelCase__     (      cls			,						lowerCAmelCase__			,						lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




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






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					copy.deepcopy(self.__dict__       )
										SCREAMING_SNAKE_CASE_		:     Any					=					self.text_config.to_dict()
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.vision_config.to_dict()
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.__class__.model_type
										return output









"""simple docstring"""




import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format




class 			__snake_case   :
							__a					 =       None




							def   __a   (     self:    int   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_dict   )
										__lowerCamelCase          =      json.loads(feat_extract.to_json_string()   )
										for key, value in self.feat_extract_dict.items():
													self.assertEqual(obj[key]     ,							A_   )




							def   __a   (     self:    List[str]   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_dict   )

										with tempfile.TemporaryDirectory() as tmpdirname:
													__lowerCamelCase          =      os.path.join(A_     ,							"""feat_extract.json"""   )
													feat_extract_first.to_json_file(A_   )
													__lowerCamelCase          =      self.feature_extraction_class.from_json_file(A_   )

										self.assertEqual(feat_extract_second.to_dict()     ,							feat_extract_first.to_dict()   )




							def   __a   (     self:    Optional[Any]   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_dict   )

										with tempfile.TemporaryDirectory() as tmpdirname:
													__lowerCamelCase          =      feat_extract_first.save_pretrained(A_   )[0]
													check_json_file_has_correct_format(A_   )
													__lowerCamelCase          =      self.feature_extraction_class.from_pretrained(A_   )

										self.assertEqual(feat_extract_second.to_dict()     ,							feat_extract_first.to_dict()   )




							def   __a   (     self:    List[Any]   ):
										__lowerCamelCase          =      self.feature_extraction_class()
										self.assertIsNotNone(A_   )




