






import copy
import os
from typing import Union

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


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

A__			:    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    _UpperCAmelCase      ( _UpperCamelCase			):

				"""simple docstring"""




				lowercase__       							= """altclip_text_model"""




				def __init__(  self		:					List[Any],						lowerCamelCase		:					Union[str, Any]=250_002,						lowerCamelCase		:					Optional[int]=1_024,						lowerCamelCase		:					Union[str, Any]=24,						lowerCamelCase		:					Any=16,						lowerCamelCase		:					List[str]=4_096,						lowerCamelCase		:					str="gelu",						lowerCamelCase		:					Tuple=0.1,						lowerCamelCase		:					Dict=0.1,						lowerCamelCase		:					List[str]=514,						lowerCamelCase		:					Union[str, Any]=1,						lowerCamelCase		:					str=0.02,						lowerCamelCase		:					Optional[int]=0.02,						lowerCamelCase		:					Optional[int]=1E-05,						lowerCamelCase		:					List[Any]=1,						lowerCamelCase		:					int=0,						lowerCamelCase		:					List[str]=2,						lowerCamelCase		:					List[str]="absolute",						lowerCamelCase		:					Optional[int]=True,						lowerCamelCase		:					Union[str, Any]=768,						**lowerCamelCase		:					Optional[int],						):

								'''simple docstring'''
								super().__init__(pad_token_id=_UpperCAmelCase,						bos_token_id=_UpperCAmelCase,						eos_token_id=_UpperCAmelCase,						**_UpperCAmelCase						)

								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    _UpperCAmelCase      ( _UpperCamelCase			):

				"""simple docstring"""




				lowercase__       							= """altclip_vision_model"""




				def __init__(  self		:					List[str],						lowerCamelCase		:					Dict=768,						lowerCamelCase		:					int=3_072,						lowerCamelCase		:					Tuple=512,						lowerCamelCase		:					int=12,						lowerCamelCase		:					Tuple=12,						lowerCamelCase		:					Any=3,						lowerCamelCase		:					int=224,						lowerCamelCase		:					List[str]=32,						lowerCamelCase		:					int="quick_gelu",						lowerCamelCase		:					Union[str, Any]=1E-5,						lowerCamelCase		:					str=0.0,						lowerCamelCase		:					str=0.02,						lowerCamelCase		:					List[str]=1.0,						**lowerCamelCase		:					int,						):

								'''simple docstring'''
								super().__init__(**_UpperCAmelCase						)

								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        lowercase__     (  cls		:					Union[str, Any],						lowerCamelCase		:					List[str],						**lowerCamelCase		:					Optional[Any]						):

								'''simple docstring'''
								cls._set_token_in_kwargs(_UpperCAmelCase						)

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

								# 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(_UpperCAmelCase,						**_UpperCAmelCase						)



class    _UpperCAmelCase      ( _UpperCamelCase			):

				"""simple docstring"""




				lowercase__       							= """altclip"""
				lowercase__       							= True




				def __init__(  self		:					Tuple,						lowerCamelCase		:					Optional[int]=None,						lowerCamelCase		:					Optional[int]=None,						lowerCamelCase		:					Tuple=768,						lowerCamelCase		:					List[str]=2.6592,						**lowerCamelCase		:					List[Any]						):

								'''simple docstring'''
								# 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!).
								lowercase__     				=    kwargs.pop('''text_config_dict''',						_UpperCAmelCase						)
								lowercase__     				=    kwargs.pop('''vision_config_dict''',						_UpperCAmelCase						)

								super().__init__(**_UpperCAmelCase						)

								# 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(**_UpperCAmelCase						).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(_UpperCAmelCase						)

            # 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(**_UpperCAmelCase						).to_dict()
												# convert keys to string instead of integer
												if "id2label" in _vision_config_dict:
																lowercase__     				=    {
																    str(_UpperCAmelCase						): 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(_UpperCAmelCase						)

            # 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(**_UpperCAmelCase						)
								lowercase__     				=    AltCLIPVisionConfig(**_UpperCAmelCase						)

								lowercase__     				=    projection_dim
								lowercase__     				=    logit_scale_init_value
								lowercase__     				=    1.0




				@classmethod
				def        lowercase__     (  cls		:					Optional[int],						lowerCamelCase		:					Dict,						lowerCamelCase		:					Any,						**lowerCamelCase		:					Dict						):

								'''simple docstring'''
								return cls(text_config=text_config.to_dict(),						vision_config=vision_config.to_dict(),						**_UpperCAmelCase						)




				def        lowercase__     (  self		:					List[Any]						):

								'''simple docstring'''
								lowercase__     				=    copy.deepcopy(self.__dict__						)
								lowercase__     				=    self.text_config.to_dict()
								lowercase__     				=    self.vision_config.to_dict()
								lowercase__     				=    self.__class__.model_type
								return output












from __future__ import annotations






def 						a    (		lowerCamelCase_       ):






				'''simple docstring'''
				lowercase__     				=    0.00
				lowercase__     				=    0
				for resistor in resistors:
								if resistor <= 0:
												lowercase__     				=    F"""Resistor at index {index} has a negative or zero value!"""
												raise ValueError(lowerCamelCase_       )
								first_sum += 1 / float(lowerCamelCase_       )
								index += 1
				return 1 / first_sum






def 						a    (		lowerCamelCase_       ):






				'''simple docstring'''
				lowercase__     				=    0.00
				lowercase__     				=    0
				for resistor in resistors:
								sum_r += resistor
								if resistor < 0:
												lowercase__     				=    F"""Resistor at index {index} has a negative value!"""
												raise ValueError(lowerCamelCase_       )
								index += 1
				return sum_r


if __name__ == "__main__":
							import doctest

							doctest.testmod()




