



import copy
import os
from typing import Union

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


lowercase_										=  logging.get_logger(__name__)

lowercase_										=  {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class 					_snake_case      (       lowercase__):
				UpperCamelCase__					:       Dict  		="altclip_text_model"




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

							lowercase__       	=					vocab_size
							lowercase__       	=					hidden_size
							lowercase__       	=					num_hidden_layers
							lowercase__       	=					num_attention_heads
							lowercase__       	=					hidden_act
							lowercase__       	=					intermediate_size
							lowercase__       	=					hidden_dropout_prob
							lowercase__       	=					attention_probs_dropout_prob
							lowercase__       	=					max_position_embeddings
							lowercase__       	=					type_vocab_size
							lowercase__       	=					initializer_range
							lowercase__       	=					initializer_factor
							lowercase__       	=					layer_norm_eps
							lowercase__       	=					position_embedding_type
							lowercase__       	=					use_cache
							lowercase__       	=					project_dim
class 					_snake_case      (       lowercase__):
				UpperCamelCase__					:       Tuple  		="altclip_vision_model"




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

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




				@classmethod
				def 				A__   (    cls       :    Union[str, Any],       __lowercase       :    List[str],       **__lowercase       :    Union[str, Any]    ):
							cls._set_token_in_kwargs(a_    )

							lowercase__	,							lowercase__       	=					cls.get_config_dict(a_,       **a_    )

							# get the vision config dict if we are loading from AltCLIPConfig
							if config_dict.get("model_type"    ) == "altclip":
										lowercase__       	=					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(a_,       **a_    )
class 					_snake_case      (       lowercase__):
				UpperCamelCase__					:       str  		="altclip"
				UpperCamelCase__					:       Any  		=True




				def __init__(    self       :    Optional[int],       __lowercase       :    List[Any]=None,       __lowercase       :    Optional[int]=None,       __lowercase       :    int=768,       __lowercase       :    Optional[Any]=2.6592,       **__lowercase       :    List[str]    ):
							lowercase__       	=					kwargs.pop("text_config_dict",       a_    )
							lowercase__       	=					kwargs.pop("vision_config_dict",       a_    )

							super().__init__(**a_    )

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

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

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

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

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

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

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

							lowercase__       	=					AltCLIPTextConfig(**a_    )
							lowercase__       	=					AltCLIPVisionConfig(**a_    )

							lowercase__       	=					projection_dim
							lowercase__       	=					logit_scale_init_value
							lowercase__       	=					1.0




				@classmethod
				def 				A__   (    cls       :    Optional[Any],       __lowercase       :    Optional[Any],       __lowercase       :    List[str],       **__lowercase       :    List[str]    ):
							return cls(text_config=text_config.to_dict(),       vision_config=vision_config.to_dict(),       **a_    )




				def 				A__   (    self       :    List[Any]    ):
							lowercase__       	=					copy.deepcopy(self.__dict__    )
							lowercase__       	=					self.text_config.to_dict()
							lowercase__       	=					self.vision_config.to_dict()
							lowercase__       	=					self.__class__.model_type
							return output







'''simple docstring'''




def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : list[int]							, SCREAMING_SNAKE_CASE   : list[int]							, SCREAMING_SNAKE_CASE   : int    ):
  return not any(
      neighbour == 1 and colored_vertices[i] == color
      for i, neighbour in enumerate(SCREAMING_SNAKE_CASE    )    )


def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : list[list[int]]							, SCREAMING_SNAKE_CASE   : int							, SCREAMING_SNAKE_CASE   : list[int]							, SCREAMING_SNAKE_CASE   : int    ):

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

  # Recursive Step
  for i in range(SCREAMING_SNAKE_CASE    ):
    if valid_coloring(graph[index]							, SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE    ):
      # Color current vertex
      UpperCAmelCase    				=						i
      # Validate coloring
      if util_color(SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE							, index + 1    ):
        return True
      # Backtrack
      UpperCAmelCase    				=						-1
  return False



def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : list[list[int]]							, SCREAMING_SNAKE_CASE   : int    ):
  UpperCAmelCase    				=						[-1] * len(SCREAMING_SNAKE_CASE    )

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

  return []


