






'''simple docstring'''

import copy
import os
from typing import Union

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


A:      int  				=				logging.get_logger(__name__)

A:      Tuple  				=				{
    "BAAI/AltCLIP": "https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}






class 							__magic_name__     (	UpperCAmelCase_				):







	"""simple docstring"""



	SCREAMING_SNAKE_CASE_					:      Any        =  'altclip_text_model'
	def __init__(							self  ,      _lowercase=25_0002  ,      _lowercase=1024  ,      _lowercase=24  ,      _lowercase=16  ,      _lowercase=4096  ,      _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  ,      )						->  str:
							super().__init__(pad_token_id=_lowercase  ,      bos_token_id=_lowercase  ,      eos_token_id=_lowercase  ,      **_lowercase       )

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






class 							__magic_name__     (	UpperCAmelCase_				):







	"""simple docstring"""



	SCREAMING_SNAKE_CASE_					:      str        =  'altclip_vision_model'
	def __init__(							self  ,      _lowercase=768  ,      _lowercase=3072  ,      _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  ,      )						->  Optional[int]:
							super().__init__(**_lowercase       )

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







	@classmethod
	def        lowerCamelCase__		(							cls  ,      _lowercase  ,      **_lowercase       )						->  "PretrainedConfig":
							cls._set_token_in_kwargs(_lowercase       )

							lowercase_      :   int        =			cls.get_config_dict(_lowercase  ,      **_lowercase       )

							# get the vision config dict if we are loading from AltCLIPConfig
							if config_dict.get('model_type'       ) == "altclip":
													lowercase_      :   List[str]        =			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 							__magic_name__     (	UpperCAmelCase_				):







	"""simple docstring"""



	SCREAMING_SNAKE_CASE_					:      Dict        =  'altclip'
	SCREAMING_SNAKE_CASE_					:      Any        =  True
	def __init__(							self  ,      _lowercase=None  ,      _lowercase=None  ,      _lowercase=768  ,      _lowercase=2.65_92  ,      **_lowercase       )						->  int:
							# 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_      :   List[str]        =			kwargs.pop('text_config_dict'  ,      _lowercase       )
							lowercase_      :   Optional[Any]        =			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:
																			lowercase_      :   List[str]        =			{}

													# This is the complete result when using `text_config_dict`.
													lowercase_      :   str        =			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:
																															lowercase_      :   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:
																															lowercase_      :   List[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(_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:
																			lowercase_      :   Dict        =			{}

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

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

							lowercase_      :   int        =			AltCLIPTextConfig(**_lowercase       )
							lowercase_      :   Any        =			AltCLIPVisionConfig(**_lowercase       )

							lowercase_      :   Union[str, Any]        =			projection_dim
							lowercase_      :   List[Any]        =			logit_scale_init_value
							lowercase_      :   str        =			1.0
	@classmethod
	def        lowerCamelCase__		(							cls  ,      _lowercase  ,      _lowercase  ,      **_lowercase       )						->  int:
							return cls(text_config=text_config.to_dict()  ,      vision_config=vision_config.to_dict()  ,      **_lowercase       )







	def        lowerCamelCase__		(							self       )						->  Union[str, Any]:
							lowercase_      :   List[Any]        =			copy.deepcopy(self.__dict__       )
							lowercase_      :   Union[str, Any]        =			self.text_config.to_dict()
							lowercase_      :   int        =			self.vision_config.to_dict()
							lowercase_      :   Optional[int]        =			self.__class__.model_type
							return output








'''simple docstring'''

from typing import TYPE_CHECKING

from ..utils import _LazyModule


A:      int  				=				{
    "config": [
        "EXTERNAL_DATA_FORMAT_SIZE_LIMIT",
        "OnnxConfig",
        "OnnxConfigWithPast",
        "OnnxSeq2SeqConfigWithPast",
        "PatchingSpec",
    ],
    "convert": ["export", "validate_model_outputs"],
    "features": ["FeaturesManager"],
    "utils": ["ParameterFormat", "compute_serialized_parameters_size"],
}


if TYPE_CHECKING:
						from .config import (
						    EXTERNAL_DATA_FORMAT_SIZE_LIMIT,
						    OnnxConfig,
						    OnnxConfigWithPast,
						    OnnxSeqaSeqConfigWithPast,
						    PatchingSpec,
						)
						from .convert import export, validate_model_outputs
						from .features import FeaturesManager
						from .utils import ParameterFormat, compute_serialized_parameters_size

else:
						import sys

						A:      Dict  				=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
