



'''simple docstring'''



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_  :							Optional[int]             =    logging.get_logger(__name__)

lowerCAmelCase_  :							Any             =    {
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}
class 						lowerCamelCase_				(       __A      ):
						_lowerCAmelCase  : Any						  =					'align_text_model'







						def __init__(	self :   Tuple					,     lowerCAmelCase__ :   int=3_05_22					,     lowerCAmelCase__ :   int=7_68					,     lowerCAmelCase__ :   Optional[int]=12					,     lowerCAmelCase__ :   Union[str, Any]=12					,     lowerCAmelCase__ :   List[str]=30_72					,     lowerCAmelCase__ :   str="gelu"					,     lowerCAmelCase__ :   int=0.1					,     lowerCAmelCase__ :   Tuple=0.1					,     lowerCAmelCase__ :   str=5_12					,     lowerCAmelCase__ :   List[str]=2					,     lowerCAmelCase__ :   Dict=0.02					,     lowerCAmelCase__ :   Optional[int]=1e-12					,     lowerCAmelCase__ :   List[Any]=0					,     lowerCAmelCase__ :   str="absolute"					,     lowerCAmelCase__ :   Optional[int]=True					,     **lowerCAmelCase__ :   Optional[int]					,     ):

													"""simple docstring"""
													super().__init__(**lowerCAmelCase__					)

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







						@classmethod
						def        __lowercase     (	cls :   int					,     lowerCAmelCase__ :   Union[str, os.PathLike]					,     **lowerCAmelCase__ :   List[str]					):

													"""simple docstring"""
													cls._set_token_in_kwargs(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   int         =      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       :   Dict         =      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 						lowerCamelCase_				(       __A      ):
						_lowerCAmelCase  : Dict						  =					'align_vision_model'







						def __init__(	self :   int					,     lowerCAmelCase__ :   int = 3					,     lowerCAmelCase__ :   int = 6_00					,     lowerCAmelCase__ :   float = 2.0					,     lowerCAmelCase__ :   float = 3.1					,     lowerCAmelCase__ :   int = 8					,     lowerCAmelCase__ :   List[int] = [3, 3, 5, 3, 5, 5, 3]					,     lowerCAmelCase__ :   List[int] = [32, 16, 24, 40, 80, 1_12, 1_92]					,     lowerCAmelCase__ :   List[int] = [16, 24, 40, 80, 1_12, 1_92, 3_20]					,     lowerCAmelCase__ :   List[int] = []					,     lowerCAmelCase__ :   List[int] = [1, 2, 2, 2, 1, 2, 1]					,     lowerCAmelCase__ :   List[int] = [1, 2, 2, 3, 3, 4, 1]					,     lowerCAmelCase__ :   List[int] = [1, 6, 6, 6, 6, 6, 6]					,     lowerCAmelCase__ :   float = 0.25					,     lowerCAmelCase__ :   str = "swish"					,     lowerCAmelCase__ :   int = 25_60					,     lowerCAmelCase__ :   str = "mean"					,     lowerCAmelCase__ :   float = 0.02					,     lowerCAmelCase__ :   float = 0.001					,     lowerCAmelCase__ :   float = 0.99					,     lowerCAmelCase__ :   float = 0.2					,     **lowerCAmelCase__ :   List[Any]					,     ):

													"""simple docstring"""
													super().__init__(**lowerCAmelCase__					)

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







						@classmethod
						def        __lowercase     (	cls :   int					,     lowerCAmelCase__ :   Union[str, os.PathLike]					,     **lowerCAmelCase__ :   Dict					):

													"""simple docstring"""
													cls._set_token_in_kwargs(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   str         =      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       :   List[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 						lowerCamelCase_				(       __A      ):
						_lowerCAmelCase  : Tuple						  =					'align'
						_lowerCAmelCase  : List[Any]						  =					True







						def __init__(	self :   Dict					,     lowerCAmelCase__ :   Optional[Any]=None					,     lowerCAmelCase__ :   List[str]=None					,     lowerCAmelCase__ :   List[str]=6_40					,     lowerCAmelCase__ :   Optional[Any]=1.0					,     lowerCAmelCase__ :   int=0.02					,     **lowerCAmelCase__ :   Optional[Any]					,     ):

													"""simple docstring"""
													super().__init__(**lowerCAmelCase__					)

													if text_config is None:
																				SCREAMING_SNAKE_CASE       :   int         =      {}
																				logger.info('''text_config is None. Initializing the AlignTextConfig with default values.'''					)

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

													SCREAMING_SNAKE_CASE       :   List[Any]         =      AlignTextConfig(**lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      AlignVisionConfig(**lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   int         =      projection_dim
													SCREAMING_SNAKE_CASE       :   Dict         =      temperature_init_value
													SCREAMING_SNAKE_CASE       :   str         =      initializer_range







						@classmethod
						def        __lowercase     (	cls :   Union[str, Any]					,     lowerCAmelCase__ :   AlignTextConfig					,     lowerCAmelCase__ :   AlignVisionConfig					,     **lowerCAmelCase__ :   Tuple					):

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







						def        __lowercase     (	self :   Any					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      copy.deepcopy(self.__dict__					)
													SCREAMING_SNAKE_CASE       :   Any         =      self.text_config.to_dict()
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      self.vision_config.to_dict()
													SCREAMING_SNAKE_CASE       :   str         =      self.__class__.model_type
													return output







def 			lowerCamelCase__			(       _a				,      _a):
	SCREAMING_SNAKE_CASE :   Optional[int]					  =							0
	while b > 0:
		if b & 1:
			res += a

		a += a
		b >>= 1

	return res

def 			lowerCamelCase__			(       _a				,      _a				,      _a):
	SCREAMING_SNAKE_CASE :   Optional[int]					  =							0
	while b > 0:
		if b & 1:
			SCREAMING_SNAKE_CASE :   Optional[Any]					  =							((res % c) + (a % c)) % c

		a += a
		b >>= 1

	return res