



import copy
import os
from typing import Union

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


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

__SCREAMING_SNAKE_CASE  :						Union[str, Any]    							=      {
    '''BAAI/AltCLIP''': '''https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json''',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}


class 							lowerCamelCase_(   A__    ):





					'''simple docstring'''



					lowercase__   :       str										= 'altclip_text_model'

					def __init__(    self				,       lowerCamelCase__=2_5_0_0_0_2				,       lowerCamelCase__=1_0_2_4				,       lowerCamelCase__=2_4				,       lowerCamelCase__=1_6				,       lowerCamelCase__=4_0_9_6				,       lowerCamelCase__="gelu"				,       lowerCamelCase__=0.1				,       lowerCamelCase__=0.1				,       lowerCamelCase__=5_1_4				,       lowerCamelCase__=1				,       lowerCamelCase__=0.0_2				,       lowerCamelCase__=0.0_2				,       lowerCamelCase__=1e-05				,       lowerCamelCase__=1				,       lowerCamelCase__=0				,       lowerCamelCase__=2				,       lowerCamelCase__="absolute"				,       lowerCamelCase__=True				,       lowerCamelCase__=7_6_8				,       **lowerCamelCase__				,       ):
									super().__init__(pad_token_id=lowerCamelCase__				,       bos_token_id=lowerCamelCase__				,       eos_token_id=lowerCamelCase__				,       **lowerCamelCase__   )

									_lowerCamelCase        =				vocab_size
									_lowerCamelCase        =				hidden_size
									_lowerCamelCase        =				num_hidden_layers
									_lowerCamelCase        =				num_attention_heads
									_lowerCamelCase        =				hidden_act
									_lowerCamelCase        =				intermediate_size
									_lowerCamelCase        =				hidden_dropout_prob
									_lowerCamelCase        =				attention_probs_dropout_prob
									_lowerCamelCase        =				max_position_embeddings
									_lowerCamelCase        =				type_vocab_size
									_lowerCamelCase        =				initializer_range
									_lowerCamelCase        =				initializer_factor
									_lowerCamelCase        =				layer_norm_eps
									_lowerCamelCase        =				position_embedding_type
									_lowerCamelCase        =				use_cache
									_lowerCamelCase        =				project_dim


class 							lowerCamelCase_(   A__    ):





					'''simple docstring'''



					lowercase__   :       Any										= 'altclip_vision_model'

					def __init__(    self				,       lowerCamelCase__=7_6_8				,       lowerCamelCase__=3_0_7_2				,       lowerCamelCase__=5_1_2				,       lowerCamelCase__=1_2				,       lowerCamelCase__=1_2				,       lowerCamelCase__=3				,       lowerCamelCase__=2_2_4				,       lowerCamelCase__=3_2				,       lowerCamelCase__="quick_gelu"				,       lowerCamelCase__=1e-5				,       lowerCamelCase__=0.0				,       lowerCamelCase__=0.0_2				,       lowerCamelCase__=1.0				,       **lowerCamelCase__				,       ):
									super().__init__(**lowerCamelCase__   )

									_lowerCamelCase        =				hidden_size
									_lowerCamelCase        =				intermediate_size
									_lowerCamelCase        =				projection_dim
									_lowerCamelCase        =				num_hidden_layers
									_lowerCamelCase        =				num_attention_heads
									_lowerCamelCase        =				num_channels
									_lowerCamelCase        =				patch_size
									_lowerCamelCase        =				image_size
									_lowerCamelCase        =				initializer_range
									_lowerCamelCase        =				initializer_factor
									_lowerCamelCase        =				attention_dropout
									_lowerCamelCase        =				layer_norm_eps
									_lowerCamelCase        =				hidden_act





					@classmethod
					def 			snake_case__      (    cls				,       lowerCamelCase__				,       **lowerCamelCase__   ):
									cls._set_token_in_kwargs(lowerCamelCase__   )

									_lowerCamelCase  ,     _lowerCamelCase        =				cls.get_config_dict(lowerCamelCase__				,       **lowerCamelCase__   )

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





					'''simple docstring'''



					lowercase__   :       Optional[int]										= 'altclip'
					lowercase__   :       str										= True

					def __init__(    self				,       lowerCamelCase__=None				,       lowerCamelCase__=None				,       lowerCamelCase__=7_6_8				,       lowerCamelCase__=2.6_5_9_2				,       **lowerCamelCase__   ):
									# If `_config_dict` exist, we use them for the backward compatibility.
									# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
									# of confusion!).
									_lowerCamelCase        =				kwargs.pop('''text_config_dict'''				,       lowerCamelCase__   )
									_lowerCamelCase        =				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:
																	_lowerCamelCase        =				{}

													# This is the complete result when using `text_config_dict`.
													_lowerCamelCase        =				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:
																									_lowerCamelCase        =				(
																									    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:
																									_lowerCamelCase        =				(
																									    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:
																	_lowerCamelCase        =				{}

													# This is the complete result when using `vision_config_dict`.
													_lowerCamelCase        =				AltCLIPVisionConfig(**lowerCamelCase__   ).to_dict()
													# convert keys to string instead of integer
													if "id2label" in _vision_config_dict:
																	_lowerCamelCase        =				{
																	    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:
																									_lowerCamelCase        =				(
																									    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:
																									_lowerCamelCase        =				(
																									    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:
													_lowerCamelCase        =				{}
													logger.info('''`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'''   )

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

									_lowerCamelCase        =				AltCLIPTextConfig(**lowerCamelCase__   )
									_lowerCamelCase        =				AltCLIPVisionConfig(**lowerCamelCase__   )

									_lowerCamelCase        =				projection_dim
									_lowerCamelCase        =				logit_scale_init_value
									_lowerCamelCase        =				1.0

					@classmethod
					def 			snake_case__      (    cls				,       lowerCamelCase__				,       lowerCamelCase__				,       **lowerCamelCase__   ):
									return cls(text_config=text_config.to_dict()				,       vision_config=vision_config.to_dict()				,       **lowerCamelCase__   )





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





"""simple docstring"""
def        lowerCAmelCase_(   lowercase_     :							str						,   lowercase_     :							str							)	->       bool:
				_lowerCamelCase        =				len(lowercase_							)
				_lowerCamelCase        =				len(lowercase_							)
				_lowerCamelCase        =				[[False for _ in range(m + 1							)] for _ in range(n + 1							)]
				_lowerCamelCase        =				True
				for i in range(lowercase_							):
								for j in range(m + 1							):
												if dp[i][j]:
																if j < m and a[i].upper() == b[j]:
																				_lowerCamelCase        =				True
																if a[i].islower():
																				_lowerCamelCase        =				True
				return dp[n][m]


if __name__ == "__main__":
			import doctest

			doctest.testmod()
