


"""simple docstring"""


import copy
import os
from typing import Union

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


UpperCamelCase						:				Optional[Any]             =      logging.get_logger(__name__)

UpperCamelCase						:				Optional[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__						(   UpperCAmelCase_			):
						lowerCAmelCase       =     """altclip_text_model"""







						def __init__(							self   :    Union[str, Any]			,			_lowercase   :    Dict=250_002			,			_lowercase   :    Tuple=1_024			,			_lowercase   :    Dict=24			,			_lowercase   :    Union[str, Any]=16			,			_lowercase   :    Union[str, Any]=4_096			,			_lowercase   :    Union[str, Any]="gelu"			,			_lowercase   :    Any=0.1			,			_lowercase   :    int=0.1			,			_lowercase   :    Dict=514			,			_lowercase   :    int=1			,			_lowercase   :    List[str]=0.0_2			,			_lowercase   :    Tuple=0.0_2			,			_lowercase   :    int=1e-05			,			_lowercase   :    int=1			,			_lowercase   :    Optional[int]=0			,			_lowercase   :    List[str]=2			,			_lowercase   :    Any="absolute"			,			_lowercase   :    Any=True			,			_lowercase   :    str=768			,			**_lowercase   :    Tuple			,			):
								super().__init__(pad_token_id=_lowercase			,			bos_token_id=_lowercase			,			eos_token_id=_lowercase			,			**_lowercase		)

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



class 			lowerCamelCase__						(   UpperCAmelCase_			):
						lowerCAmelCase       =     """altclip_vision_model"""







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

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







						@classmethod
						def __a						(							cls   :    Optional[int]			,			_lowercase   :    Union[str, os.PathLike]			,			**_lowercase   :    int		):
								cls._set_token_in_kwargs(_lowercase		)

								A       , A					       = cls.get_config_dict(_lowercase			,			**_lowercase		)

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



class 			lowerCamelCase__						(   UpperCAmelCase_			):
						lowerCAmelCase       =     """altclip"""
						lowerCAmelCase       =     True







						def __init__(							self   :    List[str]			,			_lowercase   :    Optional[Any]=None			,			_lowercase   :    Optional[Any]=None			,			_lowercase   :    Tuple=768			,			_lowercase   :    List[str]=2.6_5_9_2			,			**_lowercase   :    Union[str, Any]		):
								# 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					       = kwargs.pop('text_config_dict'			,			_lowercase		)
								A					       = kwargs.pop('vision_config_dict'			,			_lowercase		)

								super().__init__(**_lowercase		)

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

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

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

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

            # 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					       = {}
										logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'		)

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

								A					       = AltCLIPTextConfig(**_lowercase		)
								A					       = AltCLIPVisionConfig(**_lowercase		)

								A					       = projection_dim
								A					       = logit_scale_init_value
								A					       = 1.0







						@classmethod
						def __a						(							cls   :    str			,			_lowercase   :    AltCLIPTextConfig			,			_lowercase   :    AltCLIPVisionConfig			,			**_lowercase   :    Any		):
								return cls(text_config=text_config.to_dict()			,			vision_config=vision_config.to_dict()			,			**_lowercase		)







						def __a						(							self   :    Optional[int]		):
								A					       = copy.deepcopy(self.__dict__		)
								A					       = self.text_config.to_dict()
								A					       = self.vision_config.to_dict()
								A					       = self.__class__.model_type
								return output









"""simple docstring"""


from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCamelCase						:				int             =      logging.get_logger(__name__)

UpperCamelCase						:				Optional[int]             =      {
    "google/bit-50": "https://huggingface.co/google/bit-50/resolve/main/config.json",
}



class 			lowerCamelCase__						(   UpperCAmelCase_							,    UpperCAmelCase_			):
						lowerCAmelCase       =     """bit"""
						lowerCAmelCase       =     ["""preactivation""", """bottleneck"""]
						lowerCAmelCase       =     ["""SAME""", """VALID"""]







						def __init__(							self   :    List[str]			,			_lowercase   :    int=3			,			_lowercase   :    List[str]=64			,			_lowercase   :    Optional[int]=[256, 512, 1_024, 2_048]			,			_lowercase   :    Optional[int]=[3, 4, 6, 3]			,			_lowercase   :    int="preactivation"			,			_lowercase   :    Union[str, Any]="relu"			,			_lowercase   :    List[Any]=None			,			_lowercase   :    Tuple=32			,			_lowercase   :    Optional[int]=0.0			,			_lowercase   :    Union[str, Any]=False			,			_lowercase   :    Dict=32			,			_lowercase   :    Union[str, Any]=1			,			_lowercase   :    List[Any]=None			,			_lowercase   :    Any=None			,			**_lowercase   :    str			,			):
								super().__init__(**_lowercase		)
								if layer_type not in self.layer_types:
										raise ValueError(f'layer_type={layer_type} is not one of {",".join(self.layer_types		)}'		)
								if global_padding is not None:
										if global_padding.upper() in self.supported_padding:
												A					       = global_padding.upper()
										else:
												raise ValueError(f'Padding strategy {global_padding} not supported'		)
								A					       = num_channels
								A					       = embedding_size
								A					       = hidden_sizes
								A					       = depths
								A					       = layer_type
								A					       = hidden_act
								A					       = global_padding
								A					       = num_groups
								A					       = drop_path_rate
								A					       = embedding_dynamic_padding
								A					       = output_stride
								A					       = width_factor

								A					       = ['stem'] + [f'stage{idx}' for idx in range(1			,			len(_lowercase		) + 1		)]
								A       , A					       = get_aligned_output_features_output_indices(
								    out_features=_lowercase			,			out_indices=_lowercase			,			stage_names=self.stage_names		)





