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 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						str						=      'altclip_text_model'







    def __init__(	self , __lowercase=250_002 , __lowercase=1_024 , __lowercase=24 , __lowercase=16 , __lowercase=4_096 , __lowercase="gelu" , __lowercase=0.1 , __lowercase=0.1 , __lowercase=514 , __lowercase=1 , __lowercase=0.02 , __lowercase=0.02 , __lowercase=1E-0_5 , __lowercase=1 , __lowercase=0 , __lowercase=2 , __lowercase="absolute" , __lowercase=True , __lowercase=768 , **__lowercase , )       ->	Any:
        super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_ , bos_token_id=SCREAMING_SNAKE_CASE_ , eos_token_id=SCREAMING_SNAKE_CASE_ , **SCREAMING_SNAKE_CASE_)

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


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						Tuple						=      'altclip_vision_model'







    def __init__(	self , __lowercase=768 , __lowercase=3_072 , __lowercase=512 , __lowercase=12 , __lowercase=12 , __lowercase=3 , __lowercase=224 , __lowercase=32 , __lowercase="quick_gelu" , __lowercase=1E-5 , __lowercase=0.0 , __lowercase=0.02 , __lowercase=1.0 , **__lowercase , )       ->	str:
        super().__init__(**SCREAMING_SNAKE_CASE_)

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







    @classmethod
    def 			UpperCamelCase__   (	cls , __lowercase , **__lowercase)       ->	"PretrainedConfig":
        cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_)

        __UpperCamelCase  ,       __UpperCamelCase     :List[str]			  =		cls.get_config_dict(SCREAMING_SNAKE_CASE_ , **SCREAMING_SNAKE_CASE_)

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


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						Any						=      'altclip'
    a__	:						List[str]						=      True







    def __init__(	self , __lowercase=None , __lowercase=None , __lowercase=768 , __lowercase=2.65_92 , **__lowercase)       ->	List[str]:
        # 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!).
        __UpperCamelCase     :Union[str, Any]			  =		kwargs.pop('''text_config_dict''' , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :List[str]			  =		kwargs.pop('''vision_config_dict''' , SCREAMING_SNAKE_CASE_)

        super().__init__(**SCREAMING_SNAKE_CASE_)

        # 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:
                __UpperCamelCase     :Union[str, Any]			  =		{}

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

            # 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:
                __UpperCamelCase     :Optional[int]			  =		{}

            # This is the complete result when using `vision_config_dict`.
            __UpperCamelCase     :Union[str, Any]			  =		AltCLIPVisionConfig(**SCREAMING_SNAKE_CASE_).to_dict()
            # convert keys to string instead of integer
            if "id2label" in _vision_config_dict:
                __UpperCamelCase     :Dict			  =		{
                    str(SCREAMING_SNAKE_CASE_): 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:
                        __UpperCamelCase     :str			  =		(
                            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:
                        __UpperCamelCase     :Optional[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(SCREAMING_SNAKE_CASE_)

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

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

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

        __UpperCamelCase     :int			  =		AltCLIPTextConfig(**SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		AltCLIPVisionConfig(**SCREAMING_SNAKE_CASE_)

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







    @classmethod
    def 			UpperCamelCase__   (	cls , __lowercase , __lowercase , **__lowercase)       ->	List[Any]:
        return cls(text_config=text_config.to_dict() , vision_config=vision_config.to_dict() , **SCREAMING_SNAKE_CASE_)







    def 			UpperCamelCase__   (	self)       ->	Dict:
        __UpperCamelCase     :Optional[Any]			  =		copy.deepcopy(self.__dict__)
        __UpperCamelCase     :List[str]			  =		self.text_config.to_dict()
        __UpperCamelCase     :Any			  =		self.vision_config.to_dict()
        __UpperCamelCase     :Tuple			  =		self.__class__.model_type
        return output







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


__a  			=					logging.get_logger(__name__)
class  lowercase__(				UpperCAmelCase							):



	"""simple docstring"""




	a			:Union[str, Any]         =	'upernet'
	def __init__(       self  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Dict=None       ,							SCREAMING_SNAKE_CASE_  :			str=5_1_2       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.02       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=[1, 2, 3, 6]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=True       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.4       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=3_8_4       ,							SCREAMING_SNAKE_CASE_  :			str=2_5_6       ,							SCREAMING_SNAKE_CASE_  :			Dict=1       ,							SCREAMING_SNAKE_CASE_  :			Tuple=False       ,							SCREAMING_SNAKE_CASE_  :			str=2_5_5       ,							**SCREAMING_SNAKE_CASE_  :			str       ,							)       ->     int:
					super().__init__(**SCREAMING_SNAKE_CASE_       )

					if backbone_config is None:
									logger.info('''`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.'''       )
									lowercase_       =					CONFIG_MAPPING['''resnet'''](out_features=['''stage1''', '''stage2''', '''stage3''', '''stage4''']       )
					elif isinstance(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ):
									lowercase_       =					backbone_config.get('''model_type'''       )
									lowercase_       =					CONFIG_MAPPING[backbone_model_type]
									lowercase_       =					config_class.from_dict(SCREAMING_SNAKE_CASE_       )

					lowercase_       =					backbone_config
					lowercase_       =					hidden_size
					lowercase_       =					initializer_range
					lowercase_       =					pool_scales
					lowercase_       =					use_auxiliary_head
					lowercase_       =					auxiliary_loss_weight
					lowercase_       =					auxiliary_in_channels
					lowercase_       =					auxiliary_channels
					lowercase_       =					auxiliary_num_convs
					lowercase_       =					auxiliary_concat_input
					lowercase_       =					loss_ignore_index




	def 						_lowercase  (       self  :			List[str]       )       ->     List[str]:
					lowercase_       =					copy.deepcopy(self.__dict__       )
					lowercase_       =					self.backbone_config.to_dict()
					lowercase_       =					self.__class__.model_type
					return output




