






"""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  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	_A       :				Tuple    =				"""altclip_text_model"""





	def __init__(self     ,     lowerCAmelCase_=250002     ,     lowerCAmelCase_=1024     ,     lowerCAmelCase_=24     ,     lowerCAmelCase_=16     ,     lowerCAmelCase_=4096     ,     lowerCAmelCase_="gelu"     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=514     ,     lowerCAmelCase_=1     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=1e-0_5     ,     lowerCAmelCase_=1     ,     lowerCAmelCase_=0     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_="absolute"     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=768     ,     **lowerCAmelCase_     ,     ):
		super().__init__(pad_token_id=lowerCAmelCase_     ,     bos_token_id=lowerCAmelCase_     ,     eos_token_id=lowerCAmelCase_     ,     **lowerCAmelCase_							)

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






class      SCREAMING_SNAKE_CASE  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	_A       :				int    =				"""altclip_vision_model"""





	def __init__(self     ,     lowerCAmelCase_=768     ,     lowerCAmelCase_=3072     ,     lowerCAmelCase_=512     ,     lowerCAmelCase_=12     ,     lowerCAmelCase_=12     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=224     ,     lowerCAmelCase_=32     ,     lowerCAmelCase_="quick_gelu"     ,     lowerCAmelCase_=1e-5     ,     lowerCAmelCase_=0.0     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=1.0     ,     **lowerCAmelCase_     ,     ):
		super().__init__(**lowerCAmelCase_							)

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





	@classmethod
	def    lowerCamelCase(cls     ,     lowerCAmelCase_     ,     **lowerCAmelCase_							):
		cls._set_token_in_kwargs(lowerCAmelCase_							)

		A_    ,     A_		:						List[Any]	    =   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_		:						Optional[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(lowerCAmelCase_     ,     **lowerCAmelCase_							)






class      SCREAMING_SNAKE_CASE  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	_A       :				int    =				"""altclip"""
	_A       :				int    =				True





	def __init__(self     ,     lowerCAmelCase_=None     ,     lowerCAmelCase_=None     ,     lowerCAmelCase_=768     ,     lowerCAmelCase_=2.6592     ,     **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!).
		A_		:						Any	    =   kwargs.pop("""text_config_dict"""     ,     lowerCAmelCase_							)
		A_		:						int	    =   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_		:						Any	    =   {}

			# This is the complete result when using `text_config_dict`.
			A_		:						int	    =   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_		:						int	    =   (
						    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_		:						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_		:						List[Any]	    =   {}

			# This is the complete result when using `vision_config_dict`.
			A_		:						Union[str, Any]	    =   AltCLIPVisionConfig(**lowerCAmelCase_							).to_dict()
			# convert keys to string instead of integer
			if "id2label" in _vision_config_dict:
				A_		:						Optional[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_		:						Any	    =   (
						    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_		:						Any	    =   (
						    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_		:						Dict	    =   {}
			logger.info("""`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."""							)

		if vision_config is None:
			A_		:						Optional[Any]	    =   {}
			logger.info("""`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."""							)

		A_		:						Optional[Any]	    =   AltCLIPTextConfig(**lowerCAmelCase_							)
		A_		:						Tuple	    =   AltCLIPVisionConfig(**lowerCAmelCase_							)

		A_		:						Any	    =   projection_dim
		A_		:						List[str]	    =   logit_scale_init_value
		A_		:						List[Any]	    =   1.0





	@classmethod
	def    lowerCamelCase(cls     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     **lowerCAmelCase_							):
		return cls(text_config=text_config.to_dict()     ,     vision_config=vision_config.to_dict()     ,     **lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						int	    =   copy.deepcopy(self.__dict__							)
		A_		:						str	    =   self.text_config.to_dict()
		A_		:						int	    =   self.vision_config.to_dict()
		A_		:						int	    =   self.__class__.model_type
		return output









"""simple docstring"""
def 			__UpperCamelCase	(		snake_case__   ,   snake_case__   ,   snake_case__					):
	return not any(
	    neighbour == 1 and colored_vertices[i] == color
	    for i, neighbour in enumerate(snake_case__					)					)






def 			__UpperCamelCase	(		snake_case__   ,   snake_case__   ,   snake_case__   ,   snake_case__					):

	# Base Case
	if index == len(snake_case__					):
		return True

	# Recursive Step
	for i in range(snake_case__					):
		if valid_coloring(graph[index]   ,   snake_case__   ,   snake_case__					):
			# Color current vertex
			A_		:						Dict	    =   i
			# Validate coloring
			if util_color(snake_case__   ,   snake_case__   ,   snake_case__   ,   index + 1					):
				return True
			# Backtrack
			A_		:						Union[str, Any]	    =   -1
	return False






def 			__UpperCamelCase	(		snake_case__   ,   snake_case__					):
	A_		:						int	    =   [-1] * len(snake_case__					)

	if util_color(snake_case__   ,   snake_case__   ,   snake_case__   ,   0					):
		return colored_vertices

	return []

